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
|
---|---|---|---|---|---|---|---|---|---|---|---|
36,200 |
sven-piller/eslint-formatter-markdown
|
markdown.js
|
renderTemplate
|
function renderTemplate(type) {
var lcType = lodash.lowerCase(type);
if (lodash.size(stats[lcType])) {
return statsTemplate({
title: '### ' + type,
items: output(lcType)
});
} else {
return '';
}
}
|
javascript
|
function renderTemplate(type) {
var lcType = lodash.lowerCase(type);
if (lodash.size(stats[lcType])) {
return statsTemplate({
title: '### ' + type,
items: output(lcType)
});
} else {
return '';
}
}
|
[
"function",
"renderTemplate",
"(",
"type",
")",
"{",
"var",
"lcType",
"=",
"lodash",
".",
"lowerCase",
"(",
"type",
")",
";",
"if",
"(",
"lodash",
".",
"size",
"(",
"stats",
"[",
"lcType",
"]",
")",
")",
"{",
"return",
"statsTemplate",
"(",
"{",
"title",
":",
"'### '",
"+",
"type",
",",
"items",
":",
"output",
"(",
"lcType",
")",
"}",
")",
";",
"}",
"else",
"{",
"return",
"''",
";",
"}",
"}"
] |
render template for severity
@param {string} type severity
@returns {string} template
|
[
"render",
"template",
"for",
"severity"
] |
46fc4cb074b1f599f02df67d814a6a83b37de060
|
https://github.com/sven-piller/eslint-formatter-markdown/blob/46fc4cb074b1f599f02df67d814a6a83b37de060/markdown.js#L96-L106
|
36,201 |
ILLGrenoble/guacamole-common-js
|
src/ArrayBufferWriter.js
|
__send_blob
|
function __send_blob(bytes) {
var binary = "";
// Produce binary string from bytes in buffer
for (var i=0; i<bytes.byteLength; i++)
binary += String.fromCharCode(bytes[i]);
// Send as base64
stream.sendBlob(window.btoa(binary));
}
|
javascript
|
function __send_blob(bytes) {
var binary = "";
// Produce binary string from bytes in buffer
for (var i=0; i<bytes.byteLength; i++)
binary += String.fromCharCode(bytes[i]);
// Send as base64
stream.sendBlob(window.btoa(binary));
}
|
[
"function",
"__send_blob",
"(",
"bytes",
")",
"{",
"var",
"binary",
"=",
"\"\"",
";",
"// Produce binary string from bytes in buffer",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"bytes",
".",
"byteLength",
";",
"i",
"++",
")",
"binary",
"+=",
"String",
".",
"fromCharCode",
"(",
"bytes",
"[",
"i",
"]",
")",
";",
"// Send as base64",
"stream",
".",
"sendBlob",
"(",
"window",
".",
"btoa",
"(",
"binary",
")",
")",
";",
"}"
] |
Encodes the given data as base64, sending it as a blob. The data must
be small enough to fit into a single blob instruction.
@private
@param {Uint8Array} bytes The data to send.
|
[
"Encodes",
"the",
"given",
"data",
"as",
"base64",
"sending",
"it",
"as",
"a",
"blob",
".",
"The",
"data",
"must",
"be",
"small",
"enough",
"to",
"fit",
"into",
"a",
"single",
"blob",
"instruction",
"."
] |
71925794155ea3fc37d2a125adbca6f8be532887
|
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/ArrayBufferWriter.js#L51-L62
|
36,202 |
jorisvervuurt/JVSDisplayOTron
|
examples/dot3k/bar_graph.js
|
setBrightnessOfLed
|
function setBrightnessOfLed(callback) {
var ledIndex = 8;
var setBrightnessOfLedInterval = setInterval(function() {
if (ledIndex >= 0) {
dot3k.barGraph.setBrightnessOfLed(ledIndex, 0);
ledIndex--;
} else {
clearInterval(setBrightnessOfLedInterval);
if (callback) {
callback();
}
}
}, 500);
}
|
javascript
|
function setBrightnessOfLed(callback) {
var ledIndex = 8;
var setBrightnessOfLedInterval = setInterval(function() {
if (ledIndex >= 0) {
dot3k.barGraph.setBrightnessOfLed(ledIndex, 0);
ledIndex--;
} else {
clearInterval(setBrightnessOfLedInterval);
if (callback) {
callback();
}
}
}, 500);
}
|
[
"function",
"setBrightnessOfLed",
"(",
"callback",
")",
"{",
"var",
"ledIndex",
"=",
"8",
";",
"var",
"setBrightnessOfLedInterval",
"=",
"setInterval",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"ledIndex",
">=",
"0",
")",
"{",
"dot3k",
".",
"barGraph",
".",
"setBrightnessOfLed",
"(",
"ledIndex",
",",
"0",
")",
";",
"ledIndex",
"--",
";",
"}",
"else",
"{",
"clearInterval",
"(",
"setBrightnessOfLedInterval",
")",
";",
"if",
"(",
"callback",
")",
"{",
"callback",
"(",
")",
";",
"}",
"}",
"}",
",",
"500",
")",
";",
"}"
] |
Sets the brightness of each individual LED.
@param {Function} callback A function to call when the operation has finished.
|
[
"Sets",
"the",
"brightness",
"of",
"each",
"individual",
"LED",
"."
] |
c8f9bfdbf4e2658bb12fc83bbf49853c938e7dcc
|
https://github.com/jorisvervuurt/JVSDisplayOTron/blob/c8f9bfdbf4e2658bb12fc83bbf49853c938e7dcc/examples/dot3k/bar_graph.js#L33-L49
|
36,203 |
ascartabelli/lamb
|
src/privates/_getPadding.js
|
_getPadding
|
function _getPadding (source, char, len) {
if (!isNil(source) && type(source) !== "String") {
source = String(source);
}
return _repeat(String(char)[0] || "", Math.ceil(len - source.length));
}
|
javascript
|
function _getPadding (source, char, len) {
if (!isNil(source) && type(source) !== "String") {
source = String(source);
}
return _repeat(String(char)[0] || "", Math.ceil(len - source.length));
}
|
[
"function",
"_getPadding",
"(",
"source",
",",
"char",
",",
"len",
")",
"{",
"if",
"(",
"!",
"isNil",
"(",
"source",
")",
"&&",
"type",
"(",
"source",
")",
"!==",
"\"String\"",
")",
"{",
"source",
"=",
"String",
"(",
"source",
")",
";",
"}",
"return",
"_repeat",
"(",
"String",
"(",
"char",
")",
"[",
"0",
"]",
"||",
"\"\"",
",",
"Math",
".",
"ceil",
"(",
"len",
"-",
"source",
".",
"length",
")",
")",
";",
"}"
] |
Builds the prefix or suffix to be used when padding a string.
@private
@param {String} source
@param {String} char
@param {Number} len
@returns {String}
|
[
"Builds",
"the",
"prefix",
"or",
"suffix",
"to",
"be",
"used",
"when",
"padding",
"a",
"string",
"."
] |
d36e45945c4789e4f1a2d8805936514b53f32362
|
https://github.com/ascartabelli/lamb/blob/d36e45945c4789e4f1a2d8805936514b53f32362/src/privates/_getPadding.js#L13-L19
|
36,204 |
paritytech/js-shared
|
src/redux/providers/tokensActions.js
|
fetchTokensData
|
function fetchTokensData (tokenRegContract, tokenIndexes) {
return (dispatch, getState) => {
const { api, tokens } = getState();
const allTokens = Object.values(tokens);
const tokensIndexesMap = allTokens
.reduce((map, token) => {
map[token.index] = token;
return map;
}, {});
const fetchedTokenIndexes = allTokens
.filter((token) => token.fetched)
.map((token) => token.index);
const fullIndexes = [];
const partialIndexes = [];
tokenIndexes.forEach((tokenIndex) => {
if (fetchedTokenIndexes.includes(tokenIndex)) {
partialIndexes.push(tokenIndex);
} else {
fullIndexes.push(tokenIndex);
}
});
log.debug('need to fully fetch', fullIndexes);
log.debug('need to partially fetch', partialIndexes);
const fullPromise = fetchTokensInfo(api, tokenRegContract, fullIndexes);
const partialPromise = fetchTokensImages(api, tokenRegContract, partialIndexes)
.then((imagesResult) => {
return imagesResult.map((image, index) => {
const tokenIndex = partialIndexes[index];
const token = tokensIndexesMap[tokenIndex];
return { ...token, image };
});
});
return Promise.all([ fullPromise, partialPromise ])
.then(([ fullResults, partialResults ]) => {
log.debug('fetched', { fullResults, partialResults });
return []
.concat(fullResults, partialResults)
.filter(({ address }) => !/0x0*$/.test(address))
.reduce((tokens, token) => {
const { id } = token;
tokens[id] = token;
return tokens;
}, {});
})
.then((tokens) => {
dispatch(setTokens(tokens));
});
};
}
|
javascript
|
function fetchTokensData (tokenRegContract, tokenIndexes) {
return (dispatch, getState) => {
const { api, tokens } = getState();
const allTokens = Object.values(tokens);
const tokensIndexesMap = allTokens
.reduce((map, token) => {
map[token.index] = token;
return map;
}, {});
const fetchedTokenIndexes = allTokens
.filter((token) => token.fetched)
.map((token) => token.index);
const fullIndexes = [];
const partialIndexes = [];
tokenIndexes.forEach((tokenIndex) => {
if (fetchedTokenIndexes.includes(tokenIndex)) {
partialIndexes.push(tokenIndex);
} else {
fullIndexes.push(tokenIndex);
}
});
log.debug('need to fully fetch', fullIndexes);
log.debug('need to partially fetch', partialIndexes);
const fullPromise = fetchTokensInfo(api, tokenRegContract, fullIndexes);
const partialPromise = fetchTokensImages(api, tokenRegContract, partialIndexes)
.then((imagesResult) => {
return imagesResult.map((image, index) => {
const tokenIndex = partialIndexes[index];
const token = tokensIndexesMap[tokenIndex];
return { ...token, image };
});
});
return Promise.all([ fullPromise, partialPromise ])
.then(([ fullResults, partialResults ]) => {
log.debug('fetched', { fullResults, partialResults });
return []
.concat(fullResults, partialResults)
.filter(({ address }) => !/0x0*$/.test(address))
.reduce((tokens, token) => {
const { id } = token;
tokens[id] = token;
return tokens;
}, {});
})
.then((tokens) => {
dispatch(setTokens(tokens));
});
};
}
|
[
"function",
"fetchTokensData",
"(",
"tokenRegContract",
",",
"tokenIndexes",
")",
"{",
"return",
"(",
"dispatch",
",",
"getState",
")",
"=>",
"{",
"const",
"{",
"api",
",",
"tokens",
"}",
"=",
"getState",
"(",
")",
";",
"const",
"allTokens",
"=",
"Object",
".",
"values",
"(",
"tokens",
")",
";",
"const",
"tokensIndexesMap",
"=",
"allTokens",
".",
"reduce",
"(",
"(",
"map",
",",
"token",
")",
"=>",
"{",
"map",
"[",
"token",
".",
"index",
"]",
"=",
"token",
";",
"return",
"map",
";",
"}",
",",
"{",
"}",
")",
";",
"const",
"fetchedTokenIndexes",
"=",
"allTokens",
".",
"filter",
"(",
"(",
"token",
")",
"=>",
"token",
".",
"fetched",
")",
".",
"map",
"(",
"(",
"token",
")",
"=>",
"token",
".",
"index",
")",
";",
"const",
"fullIndexes",
"=",
"[",
"]",
";",
"const",
"partialIndexes",
"=",
"[",
"]",
";",
"tokenIndexes",
".",
"forEach",
"(",
"(",
"tokenIndex",
")",
"=>",
"{",
"if",
"(",
"fetchedTokenIndexes",
".",
"includes",
"(",
"tokenIndex",
")",
")",
"{",
"partialIndexes",
".",
"push",
"(",
"tokenIndex",
")",
";",
"}",
"else",
"{",
"fullIndexes",
".",
"push",
"(",
"tokenIndex",
")",
";",
"}",
"}",
")",
";",
"log",
".",
"debug",
"(",
"'need to fully fetch'",
",",
"fullIndexes",
")",
";",
"log",
".",
"debug",
"(",
"'need to partially fetch'",
",",
"partialIndexes",
")",
";",
"const",
"fullPromise",
"=",
"fetchTokensInfo",
"(",
"api",
",",
"tokenRegContract",
",",
"fullIndexes",
")",
";",
"const",
"partialPromise",
"=",
"fetchTokensImages",
"(",
"api",
",",
"tokenRegContract",
",",
"partialIndexes",
")",
".",
"then",
"(",
"(",
"imagesResult",
")",
"=>",
"{",
"return",
"imagesResult",
".",
"map",
"(",
"(",
"image",
",",
"index",
")",
"=>",
"{",
"const",
"tokenIndex",
"=",
"partialIndexes",
"[",
"index",
"]",
";",
"const",
"token",
"=",
"tokensIndexesMap",
"[",
"tokenIndex",
"]",
";",
"return",
"{",
"...",
"token",
",",
"image",
"}",
";",
"}",
")",
";",
"}",
")",
";",
"return",
"Promise",
".",
"all",
"(",
"[",
"fullPromise",
",",
"partialPromise",
"]",
")",
".",
"then",
"(",
"(",
"[",
"fullResults",
",",
"partialResults",
"]",
")",
"=>",
"{",
"log",
".",
"debug",
"(",
"'fetched'",
",",
"{",
"fullResults",
",",
"partialResults",
"}",
")",
";",
"return",
"[",
"]",
".",
"concat",
"(",
"fullResults",
",",
"partialResults",
")",
".",
"filter",
"(",
"(",
"{",
"address",
"}",
")",
"=>",
"!",
"/",
"0x0*$",
"/",
".",
"test",
"(",
"address",
")",
")",
".",
"reduce",
"(",
"(",
"tokens",
",",
"token",
")",
"=>",
"{",
"const",
"{",
"id",
"}",
"=",
"token",
";",
"tokens",
"[",
"id",
"]",
"=",
"token",
";",
"return",
"tokens",
";",
"}",
",",
"{",
"}",
")",
";",
"}",
")",
".",
"then",
"(",
"(",
"tokens",
")",
"=>",
"{",
"dispatch",
"(",
"setTokens",
"(",
"tokens",
")",
")",
";",
"}",
")",
";",
"}",
";",
"}"
] |
Split the given token indexes between those for whom
we already have some info, and thus just need to fetch
the image, and those for whom we don't have anything and
need to fetch all the info.
|
[
"Split",
"the",
"given",
"token",
"indexes",
"between",
"those",
"for",
"whom",
"we",
"already",
"have",
"some",
"info",
"and",
"thus",
"just",
"need",
"to",
"fetch",
"the",
"image",
"and",
"those",
"for",
"whom",
"we",
"don",
"t",
"have",
"anything",
"and",
"need",
"to",
"fetch",
"all",
"the",
"info",
"."
] |
bb9593e4eb369ae8629f5056860f669692396f94
|
https://github.com/paritytech/js-shared/blob/bb9593e4eb369ae8629f5056860f669692396f94/src/redux/providers/tokensActions.js#L188-L246
|
36,205 |
ILLGrenoble/guacamole-common-js
|
src/Layer.js
|
resize
|
function resize(newWidth, newHeight) {
// Default size to zero
newWidth = newWidth || 0;
newHeight = newHeight || 0;
// Calculate new dimensions of internal canvas
var canvasWidth = Math.ceil(newWidth / CANVAS_SIZE_FACTOR) * CANVAS_SIZE_FACTOR;
var canvasHeight = Math.ceil(newHeight / CANVAS_SIZE_FACTOR) * CANVAS_SIZE_FACTOR;
// Resize only if canvas dimensions are actually changing
if (canvas.width !== canvasWidth || canvas.height !== canvasHeight) {
// Copy old data only if relevant and non-empty
var oldData = null;
if (!empty && canvas.width !== 0 && canvas.height !== 0) {
// Create canvas and context for holding old data
oldData = document.createElement("canvas");
oldData.width = Math.min(layer.width, newWidth);
oldData.height = Math.min(layer.height, newHeight);
var oldDataContext = oldData.getContext("2d");
// Copy image data from current
oldDataContext.drawImage(canvas,
0, 0, oldData.width, oldData.height,
0, 0, oldData.width, oldData.height);
}
// Preserve composite operation
var oldCompositeOperation = context.globalCompositeOperation;
// Resize canvas
canvas.width = canvasWidth;
canvas.height = canvasHeight;
// Redraw old data, if any
if (oldData)
context.drawImage(oldData,
0, 0, oldData.width, oldData.height,
0, 0, oldData.width, oldData.height);
// Restore composite operation
context.globalCompositeOperation = oldCompositeOperation;
// Acknowledge reset of stack (happens on resize of canvas)
stackSize = 0;
context.save();
}
// If the canvas size is not changing, manually force state reset
else
layer.reset();
// Assign new layer dimensions
layer.width = newWidth;
layer.height = newHeight;
}
|
javascript
|
function resize(newWidth, newHeight) {
// Default size to zero
newWidth = newWidth || 0;
newHeight = newHeight || 0;
// Calculate new dimensions of internal canvas
var canvasWidth = Math.ceil(newWidth / CANVAS_SIZE_FACTOR) * CANVAS_SIZE_FACTOR;
var canvasHeight = Math.ceil(newHeight / CANVAS_SIZE_FACTOR) * CANVAS_SIZE_FACTOR;
// Resize only if canvas dimensions are actually changing
if (canvas.width !== canvasWidth || canvas.height !== canvasHeight) {
// Copy old data only if relevant and non-empty
var oldData = null;
if (!empty && canvas.width !== 0 && canvas.height !== 0) {
// Create canvas and context for holding old data
oldData = document.createElement("canvas");
oldData.width = Math.min(layer.width, newWidth);
oldData.height = Math.min(layer.height, newHeight);
var oldDataContext = oldData.getContext("2d");
// Copy image data from current
oldDataContext.drawImage(canvas,
0, 0, oldData.width, oldData.height,
0, 0, oldData.width, oldData.height);
}
// Preserve composite operation
var oldCompositeOperation = context.globalCompositeOperation;
// Resize canvas
canvas.width = canvasWidth;
canvas.height = canvasHeight;
// Redraw old data, if any
if (oldData)
context.drawImage(oldData,
0, 0, oldData.width, oldData.height,
0, 0, oldData.width, oldData.height);
// Restore composite operation
context.globalCompositeOperation = oldCompositeOperation;
// Acknowledge reset of stack (happens on resize of canvas)
stackSize = 0;
context.save();
}
// If the canvas size is not changing, manually force state reset
else
layer.reset();
// Assign new layer dimensions
layer.width = newWidth;
layer.height = newHeight;
}
|
[
"function",
"resize",
"(",
"newWidth",
",",
"newHeight",
")",
"{",
"// Default size to zero",
"newWidth",
"=",
"newWidth",
"||",
"0",
";",
"newHeight",
"=",
"newHeight",
"||",
"0",
";",
"// Calculate new dimensions of internal canvas",
"var",
"canvasWidth",
"=",
"Math",
".",
"ceil",
"(",
"newWidth",
"/",
"CANVAS_SIZE_FACTOR",
")",
"*",
"CANVAS_SIZE_FACTOR",
";",
"var",
"canvasHeight",
"=",
"Math",
".",
"ceil",
"(",
"newHeight",
"/",
"CANVAS_SIZE_FACTOR",
")",
"*",
"CANVAS_SIZE_FACTOR",
";",
"// Resize only if canvas dimensions are actually changing",
"if",
"(",
"canvas",
".",
"width",
"!==",
"canvasWidth",
"||",
"canvas",
".",
"height",
"!==",
"canvasHeight",
")",
"{",
"// Copy old data only if relevant and non-empty",
"var",
"oldData",
"=",
"null",
";",
"if",
"(",
"!",
"empty",
"&&",
"canvas",
".",
"width",
"!==",
"0",
"&&",
"canvas",
".",
"height",
"!==",
"0",
")",
"{",
"// Create canvas and context for holding old data",
"oldData",
"=",
"document",
".",
"createElement",
"(",
"\"canvas\"",
")",
";",
"oldData",
".",
"width",
"=",
"Math",
".",
"min",
"(",
"layer",
".",
"width",
",",
"newWidth",
")",
";",
"oldData",
".",
"height",
"=",
"Math",
".",
"min",
"(",
"layer",
".",
"height",
",",
"newHeight",
")",
";",
"var",
"oldDataContext",
"=",
"oldData",
".",
"getContext",
"(",
"\"2d\"",
")",
";",
"// Copy image data from current",
"oldDataContext",
".",
"drawImage",
"(",
"canvas",
",",
"0",
",",
"0",
",",
"oldData",
".",
"width",
",",
"oldData",
".",
"height",
",",
"0",
",",
"0",
",",
"oldData",
".",
"width",
",",
"oldData",
".",
"height",
")",
";",
"}",
"// Preserve composite operation",
"var",
"oldCompositeOperation",
"=",
"context",
".",
"globalCompositeOperation",
";",
"// Resize canvas",
"canvas",
".",
"width",
"=",
"canvasWidth",
";",
"canvas",
".",
"height",
"=",
"canvasHeight",
";",
"// Redraw old data, if any",
"if",
"(",
"oldData",
")",
"context",
".",
"drawImage",
"(",
"oldData",
",",
"0",
",",
"0",
",",
"oldData",
".",
"width",
",",
"oldData",
".",
"height",
",",
"0",
",",
"0",
",",
"oldData",
".",
"width",
",",
"oldData",
".",
"height",
")",
";",
"// Restore composite operation",
"context",
".",
"globalCompositeOperation",
"=",
"oldCompositeOperation",
";",
"// Acknowledge reset of stack (happens on resize of canvas)",
"stackSize",
"=",
"0",
";",
"context",
".",
"save",
"(",
")",
";",
"}",
"// If the canvas size is not changing, manually force state reset",
"else",
"layer",
".",
"reset",
"(",
")",
";",
"// Assign new layer dimensions",
"layer",
".",
"width",
"=",
"newWidth",
";",
"layer",
".",
"height",
"=",
"newHeight",
";",
"}"
] |
Resizes the canvas element backing this Layer. This function should only
be used internally.
@private
@param {Number} [newWidth=0]
The new width to assign to this Layer.
@param {Number} [newHeight=0]
The new height to assign to this Layer.
|
[
"Resizes",
"the",
"canvas",
"element",
"backing",
"this",
"Layer",
".",
"This",
"function",
"should",
"only",
"be",
"used",
"internally",
"."
] |
71925794155ea3fc37d2a125adbca6f8be532887
|
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/Layer.js#L132-L193
|
36,206 |
ILLGrenoble/guacamole-common-js
|
src/Layer.js
|
fitRect
|
function fitRect(x, y, w, h) {
// Calculate bounds
var opBoundX = w + x;
var opBoundY = h + y;
// Determine max width
var resizeWidth;
if (opBoundX > layer.width)
resizeWidth = opBoundX;
else
resizeWidth = layer.width;
// Determine max height
var resizeHeight;
if (opBoundY > layer.height)
resizeHeight = opBoundY;
else
resizeHeight = layer.height;
// Resize if necessary
layer.resize(resizeWidth, resizeHeight);
}
|
javascript
|
function fitRect(x, y, w, h) {
// Calculate bounds
var opBoundX = w + x;
var opBoundY = h + y;
// Determine max width
var resizeWidth;
if (opBoundX > layer.width)
resizeWidth = opBoundX;
else
resizeWidth = layer.width;
// Determine max height
var resizeHeight;
if (opBoundY > layer.height)
resizeHeight = opBoundY;
else
resizeHeight = layer.height;
// Resize if necessary
layer.resize(resizeWidth, resizeHeight);
}
|
[
"function",
"fitRect",
"(",
"x",
",",
"y",
",",
"w",
",",
"h",
")",
"{",
"// Calculate bounds",
"var",
"opBoundX",
"=",
"w",
"+",
"x",
";",
"var",
"opBoundY",
"=",
"h",
"+",
"y",
";",
"// Determine max width",
"var",
"resizeWidth",
";",
"if",
"(",
"opBoundX",
">",
"layer",
".",
"width",
")",
"resizeWidth",
"=",
"opBoundX",
";",
"else",
"resizeWidth",
"=",
"layer",
".",
"width",
";",
"// Determine max height",
"var",
"resizeHeight",
";",
"if",
"(",
"opBoundY",
">",
"layer",
".",
"height",
")",
"resizeHeight",
"=",
"opBoundY",
";",
"else",
"resizeHeight",
"=",
"layer",
".",
"height",
";",
"// Resize if necessary",
"layer",
".",
"resize",
"(",
"resizeWidth",
",",
"resizeHeight",
")",
";",
"}"
] |
Given the X and Y coordinates of the upper-left corner of a rectangle
and the rectangle's width and height, resize the backing canvas element
as necessary to ensure that the rectangle fits within the canvas
element's coordinate space. This function will only make the canvas
larger. If the rectangle already fits within the canvas element's
coordinate space, the canvas is left unchanged.
@private
@param {Number} x The X coordinate of the upper-left corner of the
rectangle to fit.
@param {Number} y The Y coordinate of the upper-left corner of the
rectangle to fit.
@param {Number} w The width of the the rectangle to fit.
@param {Number} h The height of the the rectangle to fit.
|
[
"Given",
"the",
"X",
"and",
"Y",
"coordinates",
"of",
"the",
"upper",
"-",
"left",
"corner",
"of",
"a",
"rectangle",
"and",
"the",
"rectangle",
"s",
"width",
"and",
"height",
"resize",
"the",
"backing",
"canvas",
"element",
"as",
"necessary",
"to",
"ensure",
"that",
"the",
"rectangle",
"fits",
"within",
"the",
"canvas",
"element",
"s",
"coordinate",
"space",
".",
"This",
"function",
"will",
"only",
"make",
"the",
"canvas",
"larger",
".",
"If",
"the",
"rectangle",
"already",
"fits",
"within",
"the",
"canvas",
"element",
"s",
"coordinate",
"space",
"the",
"canvas",
"is",
"left",
"unchanged",
"."
] |
71925794155ea3fc37d2a125adbca6f8be532887
|
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/Layer.js#L211-L234
|
36,207 |
aMarCruz/jspreproc
|
spec/uglify/riot.js
|
_mkdom
|
function _mkdom(templ, html) {
var match = templ && templ.match(/^\s*<([-\w]+)/),
tagName = match && match[1].toLowerCase(),
rootTag = rootEls[tagName] || GENERIC,
el = mkEl(rootTag)
el.stub = true
// replace all the yield tags with the tag inner html
if (html) templ = replaceYield(templ, html)
/* istanbul ignore next */
if (checkIE && tagName && (match = tagName.match(SPECIAL_TAGS_REGEX)))
ie9elem(el, templ, tagName, !!match[1])
else
el.innerHTML = templ
return el
}
|
javascript
|
function _mkdom(templ, html) {
var match = templ && templ.match(/^\s*<([-\w]+)/),
tagName = match && match[1].toLowerCase(),
rootTag = rootEls[tagName] || GENERIC,
el = mkEl(rootTag)
el.stub = true
// replace all the yield tags with the tag inner html
if (html) templ = replaceYield(templ, html)
/* istanbul ignore next */
if (checkIE && tagName && (match = tagName.match(SPECIAL_TAGS_REGEX)))
ie9elem(el, templ, tagName, !!match[1])
else
el.innerHTML = templ
return el
}
|
[
"function",
"_mkdom",
"(",
"templ",
",",
"html",
")",
"{",
"var",
"match",
"=",
"templ",
"&&",
"templ",
".",
"match",
"(",
"/",
"^\\s*<([-\\w]+)",
"/",
")",
",",
"tagName",
"=",
"match",
"&&",
"match",
"[",
"1",
"]",
".",
"toLowerCase",
"(",
")",
",",
"rootTag",
"=",
"rootEls",
"[",
"tagName",
"]",
"||",
"GENERIC",
",",
"el",
"=",
"mkEl",
"(",
"rootTag",
")",
"el",
".",
"stub",
"=",
"true",
"// replace all the yield tags with the tag inner html",
"if",
"(",
"html",
")",
"templ",
"=",
"replaceYield",
"(",
"templ",
",",
"html",
")",
"/* istanbul ignore next */",
"if",
"(",
"checkIE",
"&&",
"tagName",
"&&",
"(",
"match",
"=",
"tagName",
".",
"match",
"(",
"SPECIAL_TAGS_REGEX",
")",
")",
")",
"ie9elem",
"(",
"el",
",",
"templ",
",",
"tagName",
",",
"!",
"!",
"match",
"[",
"1",
"]",
")",
"else",
"el",
".",
"innerHTML",
"=",
"templ",
"return",
"el",
"}"
] |
creates any dom element in a div, table, or colgroup container
|
[
"creates",
"any",
"dom",
"element",
"in",
"a",
"div",
"table",
"or",
"colgroup",
"container"
] |
5f31820d702a329e8aa25f0f3983f13097610250
|
https://github.com/aMarCruz/jspreproc/blob/5f31820d702a329e8aa25f0f3983f13097610250/spec/uglify/riot.js#L913-L932
|
36,208 |
aMarCruz/jspreproc
|
spec/uglify/riot.js
|
update
|
function update(expressions, tag) {
each(expressions, function(expr, i) {
var dom = expr.dom,
attrName = expr.attr,
value = tmpl(expr.expr, tag),
parent = expr.dom.parentNode
if (expr.bool)
value = value ? attrName : false
else if (value == null)
value = ''
// leave out riot- prefixes from strings inside textarea
// fix #815: any value -> string
if (parent && parent.tagName == 'TEXTAREA') {
value = ('' + value).replace(/riot-/g, '')
// change textarea's value
parent.value = value
}
// no change
if (expr.value === value) return
expr.value = value
// text node
if (!attrName) {
dom.nodeValue = '' + value // #815 related
return
}
// remove original attribute
remAttr(dom, attrName)
// event handler
if (isFunction(value)) {
setEventHandler(attrName, value, dom, tag)
// if- conditional
} else if (attrName == 'if') {
var stub = expr.stub,
add = function() { insertTo(stub.parentNode, stub, dom) },
remove = function() { insertTo(dom.parentNode, dom, stub) }
// add to DOM
if (value) {
if (stub) {
add()
dom.inStub = false
// avoid to trigger the mount event if the tags is not visible yet
// maybe we can optimize this avoiding to mount the tag at all
if (!isInStub(dom)) {
walk(dom, function(el) {
if (el._tag && !el._tag.isMounted)
el._tag.isMounted = !!el._tag.trigger('mount')
})
}
}
// remove from DOM
} else {
stub = expr.stub = stub || document.createTextNode('')
// if the parentNode is defined we can easily replace the tag
if (dom.parentNode)
remove()
// otherwise we need to wait the updated event
else (tag.parent || tag).one('updated', remove)
dom.inStub = true
}
// show / hide
} else if (/^(show|hide)$/.test(attrName)) {
if (attrName == 'hide') value = !value
dom.style.display = value ? '' : 'none'
// field value
} else if (attrName == 'value') {
dom.value = value
// <img src="{ expr }">
} else if (startsWith(attrName, RIOT_PREFIX) && attrName != RIOT_TAG) {
if (value)
setAttr(dom, attrName.slice(RIOT_PREFIX.length), value)
} else {
if (expr.bool) {
dom[attrName] = value
if (!value) return
}
if (value === 0 || value && typeof value !== T_OBJECT)
setAttr(dom, attrName, value)
}
})
}
|
javascript
|
function update(expressions, tag) {
each(expressions, function(expr, i) {
var dom = expr.dom,
attrName = expr.attr,
value = tmpl(expr.expr, tag),
parent = expr.dom.parentNode
if (expr.bool)
value = value ? attrName : false
else if (value == null)
value = ''
// leave out riot- prefixes from strings inside textarea
// fix #815: any value -> string
if (parent && parent.tagName == 'TEXTAREA') {
value = ('' + value).replace(/riot-/g, '')
// change textarea's value
parent.value = value
}
// no change
if (expr.value === value) return
expr.value = value
// text node
if (!attrName) {
dom.nodeValue = '' + value // #815 related
return
}
// remove original attribute
remAttr(dom, attrName)
// event handler
if (isFunction(value)) {
setEventHandler(attrName, value, dom, tag)
// if- conditional
} else if (attrName == 'if') {
var stub = expr.stub,
add = function() { insertTo(stub.parentNode, stub, dom) },
remove = function() { insertTo(dom.parentNode, dom, stub) }
// add to DOM
if (value) {
if (stub) {
add()
dom.inStub = false
// avoid to trigger the mount event if the tags is not visible yet
// maybe we can optimize this avoiding to mount the tag at all
if (!isInStub(dom)) {
walk(dom, function(el) {
if (el._tag && !el._tag.isMounted)
el._tag.isMounted = !!el._tag.trigger('mount')
})
}
}
// remove from DOM
} else {
stub = expr.stub = stub || document.createTextNode('')
// if the parentNode is defined we can easily replace the tag
if (dom.parentNode)
remove()
// otherwise we need to wait the updated event
else (tag.parent || tag).one('updated', remove)
dom.inStub = true
}
// show / hide
} else if (/^(show|hide)$/.test(attrName)) {
if (attrName == 'hide') value = !value
dom.style.display = value ? '' : 'none'
// field value
} else if (attrName == 'value') {
dom.value = value
// <img src="{ expr }">
} else if (startsWith(attrName, RIOT_PREFIX) && attrName != RIOT_TAG) {
if (value)
setAttr(dom, attrName.slice(RIOT_PREFIX.length), value)
} else {
if (expr.bool) {
dom[attrName] = value
if (!value) return
}
if (value === 0 || value && typeof value !== T_OBJECT)
setAttr(dom, attrName, value)
}
})
}
|
[
"function",
"update",
"(",
"expressions",
",",
"tag",
")",
"{",
"each",
"(",
"expressions",
",",
"function",
"(",
"expr",
",",
"i",
")",
"{",
"var",
"dom",
"=",
"expr",
".",
"dom",
",",
"attrName",
"=",
"expr",
".",
"attr",
",",
"value",
"=",
"tmpl",
"(",
"expr",
".",
"expr",
",",
"tag",
")",
",",
"parent",
"=",
"expr",
".",
"dom",
".",
"parentNode",
"if",
"(",
"expr",
".",
"bool",
")",
"value",
"=",
"value",
"?",
"attrName",
":",
"false",
"else",
"if",
"(",
"value",
"==",
"null",
")",
"value",
"=",
"''",
"// leave out riot- prefixes from strings inside textarea",
"// fix #815: any value -> string",
"if",
"(",
"parent",
"&&",
"parent",
".",
"tagName",
"==",
"'TEXTAREA'",
")",
"{",
"value",
"=",
"(",
"''",
"+",
"value",
")",
".",
"replace",
"(",
"/",
"riot-",
"/",
"g",
",",
"''",
")",
"// change textarea's value",
"parent",
".",
"value",
"=",
"value",
"}",
"// no change",
"if",
"(",
"expr",
".",
"value",
"===",
"value",
")",
"return",
"expr",
".",
"value",
"=",
"value",
"// text node",
"if",
"(",
"!",
"attrName",
")",
"{",
"dom",
".",
"nodeValue",
"=",
"''",
"+",
"value",
"// #815 related",
"return",
"}",
"// remove original attribute",
"remAttr",
"(",
"dom",
",",
"attrName",
")",
"// event handler",
"if",
"(",
"isFunction",
"(",
"value",
")",
")",
"{",
"setEventHandler",
"(",
"attrName",
",",
"value",
",",
"dom",
",",
"tag",
")",
"// if- conditional",
"}",
"else",
"if",
"(",
"attrName",
"==",
"'if'",
")",
"{",
"var",
"stub",
"=",
"expr",
".",
"stub",
",",
"add",
"=",
"function",
"(",
")",
"{",
"insertTo",
"(",
"stub",
".",
"parentNode",
",",
"stub",
",",
"dom",
")",
"}",
",",
"remove",
"=",
"function",
"(",
")",
"{",
"insertTo",
"(",
"dom",
".",
"parentNode",
",",
"dom",
",",
"stub",
")",
"}",
"// add to DOM",
"if",
"(",
"value",
")",
"{",
"if",
"(",
"stub",
")",
"{",
"add",
"(",
")",
"dom",
".",
"inStub",
"=",
"false",
"// avoid to trigger the mount event if the tags is not visible yet",
"// maybe we can optimize this avoiding to mount the tag at all",
"if",
"(",
"!",
"isInStub",
"(",
"dom",
")",
")",
"{",
"walk",
"(",
"dom",
",",
"function",
"(",
"el",
")",
"{",
"if",
"(",
"el",
".",
"_tag",
"&&",
"!",
"el",
".",
"_tag",
".",
"isMounted",
")",
"el",
".",
"_tag",
".",
"isMounted",
"=",
"!",
"!",
"el",
".",
"_tag",
".",
"trigger",
"(",
"'mount'",
")",
"}",
")",
"}",
"}",
"// remove from DOM",
"}",
"else",
"{",
"stub",
"=",
"expr",
".",
"stub",
"=",
"stub",
"||",
"document",
".",
"createTextNode",
"(",
"''",
")",
"// if the parentNode is defined we can easily replace the tag",
"if",
"(",
"dom",
".",
"parentNode",
")",
"remove",
"(",
")",
"// otherwise we need to wait the updated event",
"else",
"(",
"tag",
".",
"parent",
"||",
"tag",
")",
".",
"one",
"(",
"'updated'",
",",
"remove",
")",
"dom",
".",
"inStub",
"=",
"true",
"}",
"// show / hide",
"}",
"else",
"if",
"(",
"/",
"^(show|hide)$",
"/",
".",
"test",
"(",
"attrName",
")",
")",
"{",
"if",
"(",
"attrName",
"==",
"'hide'",
")",
"value",
"=",
"!",
"value",
"dom",
".",
"style",
".",
"display",
"=",
"value",
"?",
"''",
":",
"'none'",
"// field value",
"}",
"else",
"if",
"(",
"attrName",
"==",
"'value'",
")",
"{",
"dom",
".",
"value",
"=",
"value",
"// <img src=\"{ expr }\">",
"}",
"else",
"if",
"(",
"startsWith",
"(",
"attrName",
",",
"RIOT_PREFIX",
")",
"&&",
"attrName",
"!=",
"RIOT_TAG",
")",
"{",
"if",
"(",
"value",
")",
"setAttr",
"(",
"dom",
",",
"attrName",
".",
"slice",
"(",
"RIOT_PREFIX",
".",
"length",
")",
",",
"value",
")",
"}",
"else",
"{",
"if",
"(",
"expr",
".",
"bool",
")",
"{",
"dom",
"[",
"attrName",
"]",
"=",
"value",
"if",
"(",
"!",
"value",
")",
"return",
"}",
"if",
"(",
"value",
"===",
"0",
"||",
"value",
"&&",
"typeof",
"value",
"!==",
"T_OBJECT",
")",
"setAttr",
"(",
"dom",
",",
"attrName",
",",
"value",
")",
"}",
"}",
")",
"}"
] |
Update the expressions in a Tag instance
@param { Array } expressions - expression that must be re evaluated
@param { Tag } tag - tag instance
|
[
"Update",
"the",
"expressions",
"in",
"a",
"Tag",
"instance"
] |
5f31820d702a329e8aa25f0f3983f13097610250
|
https://github.com/aMarCruz/jspreproc/blob/5f31820d702a329e8aa25f0f3983f13097610250/spec/uglify/riot.js#L1666-L1762
|
36,209 |
aMarCruz/jspreproc
|
spec/uglify/riot.js
|
each
|
function each(els, fn) {
for (var i = 0, len = (els || []).length, el; i < len; i++) {
el = els[i]
// return false -> remove current item during loop
if (el != null && fn(el, i) === false) i--
}
return els
}
|
javascript
|
function each(els, fn) {
for (var i = 0, len = (els || []).length, el; i < len; i++) {
el = els[i]
// return false -> remove current item during loop
if (el != null && fn(el, i) === false) i--
}
return els
}
|
[
"function",
"each",
"(",
"els",
",",
"fn",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"(",
"els",
"||",
"[",
"]",
")",
".",
"length",
",",
"el",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"el",
"=",
"els",
"[",
"i",
"]",
"// return false -> remove current item during loop",
"if",
"(",
"el",
"!=",
"null",
"&&",
"fn",
"(",
"el",
",",
"i",
")",
"===",
"false",
")",
"i",
"--",
"}",
"return",
"els",
"}"
] |
Loops an array
@param { Array } els - collection of items
@param {Function} fn - callback function
@returns { Array } the array looped
|
[
"Loops",
"an",
"array"
] |
5f31820d702a329e8aa25f0f3983f13097610250
|
https://github.com/aMarCruz/jspreproc/blob/5f31820d702a329e8aa25f0f3983f13097610250/spec/uglify/riot.js#L1769-L1776
|
36,210 |
aMarCruz/jspreproc
|
spec/uglify/riot.js
|
addChildTag
|
function addChildTag(tag, tagName, parent) {
var cachedTag = parent.tags[tagName]
// if there are multiple children tags having the same name
if (cachedTag) {
// if the parent tags property is not yet an array
// create it adding the first cached tag
if (!isArray(cachedTag))
// don't add the same tag twice
if (cachedTag !== tag)
parent.tags[tagName] = [cachedTag]
// add the new nested tag to the array
if (!contains(parent.tags[tagName], tag))
parent.tags[tagName].push(tag)
} else {
parent.tags[tagName] = tag
}
}
|
javascript
|
function addChildTag(tag, tagName, parent) {
var cachedTag = parent.tags[tagName]
// if there are multiple children tags having the same name
if (cachedTag) {
// if the parent tags property is not yet an array
// create it adding the first cached tag
if (!isArray(cachedTag))
// don't add the same tag twice
if (cachedTag !== tag)
parent.tags[tagName] = [cachedTag]
// add the new nested tag to the array
if (!contains(parent.tags[tagName], tag))
parent.tags[tagName].push(tag)
} else {
parent.tags[tagName] = tag
}
}
|
[
"function",
"addChildTag",
"(",
"tag",
",",
"tagName",
",",
"parent",
")",
"{",
"var",
"cachedTag",
"=",
"parent",
".",
"tags",
"[",
"tagName",
"]",
"// if there are multiple children tags having the same name",
"if",
"(",
"cachedTag",
")",
"{",
"// if the parent tags property is not yet an array",
"// create it adding the first cached tag",
"if",
"(",
"!",
"isArray",
"(",
"cachedTag",
")",
")",
"// don't add the same tag twice",
"if",
"(",
"cachedTag",
"!==",
"tag",
")",
"parent",
".",
"tags",
"[",
"tagName",
"]",
"=",
"[",
"cachedTag",
"]",
"// add the new nested tag to the array",
"if",
"(",
"!",
"contains",
"(",
"parent",
".",
"tags",
"[",
"tagName",
"]",
",",
"tag",
")",
")",
"parent",
".",
"tags",
"[",
"tagName",
"]",
".",
"push",
"(",
"tag",
")",
"}",
"else",
"{",
"parent",
".",
"tags",
"[",
"tagName",
"]",
"=",
"tag",
"}",
"}"
] |
Add a child tag to its parent into the `tags` object
@param { Object } tag - child tag instance
@param { String } tagName - key where the new tag will be stored
@param { Object } parent - tag instance where the new child tag will be included
|
[
"Add",
"a",
"child",
"tag",
"to",
"its",
"parent",
"into",
"the",
"tags",
"object"
] |
5f31820d702a329e8aa25f0f3983f13097610250
|
https://github.com/aMarCruz/jspreproc/blob/5f31820d702a329e8aa25f0f3983f13097610250/spec/uglify/riot.js#L1841-L1858
|
36,211 |
aMarCruz/jspreproc
|
spec/uglify/riot.js
|
isWritable
|
function isWritable(obj, key) {
var props = Object.getOwnPropertyDescriptor(obj, key)
return typeof obj[key] === T_UNDEF || props && props.writable
}
|
javascript
|
function isWritable(obj, key) {
var props = Object.getOwnPropertyDescriptor(obj, key)
return typeof obj[key] === T_UNDEF || props && props.writable
}
|
[
"function",
"isWritable",
"(",
"obj",
",",
"key",
")",
"{",
"var",
"props",
"=",
"Object",
".",
"getOwnPropertyDescriptor",
"(",
"obj",
",",
"key",
")",
"return",
"typeof",
"obj",
"[",
"key",
"]",
"===",
"T_UNDEF",
"||",
"props",
"&&",
"props",
".",
"writable",
"}"
] |
Detect whether a property of an object could be overridden
@param { Object } obj - source object
@param { String } key - object property
@returns { Boolean } is this property writable?
|
[
"Detect",
"whether",
"a",
"property",
"of",
"an",
"object",
"could",
"be",
"overridden"
] |
5f31820d702a329e8aa25f0f3983f13097610250
|
https://github.com/aMarCruz/jspreproc/blob/5f31820d702a329e8aa25f0f3983f13097610250/spec/uglify/riot.js#L2004-L2007
|
36,212 |
aMarCruz/jspreproc
|
spec/uglify/riot.js
|
isInStub
|
function isInStub(dom) {
while (dom) {
if (dom.inStub) return true
dom = dom.parentNode
}
return false
}
|
javascript
|
function isInStub(dom) {
while (dom) {
if (dom.inStub) return true
dom = dom.parentNode
}
return false
}
|
[
"function",
"isInStub",
"(",
"dom",
")",
"{",
"while",
"(",
"dom",
")",
"{",
"if",
"(",
"dom",
".",
"inStub",
")",
"return",
"true",
"dom",
"=",
"dom",
".",
"parentNode",
"}",
"return",
"false",
"}"
] |
Check whether a DOM node is in stub mode, useful for the riot 'if' directive
@param { Object } dom - DOM node we want to parse
@returns { Boolean } -
|
[
"Check",
"whether",
"a",
"DOM",
"node",
"is",
"in",
"stub",
"mode",
"useful",
"for",
"the",
"riot",
"if",
"directive"
] |
5f31820d702a329e8aa25f0f3983f13097610250
|
https://github.com/aMarCruz/jspreproc/blob/5f31820d702a329e8aa25f0f3983f13097610250/spec/uglify/riot.js#L2066-L2072
|
36,213 |
aMarCruz/jspreproc
|
spec/uglify/riot.js
|
setNamed
|
function setNamed(dom, parent, keys) {
// get the key value we want to add to the tag instance
var key = getNamedKey(dom),
isArr,
// add the node detected to a tag instance using the named property
add = function(value) {
// avoid to override the tag properties already set
if (contains(keys, key)) return
// check whether this value is an array
isArr = isArray(value)
// if the key was never set
if (!value)
// set it once on the tag instance
parent[key] = dom
// if it was an array and not yet set
else if (!isArr || isArr && !contains(value, dom)) {
// add the dom node into the array
if (isArr)
value.push(dom)
else
parent[key] = [value, dom]
}
}
// skip the elements with no named properties
if (!key) return
// check whether this key has been already evaluated
if (tmpl.hasExpr(key))
// wait the first updated event only once
parent.one('mount', function() {
key = getNamedKey(dom)
add(parent[key])
})
else
add(parent[key])
}
|
javascript
|
function setNamed(dom, parent, keys) {
// get the key value we want to add to the tag instance
var key = getNamedKey(dom),
isArr,
// add the node detected to a tag instance using the named property
add = function(value) {
// avoid to override the tag properties already set
if (contains(keys, key)) return
// check whether this value is an array
isArr = isArray(value)
// if the key was never set
if (!value)
// set it once on the tag instance
parent[key] = dom
// if it was an array and not yet set
else if (!isArr || isArr && !contains(value, dom)) {
// add the dom node into the array
if (isArr)
value.push(dom)
else
parent[key] = [value, dom]
}
}
// skip the elements with no named properties
if (!key) return
// check whether this key has been already evaluated
if (tmpl.hasExpr(key))
// wait the first updated event only once
parent.one('mount', function() {
key = getNamedKey(dom)
add(parent[key])
})
else
add(parent[key])
}
|
[
"function",
"setNamed",
"(",
"dom",
",",
"parent",
",",
"keys",
")",
"{",
"// get the key value we want to add to the tag instance",
"var",
"key",
"=",
"getNamedKey",
"(",
"dom",
")",
",",
"isArr",
",",
"// add the node detected to a tag instance using the named property",
"add",
"=",
"function",
"(",
"value",
")",
"{",
"// avoid to override the tag properties already set",
"if",
"(",
"contains",
"(",
"keys",
",",
"key",
")",
")",
"return",
"// check whether this value is an array",
"isArr",
"=",
"isArray",
"(",
"value",
")",
"// if the key was never set",
"if",
"(",
"!",
"value",
")",
"// set it once on the tag instance",
"parent",
"[",
"key",
"]",
"=",
"dom",
"// if it was an array and not yet set",
"else",
"if",
"(",
"!",
"isArr",
"||",
"isArr",
"&&",
"!",
"contains",
"(",
"value",
",",
"dom",
")",
")",
"{",
"// add the dom node into the array",
"if",
"(",
"isArr",
")",
"value",
".",
"push",
"(",
"dom",
")",
"else",
"parent",
"[",
"key",
"]",
"=",
"[",
"value",
",",
"dom",
"]",
"}",
"}",
"// skip the elements with no named properties",
"if",
"(",
"!",
"key",
")",
"return",
"// check whether this key has been already evaluated",
"if",
"(",
"tmpl",
".",
"hasExpr",
"(",
"key",
")",
")",
"// wait the first updated event only once",
"parent",
".",
"one",
"(",
"'mount'",
",",
"function",
"(",
")",
"{",
"key",
"=",
"getNamedKey",
"(",
"dom",
")",
"add",
"(",
"parent",
"[",
"key",
"]",
")",
"}",
")",
"else",
"add",
"(",
"parent",
"[",
"key",
"]",
")",
"}"
] |
Set the named properties of a tag element
@param { Object } dom - DOM node we need to parse
@param { Object } parent - tag instance where the named dom element will be eventually added
@param { Array } keys - list of all the tag instance properties
|
[
"Set",
"the",
"named",
"properties",
"of",
"a",
"tag",
"element"
] |
5f31820d702a329e8aa25f0f3983f13097610250
|
https://github.com/aMarCruz/jspreproc/blob/5f31820d702a329e8aa25f0f3983f13097610250/spec/uglify/riot.js#L2129-L2166
|
36,214 |
aMarCruz/jspreproc
|
spec/uglify/riot.js
|
function(value) {
// avoid to override the tag properties already set
if (contains(keys, key)) return
// check whether this value is an array
isArr = isArray(value)
// if the key was never set
if (!value)
// set it once on the tag instance
parent[key] = dom
// if it was an array and not yet set
else if (!isArr || isArr && !contains(value, dom)) {
// add the dom node into the array
if (isArr)
value.push(dom)
else
parent[key] = [value, dom]
}
}
|
javascript
|
function(value) {
// avoid to override the tag properties already set
if (contains(keys, key)) return
// check whether this value is an array
isArr = isArray(value)
// if the key was never set
if (!value)
// set it once on the tag instance
parent[key] = dom
// if it was an array and not yet set
else if (!isArr || isArr && !contains(value, dom)) {
// add the dom node into the array
if (isArr)
value.push(dom)
else
parent[key] = [value, dom]
}
}
|
[
"function",
"(",
"value",
")",
"{",
"// avoid to override the tag properties already set",
"if",
"(",
"contains",
"(",
"keys",
",",
"key",
")",
")",
"return",
"// check whether this value is an array",
"isArr",
"=",
"isArray",
"(",
"value",
")",
"// if the key was never set",
"if",
"(",
"!",
"value",
")",
"// set it once on the tag instance",
"parent",
"[",
"key",
"]",
"=",
"dom",
"// if it was an array and not yet set",
"else",
"if",
"(",
"!",
"isArr",
"||",
"isArr",
"&&",
"!",
"contains",
"(",
"value",
",",
"dom",
")",
")",
"{",
"// add the dom node into the array",
"if",
"(",
"isArr",
")",
"value",
".",
"push",
"(",
"dom",
")",
"else",
"parent",
"[",
"key",
"]",
"=",
"[",
"value",
",",
"dom",
"]",
"}",
"}"
] |
get the key value we want to add to the tag instance
|
[
"get",
"the",
"key",
"value",
"we",
"want",
"to",
"add",
"to",
"the",
"tag",
"instance"
] |
5f31820d702a329e8aa25f0f3983f13097610250
|
https://github.com/aMarCruz/jspreproc/blob/5f31820d702a329e8aa25f0f3983f13097610250/spec/uglify/riot.js#L2134-L2151
|
|
36,215 |
fin-hypergrid/grouped-header-plugin
|
index.js
|
isColumnReorderable
|
function isColumnReorderable() {
var originalMethodFromPrototype = Object.getPrototypeOf(this).isColumnReorderable,
isReorderable = originalMethodFromPrototype.call(this),
groupedHeaderCellRenderer = this.grid.cellRenderers.get(CLASS_NAME),
delimiter = groupedHeaderCellRenderer.delimiter;
return (
isReorderable &&
!this.columns.find(function(column) { // but only if no grouped columns
return column.getCellProperty(0, 'renderer') === CLASS_NAME && // header cell using GroupedHeader
column.header.indexOf(delimiter) !== -1; // header is part of a group
})
);
}
|
javascript
|
function isColumnReorderable() {
var originalMethodFromPrototype = Object.getPrototypeOf(this).isColumnReorderable,
isReorderable = originalMethodFromPrototype.call(this),
groupedHeaderCellRenderer = this.grid.cellRenderers.get(CLASS_NAME),
delimiter = groupedHeaderCellRenderer.delimiter;
return (
isReorderable &&
!this.columns.find(function(column) { // but only if no grouped columns
return column.getCellProperty(0, 'renderer') === CLASS_NAME && // header cell using GroupedHeader
column.header.indexOf(delimiter) !== -1; // header is part of a group
})
);
}
|
[
"function",
"isColumnReorderable",
"(",
")",
"{",
"var",
"originalMethodFromPrototype",
"=",
"Object",
".",
"getPrototypeOf",
"(",
"this",
")",
".",
"isColumnReorderable",
",",
"isReorderable",
"=",
"originalMethodFromPrototype",
".",
"call",
"(",
"this",
")",
",",
"groupedHeaderCellRenderer",
"=",
"this",
".",
"grid",
".",
"cellRenderers",
".",
"get",
"(",
"CLASS_NAME",
")",
",",
"delimiter",
"=",
"groupedHeaderCellRenderer",
".",
"delimiter",
";",
"return",
"(",
"isReorderable",
"&&",
"!",
"this",
".",
"columns",
".",
"find",
"(",
"function",
"(",
"column",
")",
"{",
"// but only if no grouped columns",
"return",
"column",
".",
"getCellProperty",
"(",
"0",
",",
"'renderer'",
")",
"===",
"CLASS_NAME",
"&&",
"// header cell using GroupedHeader",
"column",
".",
"header",
".",
"indexOf",
"(",
"delimiter",
")",
"!==",
"-",
"1",
";",
"// header is part of a group",
"}",
")",
")",
";",
"}"
] |
Prevent column moving when there are any grouped headers.
@returns {boolean}
@memberOf groupedHeader
@inner
|
[
"Prevent",
"column",
"moving",
"when",
"there",
"are",
"any",
"grouped",
"headers",
"."
] |
c73214e72242e2d0a2687f9dffa359a68e323be0
|
https://github.com/fin-hypergrid/grouped-header-plugin/blob/c73214e72242e2d0a2687f9dffa359a68e323be0/index.js#L299-L312
|
36,216 |
athombv/node-linux-device
|
lib/Compat.js
|
utilCallbackAfterPromise
|
function utilCallbackAfterPromise(self, func, args, cb) {
args = Array.prototype.slice.apply(args);
let lastarg = args.pop();
if(!cb) cb = lastarg;
func.apply(self, args).then(res => {
try {
cb(null, res);
} catch(e) {
process.nextTick(() => { throw e });
}
}).catch((err) => {
try {
cb(err);
} catch(e) {
process.nextTick(() => { throw e });
}
});
}
|
javascript
|
function utilCallbackAfterPromise(self, func, args, cb) {
args = Array.prototype.slice.apply(args);
let lastarg = args.pop();
if(!cb) cb = lastarg;
func.apply(self, args).then(res => {
try {
cb(null, res);
} catch(e) {
process.nextTick(() => { throw e });
}
}).catch((err) => {
try {
cb(err);
} catch(e) {
process.nextTick(() => { throw e });
}
});
}
|
[
"function",
"utilCallbackAfterPromise",
"(",
"self",
",",
"func",
",",
"args",
",",
"cb",
")",
"{",
"args",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"apply",
"(",
"args",
")",
";",
"let",
"lastarg",
"=",
"args",
".",
"pop",
"(",
")",
";",
"if",
"(",
"!",
"cb",
")",
"cb",
"=",
"lastarg",
";",
"func",
".",
"apply",
"(",
"self",
",",
"args",
")",
".",
"then",
"(",
"res",
"=>",
"{",
"try",
"{",
"cb",
"(",
"null",
",",
"res",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"process",
".",
"nextTick",
"(",
"(",
")",
"=>",
"{",
"throw",
"e",
"}",
")",
";",
"}",
"}",
")",
".",
"catch",
"(",
"(",
"err",
")",
"=>",
"{",
"try",
"{",
"cb",
"(",
"err",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"process",
".",
"nextTick",
"(",
"(",
")",
"=>",
"{",
"throw",
"e",
"}",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Strips the callback argument, and calls the function without, then invokes the callback when the promise returns
|
[
"Strips",
"the",
"callback",
"argument",
"and",
"calls",
"the",
"function",
"without",
"then",
"invokes",
"the",
"callback",
"when",
"the",
"promise",
"returns"
] |
43ce13c5718d5ee0d0f0424f5541c28fd4882b3c
|
https://github.com/athombv/node-linux-device/blob/43ce13c5718d5ee0d0f0424f5541c28fd4882b3c/lib/Compat.js#L7-L24
|
36,217 |
ILLGrenoble/guacamole-common-js
|
src/OnScreenKeyboard.js
|
removeClass
|
function removeClass(element, classname) {
// If classList supported, use that
if (element.classList)
element.classList.remove(classname);
// Otherwise, manually filter out classes with given name
else {
element.className = element.className.replace(/([^ ]+)[ ]*/g,
function removeMatchingClasses(match, testClassname) {
// If same class, remove
if (testClassname === classname)
return "";
// Otherwise, allow
return match;
}
);
}
}
|
javascript
|
function removeClass(element, classname) {
// If classList supported, use that
if (element.classList)
element.classList.remove(classname);
// Otherwise, manually filter out classes with given name
else {
element.className = element.className.replace(/([^ ]+)[ ]*/g,
function removeMatchingClasses(match, testClassname) {
// If same class, remove
if (testClassname === classname)
return "";
// Otherwise, allow
return match;
}
);
}
}
|
[
"function",
"removeClass",
"(",
"element",
",",
"classname",
")",
"{",
"// If classList supported, use that",
"if",
"(",
"element",
".",
"classList",
")",
"element",
".",
"classList",
".",
"remove",
"(",
"classname",
")",
";",
"// Otherwise, manually filter out classes with given name",
"else",
"{",
"element",
".",
"className",
"=",
"element",
".",
"className",
".",
"replace",
"(",
"/",
"([^ ]+)[ ]*",
"/",
"g",
",",
"function",
"removeMatchingClasses",
"(",
"match",
",",
"testClassname",
")",
"{",
"// If same class, remove",
"if",
"(",
"testClassname",
"===",
"classname",
")",
"return",
"\"\"",
";",
"// Otherwise, allow",
"return",
"match",
";",
"}",
")",
";",
"}",
"}"
] |
Removes a CSS class from an element.
@private
@function
@param {Element} element
The element to remove a class from.
@param {String} classname
The name of the class to remove.
|
[
"Removes",
"a",
"CSS",
"class",
"from",
"an",
"element",
"."
] |
71925794155ea3fc37d2a125adbca6f8be532887
|
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/OnScreenKeyboard.js#L106-L128
|
36,218 |
ILLGrenoble/guacamole-common-js
|
src/OnScreenKeyboard.js
|
modifiersPressed
|
function modifiersPressed(names) {
// If any required modifiers are not pressed, return false
for (var i=0; i < names.length; i++) {
// Test whether current modifier is pressed
var name = names[i];
if (!(name in modifierKeysyms))
return false;
}
// Otherwise, all required modifiers are pressed
return true;
}
|
javascript
|
function modifiersPressed(names) {
// If any required modifiers are not pressed, return false
for (var i=0; i < names.length; i++) {
// Test whether current modifier is pressed
var name = names[i];
if (!(name in modifierKeysyms))
return false;
}
// Otherwise, all required modifiers are pressed
return true;
}
|
[
"function",
"modifiersPressed",
"(",
"names",
")",
"{",
"// If any required modifiers are not pressed, return false",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"names",
".",
"length",
";",
"i",
"++",
")",
"{",
"// Test whether current modifier is pressed",
"var",
"name",
"=",
"names",
"[",
"i",
"]",
";",
"if",
"(",
"!",
"(",
"name",
"in",
"modifierKeysyms",
")",
")",
"return",
"false",
";",
"}",
"// Otherwise, all required modifiers are pressed",
"return",
"true",
";",
"}"
] |
Returns whether all modifiers having the given names are currently
active.
@private
@param {String[]} names
The names of all modifiers to test.
@returns {Boolean}
true if all specified modifiers are pressed, false otherwise.
|
[
"Returns",
"whether",
"all",
"modifiers",
"having",
"the",
"given",
"names",
"are",
"currently",
"active",
"."
] |
71925794155ea3fc37d2a125adbca6f8be532887
|
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/OnScreenKeyboard.js#L223-L238
|
36,219 |
ILLGrenoble/guacamole-common-js
|
src/OnScreenKeyboard.js
|
press
|
function press(keyName, keyElement) {
// Press key if not yet pressed
if (!pressed[keyName]) {
addClass(keyElement, "guac-keyboard-pressed");
// Get current key based on modifier state
var key = getActiveKey(keyName);
// Update modifier state
if (key.modifier) {
// Construct classname for modifier
var modifierClass = "guac-keyboard-modifier-" + getCSSName(key.modifier);
// Retrieve originally-pressed keysym, if modifier was already pressed
var originalKeysym = modifierKeysyms[key.modifier];
// Activate modifier if not pressed
if (!originalKeysym) {
addClass(keyboard, modifierClass);
modifierKeysyms[key.modifier] = key.keysym;
// Send key event
if (osk.onkeydown)
osk.onkeydown(key.keysym);
}
// Deactivate if not pressed
else {
removeClass(keyboard, modifierClass);
delete modifierKeysyms[key.modifier];
// Send key event
if (osk.onkeyup)
osk.onkeyup(originalKeysym);
}
}
// If not modifier, send key event now
else if (osk.onkeydown)
osk.onkeydown(key.keysym);
// Mark key as pressed
pressed[keyName] = true;
}
}
|
javascript
|
function press(keyName, keyElement) {
// Press key if not yet pressed
if (!pressed[keyName]) {
addClass(keyElement, "guac-keyboard-pressed");
// Get current key based on modifier state
var key = getActiveKey(keyName);
// Update modifier state
if (key.modifier) {
// Construct classname for modifier
var modifierClass = "guac-keyboard-modifier-" + getCSSName(key.modifier);
// Retrieve originally-pressed keysym, if modifier was already pressed
var originalKeysym = modifierKeysyms[key.modifier];
// Activate modifier if not pressed
if (!originalKeysym) {
addClass(keyboard, modifierClass);
modifierKeysyms[key.modifier] = key.keysym;
// Send key event
if (osk.onkeydown)
osk.onkeydown(key.keysym);
}
// Deactivate if not pressed
else {
removeClass(keyboard, modifierClass);
delete modifierKeysyms[key.modifier];
// Send key event
if (osk.onkeyup)
osk.onkeyup(originalKeysym);
}
}
// If not modifier, send key event now
else if (osk.onkeydown)
osk.onkeydown(key.keysym);
// Mark key as pressed
pressed[keyName] = true;
}
}
|
[
"function",
"press",
"(",
"keyName",
",",
"keyElement",
")",
"{",
"// Press key if not yet pressed",
"if",
"(",
"!",
"pressed",
"[",
"keyName",
"]",
")",
"{",
"addClass",
"(",
"keyElement",
",",
"\"guac-keyboard-pressed\"",
")",
";",
"// Get current key based on modifier state",
"var",
"key",
"=",
"getActiveKey",
"(",
"keyName",
")",
";",
"// Update modifier state",
"if",
"(",
"key",
".",
"modifier",
")",
"{",
"// Construct classname for modifier",
"var",
"modifierClass",
"=",
"\"guac-keyboard-modifier-\"",
"+",
"getCSSName",
"(",
"key",
".",
"modifier",
")",
";",
"// Retrieve originally-pressed keysym, if modifier was already pressed",
"var",
"originalKeysym",
"=",
"modifierKeysyms",
"[",
"key",
".",
"modifier",
"]",
";",
"// Activate modifier if not pressed",
"if",
"(",
"!",
"originalKeysym",
")",
"{",
"addClass",
"(",
"keyboard",
",",
"modifierClass",
")",
";",
"modifierKeysyms",
"[",
"key",
".",
"modifier",
"]",
"=",
"key",
".",
"keysym",
";",
"// Send key event",
"if",
"(",
"osk",
".",
"onkeydown",
")",
"osk",
".",
"onkeydown",
"(",
"key",
".",
"keysym",
")",
";",
"}",
"// Deactivate if not pressed",
"else",
"{",
"removeClass",
"(",
"keyboard",
",",
"modifierClass",
")",
";",
"delete",
"modifierKeysyms",
"[",
"key",
".",
"modifier",
"]",
";",
"// Send key event",
"if",
"(",
"osk",
".",
"onkeyup",
")",
"osk",
".",
"onkeyup",
"(",
"originalKeysym",
")",
";",
"}",
"}",
"// If not modifier, send key event now",
"else",
"if",
"(",
"osk",
".",
"onkeydown",
")",
"osk",
".",
"onkeydown",
"(",
"key",
".",
"keysym",
")",
";",
"// Mark key as pressed",
"pressed",
"[",
"keyName",
"]",
"=",
"true",
";",
"}",
"}"
] |
Presses the key having the given name, updating the associated key
element with the "guac-keyboard-pressed" CSS class. If the key is
already pressed, this function has no effect.
@private
@param {String} keyName
The name of the key to press.
@param {String} keyElement
The element associated with the given key.
|
[
"Presses",
"the",
"key",
"having",
"the",
"given",
"name",
"updating",
"the",
"associated",
"key",
"element",
"with",
"the",
"guac",
"-",
"keyboard",
"-",
"pressed",
"CSS",
"class",
".",
"If",
"the",
"key",
"is",
"already",
"pressed",
"this",
"function",
"has",
"no",
"effect",
"."
] |
71925794155ea3fc37d2a125adbca6f8be532887
|
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/OnScreenKeyboard.js#L290-L344
|
36,220 |
ILLGrenoble/guacamole-common-js
|
src/OnScreenKeyboard.js
|
release
|
function release(keyName, keyElement) {
// Release key if currently pressed
if (pressed[keyName]) {
removeClass(keyElement, "guac-keyboard-pressed");
// Get current key based on modifier state
var key = getActiveKey(keyName);
// Send key event if not a modifier key
if (!key.modifier && osk.onkeyup)
osk.onkeyup(key.keysym);
// Mark key as released
pressed[keyName] = false;
}
}
|
javascript
|
function release(keyName, keyElement) {
// Release key if currently pressed
if (pressed[keyName]) {
removeClass(keyElement, "guac-keyboard-pressed");
// Get current key based on modifier state
var key = getActiveKey(keyName);
// Send key event if not a modifier key
if (!key.modifier && osk.onkeyup)
osk.onkeyup(key.keysym);
// Mark key as released
pressed[keyName] = false;
}
}
|
[
"function",
"release",
"(",
"keyName",
",",
"keyElement",
")",
"{",
"// Release key if currently pressed",
"if",
"(",
"pressed",
"[",
"keyName",
"]",
")",
"{",
"removeClass",
"(",
"keyElement",
",",
"\"guac-keyboard-pressed\"",
")",
";",
"// Get current key based on modifier state",
"var",
"key",
"=",
"getActiveKey",
"(",
"keyName",
")",
";",
"// Send key event if not a modifier key",
"if",
"(",
"!",
"key",
".",
"modifier",
"&&",
"osk",
".",
"onkeyup",
")",
"osk",
".",
"onkeyup",
"(",
"key",
".",
"keysym",
")",
";",
"// Mark key as released",
"pressed",
"[",
"keyName",
"]",
"=",
"false",
";",
"}",
"}"
] |
Releases the key having the given name, removing the
"guac-keyboard-pressed" CSS class from the associated element. If the
key is already released, this function has no effect.
@private
@param {String} keyName
The name of the key to release.
@param {String} keyElement
The element associated with the given key.
|
[
"Releases",
"the",
"key",
"having",
"the",
"given",
"name",
"removing",
"the",
"guac",
"-",
"keyboard",
"-",
"pressed",
"CSS",
"class",
"from",
"the",
"associated",
"element",
".",
"If",
"the",
"key",
"is",
"already",
"released",
"this",
"function",
"has",
"no",
"effect",
"."
] |
71925794155ea3fc37d2a125adbca6f8be532887
|
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/OnScreenKeyboard.js#L358-L377
|
36,221 |
ILLGrenoble/guacamole-common-js
|
src/OnScreenKeyboard.js
|
getKeys
|
function getKeys(keys) {
var keyArrays = {};
// Coerce all keys into individual key arrays
for (var name in layout.keys) {
keyArrays[name] = asKeyArray(name, keys[name]);
}
return keyArrays;
}
|
javascript
|
function getKeys(keys) {
var keyArrays = {};
// Coerce all keys into individual key arrays
for (var name in layout.keys) {
keyArrays[name] = asKeyArray(name, keys[name]);
}
return keyArrays;
}
|
[
"function",
"getKeys",
"(",
"keys",
")",
"{",
"var",
"keyArrays",
"=",
"{",
"}",
";",
"// Coerce all keys into individual key arrays",
"for",
"(",
"var",
"name",
"in",
"layout",
".",
"keys",
")",
"{",
"keyArrays",
"[",
"name",
"]",
"=",
"asKeyArray",
"(",
"name",
",",
"keys",
"[",
"name",
"]",
")",
";",
"}",
"return",
"keyArrays",
";",
"}"
] |
Converts the rather forgiving key mapping allowed by
Guacamole.OnScreenKeyboard.Layout into a rigorous mapping of key name
to key definition, where the key definition is always an array of Key
objects.
@private
@param {Object.<String, Number|String|Guacamole.OnScreenKeyboard.Key|Guacamole.OnScreenKeyboard.Key[]>} keys
A mapping of key name to key definition, where the key definition is
the title of the key (a string), the keysym (a number), a single
Key object, or an array of Key objects.
@returns {Object.<String, Guacamole.OnScreenKeyboard.Key[]>}
A more-predictable mapping of key name to key definition, where the
key definition is always simply an array of Key objects.
|
[
"Converts",
"the",
"rather",
"forgiving",
"key",
"mapping",
"allowed",
"by",
"Guacamole",
".",
"OnScreenKeyboard",
".",
"Layout",
"into",
"a",
"rigorous",
"mapping",
"of",
"key",
"name",
"to",
"key",
"definition",
"where",
"the",
"key",
"definition",
"is",
"always",
"an",
"array",
"of",
"Key",
"objects",
"."
] |
71925794155ea3fc37d2a125adbca6f8be532887
|
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/OnScreenKeyboard.js#L535-L546
|
36,222 |
ILLGrenoble/guacamole-common-js
|
src/OnScreenKeyboard.js
|
getCSSName
|
function getCSSName(name) {
// Convert name from possibly-CamelCase to hyphenated lowercase
var cssName = name
.replace(/([a-z])([A-Z])/g, '$1-$2')
.replace(/[^A-Za-z0-9]+/g, '-')
.toLowerCase();
return cssName;
}
|
javascript
|
function getCSSName(name) {
// Convert name from possibly-CamelCase to hyphenated lowercase
var cssName = name
.replace(/([a-z])([A-Z])/g, '$1-$2')
.replace(/[^A-Za-z0-9]+/g, '-')
.toLowerCase();
return cssName;
}
|
[
"function",
"getCSSName",
"(",
"name",
")",
"{",
"// Convert name from possibly-CamelCase to hyphenated lowercase",
"var",
"cssName",
"=",
"name",
".",
"replace",
"(",
"/",
"([a-z])([A-Z])",
"/",
"g",
",",
"'$1-$2'",
")",
".",
"replace",
"(",
"/",
"[^A-Za-z0-9]+",
"/",
"g",
",",
"'-'",
")",
".",
"toLowerCase",
"(",
")",
";",
"return",
"cssName",
";",
"}"
] |
Given an arbitrary string representing the name of some component of the
on-screen keyboard, returns a string formatted for use as a CSS class
name. The result will be lowercase. Word boundaries previously denoted
by CamelCase will be replaced by individual hyphens, as will all
contiguous non-alphanumeric characters.
@private
@param {String} name
An arbitrary string representing the name of some component of the
on-screen keyboard.
@returns {String}
A string formatted for use as a CSS class name.
|
[
"Given",
"an",
"arbitrary",
"string",
"representing",
"the",
"name",
"of",
"some",
"component",
"of",
"the",
"on",
"-",
"screen",
"keyboard",
"returns",
"a",
"string",
"formatted",
"for",
"use",
"as",
"a",
"CSS",
"class",
"name",
".",
"The",
"result",
"will",
"be",
"lowercase",
".",
"Word",
"boundaries",
"previously",
"denoted",
"by",
"CamelCase",
"will",
"be",
"replaced",
"by",
"individual",
"hyphens",
"as",
"will",
"all",
"contiguous",
"non",
"-",
"alphanumeric",
"characters",
"."
] |
71925794155ea3fc37d2a125adbca6f8be532887
|
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/OnScreenKeyboard.js#L571-L581
|
36,223 |
ILLGrenoble/guacamole-common-js
|
src/OnScreenKeyboard.js
|
touchPress
|
function touchPress(e) {
e.preventDefault();
ignoreMouse = osk.touchMouseThreshold;
press(object, keyElement);
}
|
javascript
|
function touchPress(e) {
e.preventDefault();
ignoreMouse = osk.touchMouseThreshold;
press(object, keyElement);
}
|
[
"function",
"touchPress",
"(",
"e",
")",
"{",
"e",
".",
"preventDefault",
"(",
")",
";",
"ignoreMouse",
"=",
"osk",
".",
"touchMouseThreshold",
";",
"press",
"(",
"object",
",",
"keyElement",
")",
";",
"}"
] |
Handles a touch event which results in the pressing of an OSK
key. Touch events will result in mouse events being ignored for
touchMouseThreshold events.
@private
@param {TouchEvent} e
The touch event being handled.
|
[
"Handles",
"a",
"touch",
"event",
"which",
"results",
"in",
"the",
"pressing",
"of",
"an",
"OSK",
"key",
".",
"Touch",
"events",
"will",
"result",
"in",
"mouse",
"events",
"being",
"ignored",
"for",
"touchMouseThreshold",
"events",
"."
] |
71925794155ea3fc37d2a125adbca6f8be532887
|
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/OnScreenKeyboard.js#L726-L730
|
36,224 |
ILLGrenoble/guacamole-common-js
|
src/OnScreenKeyboard.js
|
touchRelease
|
function touchRelease(e) {
e.preventDefault();
ignoreMouse = osk.touchMouseThreshold;
release(object, keyElement);
}
|
javascript
|
function touchRelease(e) {
e.preventDefault();
ignoreMouse = osk.touchMouseThreshold;
release(object, keyElement);
}
|
[
"function",
"touchRelease",
"(",
"e",
")",
"{",
"e",
".",
"preventDefault",
"(",
")",
";",
"ignoreMouse",
"=",
"osk",
".",
"touchMouseThreshold",
";",
"release",
"(",
"object",
",",
"keyElement",
")",
";",
"}"
] |
Handles a touch event which results in the release of an OSK
key. Touch events will result in mouse events being ignored for
touchMouseThreshold events.
@private
@param {TouchEvent} e
The touch event being handled.
|
[
"Handles",
"a",
"touch",
"event",
"which",
"results",
"in",
"the",
"release",
"of",
"an",
"OSK",
"key",
".",
"Touch",
"events",
"will",
"result",
"in",
"mouse",
"events",
"being",
"ignored",
"for",
"touchMouseThreshold",
"events",
"."
] |
71925794155ea3fc37d2a125adbca6f8be532887
|
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/OnScreenKeyboard.js#L741-L745
|
36,225 |
Twipped/QueryizeJS
|
lib/mutators.js
|
_makeJoiner
|
function _makeJoiner (type) {
return function (clause, options) {
if (isQueryizeObject(clause)) {
if (typeof options !== 'object') throw new Error('You must define join options when joining against a queryize subquery.');
options = Object.create(options);
options.table = clause;
clause = options;
} else if (typeof clause === 'object') {
if (isArray(clause)) throw new TypeError('Join clauses can only be strings or object definitions');
if (!clause.table) throw new Error('You must define a table to join against');
} else if (typeof options === 'object') {
options = Object.create(options);
options.table = clause;
clause = options;
}
if (typeof clause === 'object') {
clause.type = type;
} else {
clause = clause.search(joinTest) > -1 ? clause.replace(joinTest, type + ' JOIN ') : type + ' JOIN ' + clause;
}
this.join(clause);
return this;
};
}
|
javascript
|
function _makeJoiner (type) {
return function (clause, options) {
if (isQueryizeObject(clause)) {
if (typeof options !== 'object') throw new Error('You must define join options when joining against a queryize subquery.');
options = Object.create(options);
options.table = clause;
clause = options;
} else if (typeof clause === 'object') {
if (isArray(clause)) throw new TypeError('Join clauses can only be strings or object definitions');
if (!clause.table) throw new Error('You must define a table to join against');
} else if (typeof options === 'object') {
options = Object.create(options);
options.table = clause;
clause = options;
}
if (typeof clause === 'object') {
clause.type = type;
} else {
clause = clause.search(joinTest) > -1 ? clause.replace(joinTest, type + ' JOIN ') : type + ' JOIN ' + clause;
}
this.join(clause);
return this;
};
}
|
[
"function",
"_makeJoiner",
"(",
"type",
")",
"{",
"return",
"function",
"(",
"clause",
",",
"options",
")",
"{",
"if",
"(",
"isQueryizeObject",
"(",
"clause",
")",
")",
"{",
"if",
"(",
"typeof",
"options",
"!==",
"'object'",
")",
"throw",
"new",
"Error",
"(",
"'You must define join options when joining against a queryize subquery.'",
")",
";",
"options",
"=",
"Object",
".",
"create",
"(",
"options",
")",
";",
"options",
".",
"table",
"=",
"clause",
";",
"clause",
"=",
"options",
";",
"}",
"else",
"if",
"(",
"typeof",
"clause",
"===",
"'object'",
")",
"{",
"if",
"(",
"isArray",
"(",
"clause",
")",
")",
"throw",
"new",
"TypeError",
"(",
"'Join clauses can only be strings or object definitions'",
")",
";",
"if",
"(",
"!",
"clause",
".",
"table",
")",
"throw",
"new",
"Error",
"(",
"'You must define a table to join against'",
")",
";",
"}",
"else",
"if",
"(",
"typeof",
"options",
"===",
"'object'",
")",
"{",
"options",
"=",
"Object",
".",
"create",
"(",
"options",
")",
";",
"options",
".",
"table",
"=",
"clause",
";",
"clause",
"=",
"options",
";",
"}",
"if",
"(",
"typeof",
"clause",
"===",
"'object'",
")",
"{",
"clause",
".",
"type",
"=",
"type",
";",
"}",
"else",
"{",
"clause",
"=",
"clause",
".",
"search",
"(",
"joinTest",
")",
">",
"-",
"1",
"?",
"clause",
".",
"replace",
"(",
"joinTest",
",",
"type",
"+",
"' JOIN '",
")",
":",
"type",
"+",
"' JOIN '",
"+",
"clause",
";",
"}",
"this",
".",
"join",
"(",
"clause",
")",
";",
"return",
"this",
";",
"}",
";",
"}"
] |
Generates the closures for innerJoin, leftJoin and rightJoin
@private
@param {string} type Join type
@return {function}
|
[
"Generates",
"the",
"closures",
"for",
"innerJoin",
"leftJoin",
"and",
"rightJoin"
] |
fdee3e8900f6a95419b88056916577f9b0067c93
|
https://github.com/Twipped/QueryizeJS/blob/fdee3e8900f6a95419b88056916577f9b0067c93/lib/mutators.js#L1189-L1216
|
36,226 |
Twipped/QueryizeJS
|
lib/mutators.js
|
flatten
|
function flatten (input, includingObjects) {
var result = [];
function descend (level) {
if (isArray(level)) {
level.forEach(descend);
} else if (typeof level === 'object' && includingObjects) {
Object.keys(level).forEach(function (key) {
descend(level[key]);
});
} else {
result.push(level);
}
}
descend(input);
return result;
}
|
javascript
|
function flatten (input, includingObjects) {
var result = [];
function descend (level) {
if (isArray(level)) {
level.forEach(descend);
} else if (typeof level === 'object' && includingObjects) {
Object.keys(level).forEach(function (key) {
descend(level[key]);
});
} else {
result.push(level);
}
}
descend(input);
return result;
}
|
[
"function",
"flatten",
"(",
"input",
",",
"includingObjects",
")",
"{",
"var",
"result",
"=",
"[",
"]",
";",
"function",
"descend",
"(",
"level",
")",
"{",
"if",
"(",
"isArray",
"(",
"level",
")",
")",
"{",
"level",
".",
"forEach",
"(",
"descend",
")",
";",
"}",
"else",
"if",
"(",
"typeof",
"level",
"===",
"'object'",
"&&",
"includingObjects",
")",
"{",
"Object",
".",
"keys",
"(",
"level",
")",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"descend",
"(",
"level",
"[",
"key",
"]",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"result",
".",
"push",
"(",
"level",
")",
";",
"}",
"}",
"descend",
"(",
"input",
")",
";",
"return",
"result",
";",
"}"
] |
Flattens a nested array into a single level array
@private
@param {Array} input The top level array to flatten
@param {boolean} [includingObjects=false] If an object is encountered and this argument is truthy, the object will also be flattened by its property values.
@return {Array}
|
[
"Flattens",
"a",
"nested",
"array",
"into",
"a",
"single",
"level",
"array"
] |
fdee3e8900f6a95419b88056916577f9b0067c93
|
https://github.com/Twipped/QueryizeJS/blob/fdee3e8900f6a95419b88056916577f9b0067c93/lib/mutators.js#L1922-L1940
|
36,227 |
Twipped/QueryizeJS
|
lib/mutators.js
|
mysqlDate
|
function mysqlDate (input) {
var date = new Date(input.getTime());
date.setMinutes(date.getMinutes() + date.getTimezoneOffset());
var y = date.getFullYear();
var m = ('0' + (date.getMonth() + 1)).substr(-2);
var d = ('0' + date.getDate()).substr(-2);
var h = ('0' + date.getHours()).substr(-2);
var i = ('0' + date.getMinutes()).substr(-2);
var s = ('0' + date.getSeconds()).substr(-2);
return y + '-' + m + '-' + d + ' ' + h + ':' + i + ':' + s;
}
|
javascript
|
function mysqlDate (input) {
var date = new Date(input.getTime());
date.setMinutes(date.getMinutes() + date.getTimezoneOffset());
var y = date.getFullYear();
var m = ('0' + (date.getMonth() + 1)).substr(-2);
var d = ('0' + date.getDate()).substr(-2);
var h = ('0' + date.getHours()).substr(-2);
var i = ('0' + date.getMinutes()).substr(-2);
var s = ('0' + date.getSeconds()).substr(-2);
return y + '-' + m + '-' + d + ' ' + h + ':' + i + ':' + s;
}
|
[
"function",
"mysqlDate",
"(",
"input",
")",
"{",
"var",
"date",
"=",
"new",
"Date",
"(",
"input",
".",
"getTime",
"(",
")",
")",
";",
"date",
".",
"setMinutes",
"(",
"date",
".",
"getMinutes",
"(",
")",
"+",
"date",
".",
"getTimezoneOffset",
"(",
")",
")",
";",
"var",
"y",
"=",
"date",
".",
"getFullYear",
"(",
")",
";",
"var",
"m",
"=",
"(",
"'0'",
"+",
"(",
"date",
".",
"getMonth",
"(",
")",
"+",
"1",
")",
")",
".",
"substr",
"(",
"-",
"2",
")",
";",
"var",
"d",
"=",
"(",
"'0'",
"+",
"date",
".",
"getDate",
"(",
")",
")",
".",
"substr",
"(",
"-",
"2",
")",
";",
"var",
"h",
"=",
"(",
"'0'",
"+",
"date",
".",
"getHours",
"(",
")",
")",
".",
"substr",
"(",
"-",
"2",
")",
";",
"var",
"i",
"=",
"(",
"'0'",
"+",
"date",
".",
"getMinutes",
"(",
")",
")",
".",
"substr",
"(",
"-",
"2",
")",
";",
"var",
"s",
"=",
"(",
"'0'",
"+",
"date",
".",
"getSeconds",
"(",
")",
")",
".",
"substr",
"(",
"-",
"2",
")",
";",
"return",
"y",
"+",
"'-'",
"+",
"m",
"+",
"'-'",
"+",
"d",
"+",
"' '",
"+",
"h",
"+",
"':'",
"+",
"i",
"+",
"':'",
"+",
"s",
";",
"}"
] |
Formats a Date object into a MySQL DATETIME
@param {Date} date [description]
@private
@return {string} [description]
|
[
"Formats",
"a",
"Date",
"object",
"into",
"a",
"MySQL",
"DATETIME"
] |
fdee3e8900f6a95419b88056916577f9b0067c93
|
https://github.com/Twipped/QueryizeJS/blob/fdee3e8900f6a95419b88056916577f9b0067c93/lib/mutators.js#L1948-L1960
|
36,228 |
Twipped/QueryizeJS
|
lib/mutators.js
|
arrayFromArguments
|
function arrayFromArguments () {
var len = arguments.length;
var args = new Array(len);
for (var i = 0; i < len; ++i) {
args[i] = arguments[i];
}
return args;
}
|
javascript
|
function arrayFromArguments () {
var len = arguments.length;
var args = new Array(len);
for (var i = 0; i < len; ++i) {
args[i] = arguments[i];
}
return args;
}
|
[
"function",
"arrayFromArguments",
"(",
")",
"{",
"var",
"len",
"=",
"arguments",
".",
"length",
";",
"var",
"args",
"=",
"new",
"Array",
"(",
"len",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"len",
";",
"++",
"i",
")",
"{",
"args",
"[",
"i",
"]",
"=",
"arguments",
"[",
"i",
"]",
";",
"}",
"return",
"args",
";",
"}"
] |
Helper function to convert arguments to an array without triggering de-optimization in V8
MUST be called via .apply
@private
@return {Array<mixed>}
|
[
"Helper",
"function",
"to",
"convert",
"arguments",
"to",
"an",
"array",
"without",
"triggering",
"de",
"-",
"optimization",
"in",
"V8",
"MUST",
"be",
"called",
"via",
".",
"apply"
] |
fdee3e8900f6a95419b88056916577f9b0067c93
|
https://github.com/Twipped/QueryizeJS/blob/fdee3e8900f6a95419b88056916577f9b0067c93/lib/mutators.js#L1968-L1975
|
36,229 |
latentflip/base32-crockford-browser
|
dist/base32.js
|
function() {
var table = {}
// Invert 'alphabet'
for (var i = 0; i < alphabet.length; i++) {
table[alphabet[i]] = i
}
// Splice in 'alias'
for (var key in alias) {
if (!alias.hasOwnProperty(key)) continue
table[key] = table['' + alias[key]]
}
lookup = function() { return table }
return table
}
|
javascript
|
function() {
var table = {}
// Invert 'alphabet'
for (var i = 0; i < alphabet.length; i++) {
table[alphabet[i]] = i
}
// Splice in 'alias'
for (var key in alias) {
if (!alias.hasOwnProperty(key)) continue
table[key] = table['' + alias[key]]
}
lookup = function() { return table }
return table
}
|
[
"function",
"(",
")",
"{",
"var",
"table",
"=",
"{",
"}",
"// Invert 'alphabet'",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"alphabet",
".",
"length",
";",
"i",
"++",
")",
"{",
"table",
"[",
"alphabet",
"[",
"i",
"]",
"]",
"=",
"i",
"}",
"// Splice in 'alias'",
"for",
"(",
"var",
"key",
"in",
"alias",
")",
"{",
"if",
"(",
"!",
"alias",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"continue",
"table",
"[",
"key",
"]",
"=",
"table",
"[",
"''",
"+",
"alias",
"[",
"key",
"]",
"]",
"}",
"lookup",
"=",
"function",
"(",
")",
"{",
"return",
"table",
"}",
"return",
"table",
"}"
] |
Build a lookup table and memoize it
Return an object that maps a character to its
byte value.
|
[
"Build",
"a",
"lookup",
"table",
"and",
"memoize",
"it"
] |
6ae0826cc89838fc935160e8547edf77f6690858
|
https://github.com/latentflip/base32-crockford-browser/blob/6ae0826cc89838fc935160e8547edf77f6690858/dist/base32.js#L16-L29
|
|
36,230 |
latentflip/base32-crockford-browser
|
dist/base32.js
|
Encoder
|
function Encoder() {
var skip = 0 // how many bits we will skip from the first byte
var bits = 0 // 5 high bits, carry from one byte to the next
this.output = ''
// Read one byte of input
// Should not really be used except by "update"
this.readByte = function(byte) {
// coerce the byte to an int
if (typeof byte == 'string') byte = byte.charCodeAt(0)
if (skip < 0) { // we have a carry from the previous byte
bits |= (byte >> (-skip))
} else { // no carry
bits = (byte << skip) & 248
}
if (skip > 3) {
// not enough data to produce a character, get us another one
skip -= 8
return 1
}
if (skip < 4) {
// produce a character
this.output += alphabet[bits >> 3]
skip += 5
}
return 0
}
// Flush any remaining bits left in the stream
this.finish = function(check) {
var output = this.output + (skip < 0 ? alphabet[bits >> 3] : '') + (check ? '$' : '')
this.output = ''
return output
}
}
|
javascript
|
function Encoder() {
var skip = 0 // how many bits we will skip from the first byte
var bits = 0 // 5 high bits, carry from one byte to the next
this.output = ''
// Read one byte of input
// Should not really be used except by "update"
this.readByte = function(byte) {
// coerce the byte to an int
if (typeof byte == 'string') byte = byte.charCodeAt(0)
if (skip < 0) { // we have a carry from the previous byte
bits |= (byte >> (-skip))
} else { // no carry
bits = (byte << skip) & 248
}
if (skip > 3) {
// not enough data to produce a character, get us another one
skip -= 8
return 1
}
if (skip < 4) {
// produce a character
this.output += alphabet[bits >> 3]
skip += 5
}
return 0
}
// Flush any remaining bits left in the stream
this.finish = function(check) {
var output = this.output + (skip < 0 ? alphabet[bits >> 3] : '') + (check ? '$' : '')
this.output = ''
return output
}
}
|
[
"function",
"Encoder",
"(",
")",
"{",
"var",
"skip",
"=",
"0",
"// how many bits we will skip from the first byte",
"var",
"bits",
"=",
"0",
"// 5 high bits, carry from one byte to the next",
"this",
".",
"output",
"=",
"''",
"// Read one byte of input",
"// Should not really be used except by \"update\"",
"this",
".",
"readByte",
"=",
"function",
"(",
"byte",
")",
"{",
"// coerce the byte to an int",
"if",
"(",
"typeof",
"byte",
"==",
"'string'",
")",
"byte",
"=",
"byte",
".",
"charCodeAt",
"(",
"0",
")",
"if",
"(",
"skip",
"<",
"0",
")",
"{",
"// we have a carry from the previous byte",
"bits",
"|=",
"(",
"byte",
">>",
"(",
"-",
"skip",
")",
")",
"}",
"else",
"{",
"// no carry",
"bits",
"=",
"(",
"byte",
"<<",
"skip",
")",
"&",
"248",
"}",
"if",
"(",
"skip",
">",
"3",
")",
"{",
"// not enough data to produce a character, get us another one",
"skip",
"-=",
"8",
"return",
"1",
"}",
"if",
"(",
"skip",
"<",
"4",
")",
"{",
"// produce a character",
"this",
".",
"output",
"+=",
"alphabet",
"[",
"bits",
">>",
"3",
"]",
"skip",
"+=",
"5",
"}",
"return",
"0",
"}",
"// Flush any remaining bits left in the stream",
"this",
".",
"finish",
"=",
"function",
"(",
"check",
")",
"{",
"var",
"output",
"=",
"this",
".",
"output",
"+",
"(",
"skip",
"<",
"0",
"?",
"alphabet",
"[",
"bits",
">>",
"3",
"]",
":",
"''",
")",
"+",
"(",
"check",
"?",
"'$'",
":",
"''",
")",
"this",
".",
"output",
"=",
"''",
"return",
"output",
"}",
"}"
] |
A streaming encoder
var encoder = new base32.Encoder()
var output1 = encoder.update(input1)
var output2 = encoder.update(input2)
var lastoutput = encode.update(lastinput, true)
|
[
"A",
"streaming",
"encoder"
] |
6ae0826cc89838fc935160e8547edf77f6690858
|
https://github.com/latentflip/base32-crockford-browser/blob/6ae0826cc89838fc935160e8547edf77f6690858/dist/base32.js#L40-L79
|
36,231 |
latentflip/base32-crockford-browser
|
dist/base32.js
|
Decoder
|
function Decoder() {
var skip = 0 // how many bits we have from the previous character
var byte = 0 // current byte we're producing
this.output = ''
// Consume a character from the stream, store
// the output in this.output. As before, better
// to use update().
this.readChar = function(char) {
if (typeof char != 'string'){
if (typeof char == 'number') {
char = String.fromCharCode(char)
}
}
char = char.toLowerCase()
var val = lookup()[char]
if (typeof val == 'undefined') {
// character does not exist in our lookup table
return // skip silently. An alternative would be:
// throw Error('Could not find character "' + char + '" in lookup table.')
}
val <<= 3 // move to the high bits
byte |= val >>> skip
skip += 5
if (skip >= 8) {
// we have enough to preduce output
this.output += String.fromCharCode(byte)
skip -= 8
if (skip > 0) byte = (val << (5 - skip)) & 255
else byte = 0
}
}
this.finish = function(check) {
var output = this.output + (skip < 0 ? alphabet[bits >> 3] : '') + (check ? '$' : '')
this.output = ''
return output
}
}
|
javascript
|
function Decoder() {
var skip = 0 // how many bits we have from the previous character
var byte = 0 // current byte we're producing
this.output = ''
// Consume a character from the stream, store
// the output in this.output. As before, better
// to use update().
this.readChar = function(char) {
if (typeof char != 'string'){
if (typeof char == 'number') {
char = String.fromCharCode(char)
}
}
char = char.toLowerCase()
var val = lookup()[char]
if (typeof val == 'undefined') {
// character does not exist in our lookup table
return // skip silently. An alternative would be:
// throw Error('Could not find character "' + char + '" in lookup table.')
}
val <<= 3 // move to the high bits
byte |= val >>> skip
skip += 5
if (skip >= 8) {
// we have enough to preduce output
this.output += String.fromCharCode(byte)
skip -= 8
if (skip > 0) byte = (val << (5 - skip)) & 255
else byte = 0
}
}
this.finish = function(check) {
var output = this.output + (skip < 0 ? alphabet[bits >> 3] : '') + (check ? '$' : '')
this.output = ''
return output
}
}
|
[
"function",
"Decoder",
"(",
")",
"{",
"var",
"skip",
"=",
"0",
"// how many bits we have from the previous character",
"var",
"byte",
"=",
"0",
"// current byte we're producing",
"this",
".",
"output",
"=",
"''",
"// Consume a character from the stream, store",
"// the output in this.output. As before, better",
"// to use update().",
"this",
".",
"readChar",
"=",
"function",
"(",
"char",
")",
"{",
"if",
"(",
"typeof",
"char",
"!=",
"'string'",
")",
"{",
"if",
"(",
"typeof",
"char",
"==",
"'number'",
")",
"{",
"char",
"=",
"String",
".",
"fromCharCode",
"(",
"char",
")",
"}",
"}",
"char",
"=",
"char",
".",
"toLowerCase",
"(",
")",
"var",
"val",
"=",
"lookup",
"(",
")",
"[",
"char",
"]",
"if",
"(",
"typeof",
"val",
"==",
"'undefined'",
")",
"{",
"// character does not exist in our lookup table",
"return",
"// skip silently. An alternative would be:",
"// throw Error('Could not find character \"' + char + '\" in lookup table.')",
"}",
"val",
"<<=",
"3",
"// move to the high bits",
"byte",
"|=",
"val",
">>>",
"skip",
"skip",
"+=",
"5",
"if",
"(",
"skip",
">=",
"8",
")",
"{",
"// we have enough to preduce output",
"this",
".",
"output",
"+=",
"String",
".",
"fromCharCode",
"(",
"byte",
")",
"skip",
"-=",
"8",
"if",
"(",
"skip",
">",
"0",
")",
"byte",
"=",
"(",
"val",
"<<",
"(",
"5",
"-",
"skip",
")",
")",
"&",
"255",
"else",
"byte",
"=",
"0",
"}",
"}",
"this",
".",
"finish",
"=",
"function",
"(",
"check",
")",
"{",
"var",
"output",
"=",
"this",
".",
"output",
"+",
"(",
"skip",
"<",
"0",
"?",
"alphabet",
"[",
"bits",
">>",
"3",
"]",
":",
"''",
")",
"+",
"(",
"check",
"?",
"'$'",
":",
"''",
")",
"this",
".",
"output",
"=",
"''",
"return",
"output",
"}",
"}"
] |
Functions analogously to Encoder
|
[
"Functions",
"analogously",
"to",
"Encoder"
] |
6ae0826cc89838fc935160e8547edf77f6690858
|
https://github.com/latentflip/base32-crockford-browser/blob/6ae0826cc89838fc935160e8547edf77f6690858/dist/base32.js#L105-L145
|
36,232 |
latentflip/base32-crockford-browser
|
dist/base32.js
|
decode
|
function decode(input) {
var decoder = new Decoder()
var output = decoder.update(input, true)
return output
}
|
javascript
|
function decode(input) {
var decoder = new Decoder()
var output = decoder.update(input, true)
return output
}
|
[
"function",
"decode",
"(",
"input",
")",
"{",
"var",
"decoder",
"=",
"new",
"Decoder",
"(",
")",
"var",
"output",
"=",
"decoder",
".",
"update",
"(",
"input",
",",
"true",
")",
"return",
"output",
"}"
] |
Base32-encoded string goes in, decoded data comes out.
|
[
"Base32",
"-",
"encoded",
"string",
"goes",
"in",
"decoded",
"data",
"comes",
"out",
"."
] |
6ae0826cc89838fc935160e8547edf77f6690858
|
https://github.com/latentflip/base32-crockford-browser/blob/6ae0826cc89838fc935160e8547edf77f6690858/dist/base32.js#L173-L177
|
36,233 |
delian/node-amfutils
|
amfUtils.js
|
amf3decUI29
|
function amf3decUI29(buf) {
var val = 0;
var len = 1;
var b;
do {
b = buf.readUInt8(len++);
val = (val << 7) + (b & 0x7F);
} while (len < 5 || b > 0x7F);
if (len == 5) val = val | b; // Preserve the major bit of the last byte
return { len: len, value: val }
}
|
javascript
|
function amf3decUI29(buf) {
var val = 0;
var len = 1;
var b;
do {
b = buf.readUInt8(len++);
val = (val << 7) + (b & 0x7F);
} while (len < 5 || b > 0x7F);
if (len == 5) val = val | b; // Preserve the major bit of the last byte
return { len: len, value: val }
}
|
[
"function",
"amf3decUI29",
"(",
"buf",
")",
"{",
"var",
"val",
"=",
"0",
";",
"var",
"len",
"=",
"1",
";",
"var",
"b",
";",
"do",
"{",
"b",
"=",
"buf",
".",
"readUInt8",
"(",
"len",
"++",
")",
";",
"val",
"=",
"(",
"val",
"<<",
"7",
")",
"+",
"(",
"b",
"&",
"0x7F",
")",
";",
"}",
"while",
"(",
"len",
"<",
"5",
"||",
"b",
">",
"0x7F",
")",
";",
"if",
"(",
"len",
"==",
"5",
")",
"val",
"=",
"val",
"|",
"b",
";",
"// Preserve the major bit of the last byte",
"return",
"{",
"len",
":",
"len",
",",
"value",
":",
"val",
"}",
"}"
] |
Generic decode of AMF3 UInt29 values
@param buf
@returns {{len: number, value: number}}
|
[
"Generic",
"decode",
"of",
"AMF3",
"UInt29",
"values"
] |
f9ef2d0df385f371c2f83a52200933f59eaebcce
|
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L178-L191
|
36,234 |
delian/node-amfutils
|
amfUtils.js
|
amf3encUI29
|
function amf3encUI29(num) {
var len = 0;
if (num < 0x80) len = 1;
if (num < 0x4000) len = 2;
if (num < 0x200000) len = 3;
if (num >= 0x200000) len = 4;
var buf = new Buffer(len);
switch (len) {
case 1:
buf.writeUInt8(num, 0);
break;
case 2:
buf.writeUInt8(num & 0x7F, 0);
buf.writeUInt8((num >> 7) | 0x80, 1);
break;
case 3:
buf.writeUInt8(num & 0x7F, 0);
buf.writeUInt8((num >> 7) & 0x7F, 1);
buf.writeUInt8((num >> 14) | 0x80, 2);
break;
case 4:
buf.writeUInt8(num & 0xFF, 0);
buf.writeUInt8((num >> 8) & 0x7F, 1);
buf.writeUInt8((num >> 15) | 0x7F, 2);
buf.writeUInt8((num >> 22) | 0x7F, 3);
break;
}
return buf;
}
|
javascript
|
function amf3encUI29(num) {
var len = 0;
if (num < 0x80) len = 1;
if (num < 0x4000) len = 2;
if (num < 0x200000) len = 3;
if (num >= 0x200000) len = 4;
var buf = new Buffer(len);
switch (len) {
case 1:
buf.writeUInt8(num, 0);
break;
case 2:
buf.writeUInt8(num & 0x7F, 0);
buf.writeUInt8((num >> 7) | 0x80, 1);
break;
case 3:
buf.writeUInt8(num & 0x7F, 0);
buf.writeUInt8((num >> 7) & 0x7F, 1);
buf.writeUInt8((num >> 14) | 0x80, 2);
break;
case 4:
buf.writeUInt8(num & 0xFF, 0);
buf.writeUInt8((num >> 8) & 0x7F, 1);
buf.writeUInt8((num >> 15) | 0x7F, 2);
buf.writeUInt8((num >> 22) | 0x7F, 3);
break;
}
return buf;
}
|
[
"function",
"amf3encUI29",
"(",
"num",
")",
"{",
"var",
"len",
"=",
"0",
";",
"if",
"(",
"num",
"<",
"0x80",
")",
"len",
"=",
"1",
";",
"if",
"(",
"num",
"<",
"0x4000",
")",
"len",
"=",
"2",
";",
"if",
"(",
"num",
"<",
"0x200000",
")",
"len",
"=",
"3",
";",
"if",
"(",
"num",
">=",
"0x200000",
")",
"len",
"=",
"4",
";",
"var",
"buf",
"=",
"new",
"Buffer",
"(",
"len",
")",
";",
"switch",
"(",
"len",
")",
"{",
"case",
"1",
":",
"buf",
".",
"writeUInt8",
"(",
"num",
",",
"0",
")",
";",
"break",
";",
"case",
"2",
":",
"buf",
".",
"writeUInt8",
"(",
"num",
"&",
"0x7F",
",",
"0",
")",
";",
"buf",
".",
"writeUInt8",
"(",
"(",
"num",
">>",
"7",
")",
"|",
"0x80",
",",
"1",
")",
";",
"break",
";",
"case",
"3",
":",
"buf",
".",
"writeUInt8",
"(",
"num",
"&",
"0x7F",
",",
"0",
")",
";",
"buf",
".",
"writeUInt8",
"(",
"(",
"num",
">>",
"7",
")",
"&",
"0x7F",
",",
"1",
")",
";",
"buf",
".",
"writeUInt8",
"(",
"(",
"num",
">>",
"14",
")",
"|",
"0x80",
",",
"2",
")",
";",
"break",
";",
"case",
"4",
":",
"buf",
".",
"writeUInt8",
"(",
"num",
"&",
"0xFF",
",",
"0",
")",
";",
"buf",
".",
"writeUInt8",
"(",
"(",
"num",
">>",
"8",
")",
"&",
"0x7F",
",",
"1",
")",
";",
"buf",
".",
"writeUInt8",
"(",
"(",
"num",
">>",
"15",
")",
"|",
"0x7F",
",",
"2",
")",
";",
"buf",
".",
"writeUInt8",
"(",
"(",
"num",
">>",
"22",
")",
"|",
"0x7F",
",",
"3",
")",
";",
"break",
";",
"}",
"return",
"buf",
";",
"}"
] |
Generic encode of AMF3 UInt29 value
@param num
@returns {Buffer}
|
[
"Generic",
"encode",
"of",
"AMF3",
"UInt29",
"value"
] |
f9ef2d0df385f371c2f83a52200933f59eaebcce
|
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L198-L226
|
36,235 |
delian/node-amfutils
|
amfUtils.js
|
amf3decInteger
|
function amf3decInteger(buf) { // Invert the integer
var resp = amf3decUI29(buf);
if (resp.value > 0x0FFFFFFF) resp.value = (resp.value & 0x0FFFFFFF) - 0x10000000;
return resp;
}
|
javascript
|
function amf3decInteger(buf) { // Invert the integer
var resp = amf3decUI29(buf);
if (resp.value > 0x0FFFFFFF) resp.value = (resp.value & 0x0FFFFFFF) - 0x10000000;
return resp;
}
|
[
"function",
"amf3decInteger",
"(",
"buf",
")",
"{",
"// Invert the integer",
"var",
"resp",
"=",
"amf3decUI29",
"(",
"buf",
")",
";",
"if",
"(",
"resp",
".",
"value",
">",
"0x0FFFFFFF",
")",
"resp",
".",
"value",
"=",
"(",
"resp",
".",
"value",
"&",
"0x0FFFFFFF",
")",
"-",
"0x10000000",
";",
"return",
"resp",
";",
"}"
] |
AMF3 Decode an integer
@param buf
@returns {{len: number, value: number}}
|
[
"AMF3",
"Decode",
"an",
"integer"
] |
f9ef2d0df385f371c2f83a52200933f59eaebcce
|
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L233-L237
|
36,236 |
delian/node-amfutils
|
amfUtils.js
|
amf3encInteger
|
function amf3encInteger(num) {
var buf = new Buffer(1);
buf.writeUInt8(0x4, 0);
return Buffer.concat([buf, amf3encUI29(num & 0x3FFFFFFF)]); // This AND will auto convert the sign bit!
}
|
javascript
|
function amf3encInteger(num) {
var buf = new Buffer(1);
buf.writeUInt8(0x4, 0);
return Buffer.concat([buf, amf3encUI29(num & 0x3FFFFFFF)]); // This AND will auto convert the sign bit!
}
|
[
"function",
"amf3encInteger",
"(",
"num",
")",
"{",
"var",
"buf",
"=",
"new",
"Buffer",
"(",
"1",
")",
";",
"buf",
".",
"writeUInt8",
"(",
"0x4",
",",
"0",
")",
";",
"return",
"Buffer",
".",
"concat",
"(",
"[",
"buf",
",",
"amf3encUI29",
"(",
"num",
"&",
"0x3FFFFFFF",
")",
"]",
")",
";",
"// This AND will auto convert the sign bit!",
"}"
] |
AMF3 Encode an integer
@param num
@returns {Buffer}
|
[
"AMF3",
"Encode",
"an",
"integer"
] |
f9ef2d0df385f371c2f83a52200933f59eaebcce
|
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L244-L248
|
36,237 |
delian/node-amfutils
|
amfUtils.js
|
amf3decXmlDoc
|
function amf3decXmlDoc(buf) {
var sLen = amf3decUI29(buf);
var s = sLen & 1;
sLen = sLen >> 1; // The real length without the lowest bit
if (s) return { len: sLen.value + 5, value: buf.slice(5, sLen.value + 5).toString('utf8') };
throw new Error("Error, we have a need to decode a String that is a Reference"); // TODO: Implement references!
}
|
javascript
|
function amf3decXmlDoc(buf) {
var sLen = amf3decUI29(buf);
var s = sLen & 1;
sLen = sLen >> 1; // The real length without the lowest bit
if (s) return { len: sLen.value + 5, value: buf.slice(5, sLen.value + 5).toString('utf8') };
throw new Error("Error, we have a need to decode a String that is a Reference"); // TODO: Implement references!
}
|
[
"function",
"amf3decXmlDoc",
"(",
"buf",
")",
"{",
"var",
"sLen",
"=",
"amf3decUI29",
"(",
"buf",
")",
";",
"var",
"s",
"=",
"sLen",
"&",
"1",
";",
"sLen",
"=",
"sLen",
">>",
"1",
";",
"// The real length without the lowest bit",
"if",
"(",
"s",
")",
"return",
"{",
"len",
":",
"sLen",
".",
"value",
"+",
"5",
",",
"value",
":",
"buf",
".",
"slice",
"(",
"5",
",",
"sLen",
".",
"value",
"+",
"5",
")",
".",
"toString",
"(",
"'utf8'",
")",
"}",
";",
"throw",
"new",
"Error",
"(",
"\"Error, we have a need to decode a String that is a Reference\"",
")",
";",
"// TODO: Implement references!",
"}"
] |
AMF3 Decode XMLDoc
@param buf
@returns {{len: *, value: (*|String)}}
|
[
"AMF3",
"Decode",
"XMLDoc"
] |
f9ef2d0df385f371c2f83a52200933f59eaebcce
|
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L280-L286
|
36,238 |
delian/node-amfutils
|
amfUtils.js
|
amf3encXmlDoc
|
function amf3encXmlDoc(str) {
var sLen = amf3encUI29(str.length << 1);
var buf = new Buffer(1);
buf.writeUInt8(0x7, 0);
return Buffer.concat([buf, sLen, new Buffer(str, 'utf8')]);
}
|
javascript
|
function amf3encXmlDoc(str) {
var sLen = amf3encUI29(str.length << 1);
var buf = new Buffer(1);
buf.writeUInt8(0x7, 0);
return Buffer.concat([buf, sLen, new Buffer(str, 'utf8')]);
}
|
[
"function",
"amf3encXmlDoc",
"(",
"str",
")",
"{",
"var",
"sLen",
"=",
"amf3encUI29",
"(",
"str",
".",
"length",
"<<",
"1",
")",
";",
"var",
"buf",
"=",
"new",
"Buffer",
"(",
"1",
")",
";",
"buf",
".",
"writeUInt8",
"(",
"0x7",
",",
"0",
")",
";",
"return",
"Buffer",
".",
"concat",
"(",
"[",
"buf",
",",
"sLen",
",",
"new",
"Buffer",
"(",
"str",
",",
"'utf8'",
")",
"]",
")",
";",
"}"
] |
AMF3 Encode XMLDoc
@param str
@returns {Buffer}
|
[
"AMF3",
"Encode",
"XMLDoc"
] |
f9ef2d0df385f371c2f83a52200933f59eaebcce
|
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L293-L298
|
36,239 |
delian/node-amfutils
|
amfUtils.js
|
amf3decByteArray
|
function amf3decByteArray(buf) {
var sLen = amf3decUI29(buf);
var s = sLen & 1; // TODO: Check if we follow the same rule!
sLen = sLen >> 1; // The real length without the lowest bit
if (s) return { len: sLen.value + 5, value: buf.slice(5, sLen.value + 5) };
throw new Error("Error, we have a need to decode a String that is a Reference"); // TODO: Implement references!
}
|
javascript
|
function amf3decByteArray(buf) {
var sLen = amf3decUI29(buf);
var s = sLen & 1; // TODO: Check if we follow the same rule!
sLen = sLen >> 1; // The real length without the lowest bit
if (s) return { len: sLen.value + 5, value: buf.slice(5, sLen.value + 5) };
throw new Error("Error, we have a need to decode a String that is a Reference"); // TODO: Implement references!
}
|
[
"function",
"amf3decByteArray",
"(",
"buf",
")",
"{",
"var",
"sLen",
"=",
"amf3decUI29",
"(",
"buf",
")",
";",
"var",
"s",
"=",
"sLen",
"&",
"1",
";",
"// TODO: Check if we follow the same rule!",
"sLen",
"=",
"sLen",
">>",
"1",
";",
"// The real length without the lowest bit",
"if",
"(",
"s",
")",
"return",
"{",
"len",
":",
"sLen",
".",
"value",
"+",
"5",
",",
"value",
":",
"buf",
".",
"slice",
"(",
"5",
",",
"sLen",
".",
"value",
"+",
"5",
")",
"}",
";",
"throw",
"new",
"Error",
"(",
"\"Error, we have a need to decode a String that is a Reference\"",
")",
";",
"// TODO: Implement references!",
"}"
] |
AMF3 Decide Byte Array
@param buf
@returns {{len: *, value: (Array|string|*|Buffer|Blob)}}
|
[
"AMF3",
"Decide",
"Byte",
"Array"
] |
f9ef2d0df385f371c2f83a52200933f59eaebcce
|
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L330-L336
|
36,240 |
delian/node-amfutils
|
amfUtils.js
|
amf3encDouble
|
function amf3encDouble(num) {
var buf = new Buffer(9);
buf.writeUInt8(0x05, 0);
buf.writeDoubleBE(num, 1);
return buf;
}
|
javascript
|
function amf3encDouble(num) {
var buf = new Buffer(9);
buf.writeUInt8(0x05, 0);
buf.writeDoubleBE(num, 1);
return buf;
}
|
[
"function",
"amf3encDouble",
"(",
"num",
")",
"{",
"var",
"buf",
"=",
"new",
"Buffer",
"(",
"9",
")",
";",
"buf",
".",
"writeUInt8",
"(",
"0x05",
",",
"0",
")",
";",
"buf",
".",
"writeDoubleBE",
"(",
"num",
",",
"1",
")",
";",
"return",
"buf",
";",
"}"
] |
AMF3 Encode Double
@param num
@returns {Buffer}
|
[
"AMF3",
"Encode",
"Double"
] |
f9ef2d0df385f371c2f83a52200933f59eaebcce
|
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L364-L369
|
36,241 |
delian/node-amfutils
|
amfUtils.js
|
amf3decDate
|
function amf3decDate(buf) { // The UI29 should be 1
var uTz = amf3decUI29(buf);
var ts = buf.readDoubleBE(uTz.len);
return { len: uTz.len + 8, value: ts }
}
|
javascript
|
function amf3decDate(buf) { // The UI29 should be 1
var uTz = amf3decUI29(buf);
var ts = buf.readDoubleBE(uTz.len);
return { len: uTz.len + 8, value: ts }
}
|
[
"function",
"amf3decDate",
"(",
"buf",
")",
"{",
"// The UI29 should be 1",
"var",
"uTz",
"=",
"amf3decUI29",
"(",
"buf",
")",
";",
"var",
"ts",
"=",
"buf",
".",
"readDoubleBE",
"(",
"uTz",
".",
"len",
")",
";",
"return",
"{",
"len",
":",
"uTz",
".",
"len",
"+",
"8",
",",
"value",
":",
"ts",
"}",
"}"
] |
AMF3 Decode Date
@param buf
@returns {{len: *, value: (*|Number)}}
|
[
"AMF3",
"Decode",
"Date"
] |
f9ef2d0df385f371c2f83a52200933f59eaebcce
|
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L376-L380
|
36,242 |
delian/node-amfutils
|
amfUtils.js
|
amf3encDate
|
function amf3encDate(ts) {
var buf = new Buffer(1);
buf.writeUInt8(0x8, 0);
var tsBuf = new Buffer(8);
tsBuf.writeDoubleBE(ts, 0);
return Buffer.concat([buf, amf3encUI29(1), tsBuf]); // We always do 1
}
|
javascript
|
function amf3encDate(ts) {
var buf = new Buffer(1);
buf.writeUInt8(0x8, 0);
var tsBuf = new Buffer(8);
tsBuf.writeDoubleBE(ts, 0);
return Buffer.concat([buf, amf3encUI29(1), tsBuf]); // We always do 1
}
|
[
"function",
"amf3encDate",
"(",
"ts",
")",
"{",
"var",
"buf",
"=",
"new",
"Buffer",
"(",
"1",
")",
";",
"buf",
".",
"writeUInt8",
"(",
"0x8",
",",
"0",
")",
";",
"var",
"tsBuf",
"=",
"new",
"Buffer",
"(",
"8",
")",
";",
"tsBuf",
".",
"writeDoubleBE",
"(",
"ts",
",",
"0",
")",
";",
"return",
"Buffer",
".",
"concat",
"(",
"[",
"buf",
",",
"amf3encUI29",
"(",
"1",
")",
",",
"tsBuf",
"]",
")",
";",
"// We always do 1",
"}"
] |
AMF3 Encode Date
@param ts
@returns {Buffer}
|
[
"AMF3",
"Encode",
"Date"
] |
f9ef2d0df385f371c2f83a52200933f59eaebcce
|
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L387-L393
|
36,243 |
delian/node-amfutils
|
amfUtils.js
|
amf3decArray
|
function amf3decArray(buf) {
var count = amf3decUI29(buf.slice(1));
var obj = amf3decObject(buf.slice(count.len));
if (count.value % 2 == 1) throw new Error("This is a reference to another array, which currently we don't support!");
return { len: count.len + obj.len, value: obj.value }
}
|
javascript
|
function amf3decArray(buf) {
var count = amf3decUI29(buf.slice(1));
var obj = amf3decObject(buf.slice(count.len));
if (count.value % 2 == 1) throw new Error("This is a reference to another array, which currently we don't support!");
return { len: count.len + obj.len, value: obj.value }
}
|
[
"function",
"amf3decArray",
"(",
"buf",
")",
"{",
"var",
"count",
"=",
"amf3decUI29",
"(",
"buf",
".",
"slice",
"(",
"1",
")",
")",
";",
"var",
"obj",
"=",
"amf3decObject",
"(",
"buf",
".",
"slice",
"(",
"count",
".",
"len",
")",
")",
";",
"if",
"(",
"count",
".",
"value",
"%",
"2",
"==",
"1",
")",
"throw",
"new",
"Error",
"(",
"\"This is a reference to another array, which currently we don't support!\"",
")",
";",
"return",
"{",
"len",
":",
"count",
".",
"len",
"+",
"obj",
".",
"len",
",",
"value",
":",
"obj",
".",
"value",
"}",
"}"
] |
AMF3 Decode Array
@param buf
@returns {{len: *, value: *}}
|
[
"AMF3",
"Decode",
"Array"
] |
f9ef2d0df385f371c2f83a52200933f59eaebcce
|
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L400-L405
|
36,244 |
delian/node-amfutils
|
amfUtils.js
|
amf0encNumber
|
function amf0encNumber(num) {
var buf = new Buffer(9);
buf.writeUInt8(0x00, 0);
buf.writeDoubleBE(num, 1);
return buf;
}
|
javascript
|
function amf0encNumber(num) {
var buf = new Buffer(9);
buf.writeUInt8(0x00, 0);
buf.writeDoubleBE(num, 1);
return buf;
}
|
[
"function",
"amf0encNumber",
"(",
"num",
")",
"{",
"var",
"buf",
"=",
"new",
"Buffer",
"(",
"9",
")",
";",
"buf",
".",
"writeUInt8",
"(",
"0x00",
",",
"0",
")",
";",
"buf",
".",
"writeDoubleBE",
"(",
"num",
",",
"1",
")",
";",
"return",
"buf",
";",
"}"
] |
AMF0 Encode Number
@param num
@returns {Buffer}
|
[
"AMF0",
"Encode",
"Number"
] |
f9ef2d0df385f371c2f83a52200933f59eaebcce
|
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L446-L451
|
36,245 |
delian/node-amfutils
|
amfUtils.js
|
amf0encBool
|
function amf0encBool(num) {
var buf = new Buffer(2);
buf.writeUInt8(0x01, 0);
buf.writeUInt8((num ? 1 : 0), 1);
return buf;
}
|
javascript
|
function amf0encBool(num) {
var buf = new Buffer(2);
buf.writeUInt8(0x01, 0);
buf.writeUInt8((num ? 1 : 0), 1);
return buf;
}
|
[
"function",
"amf0encBool",
"(",
"num",
")",
"{",
"var",
"buf",
"=",
"new",
"Buffer",
"(",
"2",
")",
";",
"buf",
".",
"writeUInt8",
"(",
"0x01",
",",
"0",
")",
";",
"buf",
".",
"writeUInt8",
"(",
"(",
"num",
"?",
"1",
":",
"0",
")",
",",
"1",
")",
";",
"return",
"buf",
";",
"}"
] |
AMF0 Encode Boolean
@param num
@returns {Buffer}
|
[
"AMF0",
"Encode",
"Boolean"
] |
f9ef2d0df385f371c2f83a52200933f59eaebcce
|
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L467-L472
|
36,246 |
delian/node-amfutils
|
amfUtils.js
|
amf0encDate
|
function amf0encDate(ts) {
var buf = new Buffer(11);
buf.writeUInt8(0x0B, 0);
buf.writeInt16BE(0, 1);
buf.writeDoubleBE(ts, 3);
return buf;
}
|
javascript
|
function amf0encDate(ts) {
var buf = new Buffer(11);
buf.writeUInt8(0x0B, 0);
buf.writeInt16BE(0, 1);
buf.writeDoubleBE(ts, 3);
return buf;
}
|
[
"function",
"amf0encDate",
"(",
"ts",
")",
"{",
"var",
"buf",
"=",
"new",
"Buffer",
"(",
"11",
")",
";",
"buf",
".",
"writeUInt8",
"(",
"0x0B",
",",
"0",
")",
";",
"buf",
".",
"writeInt16BE",
"(",
"0",
",",
"1",
")",
";",
"buf",
".",
"writeDoubleBE",
"(",
"ts",
",",
"3",
")",
";",
"return",
"buf",
";",
"}"
] |
AMF0 Encode Date
@param ts
@returns {Buffer}
|
[
"AMF0",
"Encode",
"Date"
] |
f9ef2d0df385f371c2f83a52200933f59eaebcce
|
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L526-L532
|
36,247 |
delian/node-amfutils
|
amfUtils.js
|
amf0decObject
|
function amf0decObject(buf) { // TODO: Implement references!
var obj = {};
var iBuf = buf.slice(1);
var len = 1;
// console.log('ODec',iBuf.readUInt8(0));
while (iBuf.readUInt8(0) != 0x09) {
// console.log('Field', iBuf.readUInt8(0), iBuf);
var prop = amf0decUString(iBuf);
// console.log('Got field for property', prop);
len += prop.len;
if (iBuf.slice(prop.len).readUInt8(0) == 0x09) {
len++;
// console.log('Found the end property');
break;
} // END Object as value, we shall leave
if (prop.value == '') break;
var val = amf0DecodeOne(iBuf.slice(prop.len));
// console.log('Got field for value', val);
obj[prop.value] = val.value;
len += val.len;
iBuf = iBuf.slice(prop.len + val.len);
}
return { len: len, value: obj }
}
|
javascript
|
function amf0decObject(buf) { // TODO: Implement references!
var obj = {};
var iBuf = buf.slice(1);
var len = 1;
// console.log('ODec',iBuf.readUInt8(0));
while (iBuf.readUInt8(0) != 0x09) {
// console.log('Field', iBuf.readUInt8(0), iBuf);
var prop = amf0decUString(iBuf);
// console.log('Got field for property', prop);
len += prop.len;
if (iBuf.slice(prop.len).readUInt8(0) == 0x09) {
len++;
// console.log('Found the end property');
break;
} // END Object as value, we shall leave
if (prop.value == '') break;
var val = amf0DecodeOne(iBuf.slice(prop.len));
// console.log('Got field for value', val);
obj[prop.value] = val.value;
len += val.len;
iBuf = iBuf.slice(prop.len + val.len);
}
return { len: len, value: obj }
}
|
[
"function",
"amf0decObject",
"(",
"buf",
")",
"{",
"// TODO: Implement references!",
"var",
"obj",
"=",
"{",
"}",
";",
"var",
"iBuf",
"=",
"buf",
".",
"slice",
"(",
"1",
")",
";",
"var",
"len",
"=",
"1",
";",
"// console.log('ODec',iBuf.readUInt8(0));",
"while",
"(",
"iBuf",
".",
"readUInt8",
"(",
"0",
")",
"!=",
"0x09",
")",
"{",
"// console.log('Field', iBuf.readUInt8(0), iBuf);",
"var",
"prop",
"=",
"amf0decUString",
"(",
"iBuf",
")",
";",
"// console.log('Got field for property', prop);",
"len",
"+=",
"prop",
".",
"len",
";",
"if",
"(",
"iBuf",
".",
"slice",
"(",
"prop",
".",
"len",
")",
".",
"readUInt8",
"(",
"0",
")",
"==",
"0x09",
")",
"{",
"len",
"++",
";",
"// console.log('Found the end property');",
"break",
";",
"}",
"// END Object as value, we shall leave",
"if",
"(",
"prop",
".",
"value",
"==",
"''",
")",
"break",
";",
"var",
"val",
"=",
"amf0DecodeOne",
"(",
"iBuf",
".",
"slice",
"(",
"prop",
".",
"len",
")",
")",
";",
"// console.log('Got field for value', val);",
"obj",
"[",
"prop",
".",
"value",
"]",
"=",
"val",
".",
"value",
";",
"len",
"+=",
"val",
".",
"len",
";",
"iBuf",
"=",
"iBuf",
".",
"slice",
"(",
"prop",
".",
"len",
"+",
"val",
".",
"len",
")",
";",
"}",
"return",
"{",
"len",
":",
"len",
",",
"value",
":",
"obj",
"}",
"}"
] |
AMF0 Decode Object
@param buf
@returns {{len: number, value: {}}}
|
[
"AMF0",
"Decode",
"Object"
] |
f9ef2d0df385f371c2f83a52200933f59eaebcce
|
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L539-L562
|
36,248 |
delian/node-amfutils
|
amfUtils.js
|
amf0encObject
|
function amf0encObject(o) {
if (typeof o !== 'object') return;
var data = new Buffer(1);
data.writeUInt8(0x03,0); // Type object
var k;
for (k in o) {
data = Buffer.concat([data,amf0encUString(k),amf0EncodeOne(o[k])]);
}
var termCode = new Buffer(1);
termCode.writeUInt8(0x09,0);
return Buffer.concat([data,amf0encUString(''),termCode]);
}
|
javascript
|
function amf0encObject(o) {
if (typeof o !== 'object') return;
var data = new Buffer(1);
data.writeUInt8(0x03,0); // Type object
var k;
for (k in o) {
data = Buffer.concat([data,amf0encUString(k),amf0EncodeOne(o[k])]);
}
var termCode = new Buffer(1);
termCode.writeUInt8(0x09,0);
return Buffer.concat([data,amf0encUString(''),termCode]);
}
|
[
"function",
"amf0encObject",
"(",
"o",
")",
"{",
"if",
"(",
"typeof",
"o",
"!==",
"'object'",
")",
"return",
";",
"var",
"data",
"=",
"new",
"Buffer",
"(",
"1",
")",
";",
"data",
".",
"writeUInt8",
"(",
"0x03",
",",
"0",
")",
";",
"// Type object",
"var",
"k",
";",
"for",
"(",
"k",
"in",
"o",
")",
"{",
"data",
"=",
"Buffer",
".",
"concat",
"(",
"[",
"data",
",",
"amf0encUString",
"(",
"k",
")",
",",
"amf0EncodeOne",
"(",
"o",
"[",
"k",
"]",
")",
"]",
")",
";",
"}",
"var",
"termCode",
"=",
"new",
"Buffer",
"(",
"1",
")",
";",
"termCode",
".",
"writeUInt8",
"(",
"0x09",
",",
"0",
")",
";",
"return",
"Buffer",
".",
"concat",
"(",
"[",
"data",
",",
"amf0encUString",
"(",
"''",
")",
",",
"termCode",
"]",
")",
";",
"}"
] |
AMF0 Encode Object
|
[
"AMF0",
"Encode",
"Object"
] |
f9ef2d0df385f371c2f83a52200933f59eaebcce
|
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L567-L579
|
36,249 |
delian/node-amfutils
|
amfUtils.js
|
amf0encRef
|
function amf0encRef(index) {
var buf = new Buffer(3);
buf.writeUInt8(0x07, 0);
buf.writeUInt16BE(index, 1);
return buf;
}
|
javascript
|
function amf0encRef(index) {
var buf = new Buffer(3);
buf.writeUInt8(0x07, 0);
buf.writeUInt16BE(index, 1);
return buf;
}
|
[
"function",
"amf0encRef",
"(",
"index",
")",
"{",
"var",
"buf",
"=",
"new",
"Buffer",
"(",
"3",
")",
";",
"buf",
".",
"writeUInt8",
"(",
"0x07",
",",
"0",
")",
";",
"buf",
".",
"writeUInt16BE",
"(",
"index",
",",
"1",
")",
";",
"return",
"buf",
";",
"}"
] |
AMF0 Encode Reference
@param index
@returns {Buffer}
|
[
"AMF0",
"Encode",
"Reference"
] |
f9ef2d0df385f371c2f83a52200933f59eaebcce
|
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L596-L601
|
36,250 |
delian/node-amfutils
|
amfUtils.js
|
amf0decString
|
function amf0decString(buf) {
var sLen = buf.readUInt16BE(1);
return { len: 3 + sLen, value: buf.toString('utf8', 3, 3 + sLen) }
}
|
javascript
|
function amf0decString(buf) {
var sLen = buf.readUInt16BE(1);
return { len: 3 + sLen, value: buf.toString('utf8', 3, 3 + sLen) }
}
|
[
"function",
"amf0decString",
"(",
"buf",
")",
"{",
"var",
"sLen",
"=",
"buf",
".",
"readUInt16BE",
"(",
"1",
")",
";",
"return",
"{",
"len",
":",
"3",
"+",
"sLen",
",",
"value",
":",
"buf",
".",
"toString",
"(",
"'utf8'",
",",
"3",
",",
"3",
"+",
"sLen",
")",
"}",
"}"
] |
AMF0 Decode String
@param buf
@returns {{len: *, value: (*|string|String)}}
|
[
"AMF0",
"Decode",
"String"
] |
f9ef2d0df385f371c2f83a52200933f59eaebcce
|
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L608-L611
|
36,251 |
delian/node-amfutils
|
amfUtils.js
|
amf0encUString
|
function amf0encUString(s) {
var data = new Buffer(s,'utf8');
var sLen = new Buffer(2);
sLen.writeUInt16BE(data.length,0);
return Buffer.concat([sLen,data]);
}
|
javascript
|
function amf0encUString(s) {
var data = new Buffer(s,'utf8');
var sLen = new Buffer(2);
sLen.writeUInt16BE(data.length,0);
return Buffer.concat([sLen,data]);
}
|
[
"function",
"amf0encUString",
"(",
"s",
")",
"{",
"var",
"data",
"=",
"new",
"Buffer",
"(",
"s",
",",
"'utf8'",
")",
";",
"var",
"sLen",
"=",
"new",
"Buffer",
"(",
"2",
")",
";",
"sLen",
".",
"writeUInt16BE",
"(",
"data",
".",
"length",
",",
"0",
")",
";",
"return",
"Buffer",
".",
"concat",
"(",
"[",
"sLen",
",",
"data",
"]",
")",
";",
"}"
] |
Do AMD0 Encode of Untyped String
@param s
@returns {Buffer}
|
[
"Do",
"AMD0",
"Encode",
"of",
"Untyped",
"String"
] |
f9ef2d0df385f371c2f83a52200933f59eaebcce
|
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L628-L633
|
36,252 |
delian/node-amfutils
|
amfUtils.js
|
amf0encString
|
function amf0encString(str) {
var buf = new Buffer(3);
buf.writeUInt8(0x02, 0);
buf.writeUInt16BE(str.length, 1);
return Buffer.concat([buf, new Buffer(str, 'utf8')]);
}
|
javascript
|
function amf0encString(str) {
var buf = new Buffer(3);
buf.writeUInt8(0x02, 0);
buf.writeUInt16BE(str.length, 1);
return Buffer.concat([buf, new Buffer(str, 'utf8')]);
}
|
[
"function",
"amf0encString",
"(",
"str",
")",
"{",
"var",
"buf",
"=",
"new",
"Buffer",
"(",
"3",
")",
";",
"buf",
".",
"writeUInt8",
"(",
"0x02",
",",
"0",
")",
";",
"buf",
".",
"writeUInt16BE",
"(",
"str",
".",
"length",
",",
"1",
")",
";",
"return",
"Buffer",
".",
"concat",
"(",
"[",
"buf",
",",
"new",
"Buffer",
"(",
"str",
",",
"'utf8'",
")",
"]",
")",
";",
"}"
] |
AMF0 Encode String
@param str
@returns {Buffer}
|
[
"AMF0",
"Encode",
"String"
] |
f9ef2d0df385f371c2f83a52200933f59eaebcce
|
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L640-L645
|
36,253 |
delian/node-amfutils
|
amfUtils.js
|
amf0decLongString
|
function amf0decLongString(buf) {
var sLen = buf.readUInt32BE(1);
return { len: 5 + sLen, value: buf.toString('utf8', 5, 5 + sLen) }
}
|
javascript
|
function amf0decLongString(buf) {
var sLen = buf.readUInt32BE(1);
return { len: 5 + sLen, value: buf.toString('utf8', 5, 5 + sLen) }
}
|
[
"function",
"amf0decLongString",
"(",
"buf",
")",
"{",
"var",
"sLen",
"=",
"buf",
".",
"readUInt32BE",
"(",
"1",
")",
";",
"return",
"{",
"len",
":",
"5",
"+",
"sLen",
",",
"value",
":",
"buf",
".",
"toString",
"(",
"'utf8'",
",",
"5",
",",
"5",
"+",
"sLen",
")",
"}",
"}"
] |
AMF0 Decode Long String
@param buf
@returns {{len: *, value: (*|string|String)}}
|
[
"AMF0",
"Decode",
"Long",
"String"
] |
f9ef2d0df385f371c2f83a52200933f59eaebcce
|
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L652-L655
|
36,254 |
delian/node-amfutils
|
amfUtils.js
|
amf0encLongString
|
function amf0encLongString(str) {
var buf = new Buffer(5);
buf.writeUInt8(0x0C, 0);
buf.writeUInt32BE(str.length, 1);
return Buffer.concat([buf, new Buffer(str, 'utf8')]);
}
|
javascript
|
function amf0encLongString(str) {
var buf = new Buffer(5);
buf.writeUInt8(0x0C, 0);
buf.writeUInt32BE(str.length, 1);
return Buffer.concat([buf, new Buffer(str, 'utf8')]);
}
|
[
"function",
"amf0encLongString",
"(",
"str",
")",
"{",
"var",
"buf",
"=",
"new",
"Buffer",
"(",
"5",
")",
";",
"buf",
".",
"writeUInt8",
"(",
"0x0C",
",",
"0",
")",
";",
"buf",
".",
"writeUInt32BE",
"(",
"str",
".",
"length",
",",
"1",
")",
";",
"return",
"Buffer",
".",
"concat",
"(",
"[",
"buf",
",",
"new",
"Buffer",
"(",
"str",
",",
"'utf8'",
")",
"]",
")",
";",
"}"
] |
AMF0 Encode Long String
@param str
@returns {Buffer}
|
[
"AMF0",
"Encode",
"Long",
"String"
] |
f9ef2d0df385f371c2f83a52200933f59eaebcce
|
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L662-L667
|
36,255 |
delian/node-amfutils
|
amfUtils.js
|
amf0decArray
|
function amf0decArray(buf) {
// var count = buf.readUInt32BE(1);
var obj = amf0decObject(buf.slice(4));
return { len: 5 + obj.len, value: obj.value }
}
|
javascript
|
function amf0decArray(buf) {
// var count = buf.readUInt32BE(1);
var obj = amf0decObject(buf.slice(4));
return { len: 5 + obj.len, value: obj.value }
}
|
[
"function",
"amf0decArray",
"(",
"buf",
")",
"{",
"// var count = buf.readUInt32BE(1);",
"var",
"obj",
"=",
"amf0decObject",
"(",
"buf",
".",
"slice",
"(",
"4",
")",
")",
";",
"return",
"{",
"len",
":",
"5",
"+",
"obj",
".",
"len",
",",
"value",
":",
"obj",
".",
"value",
"}",
"}"
] |
AMF0 Decode Array
@param buf
@returns {{len: *, value: ({}|*)}}
|
[
"AMF0",
"Decode",
"Array"
] |
f9ef2d0df385f371c2f83a52200933f59eaebcce
|
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L674-L678
|
36,256 |
delian/node-amfutils
|
amfUtils.js
|
amf0encArray
|
function amf0encArray(a) {
var l = 0;
if (a instanceof Array) l = a.length; else l = Object.keys(a).length;
console.log('Array encode', l, a);
var buf = new Buffer(5);
buf.writeUInt8(8,0);
buf.writeUInt32BE(l,1);
var data = amf0encObject(a);
return Buffer.concat([buf,data.slice(1)]);
}
|
javascript
|
function amf0encArray(a) {
var l = 0;
if (a instanceof Array) l = a.length; else l = Object.keys(a).length;
console.log('Array encode', l, a);
var buf = new Buffer(5);
buf.writeUInt8(8,0);
buf.writeUInt32BE(l,1);
var data = amf0encObject(a);
return Buffer.concat([buf,data.slice(1)]);
}
|
[
"function",
"amf0encArray",
"(",
"a",
")",
"{",
"var",
"l",
"=",
"0",
";",
"if",
"(",
"a",
"instanceof",
"Array",
")",
"l",
"=",
"a",
".",
"length",
";",
"else",
"l",
"=",
"Object",
".",
"keys",
"(",
"a",
")",
".",
"length",
";",
"console",
".",
"log",
"(",
"'Array encode'",
",",
"l",
",",
"a",
")",
";",
"var",
"buf",
"=",
"new",
"Buffer",
"(",
"5",
")",
";",
"buf",
".",
"writeUInt8",
"(",
"8",
",",
"0",
")",
";",
"buf",
".",
"writeUInt32BE",
"(",
"l",
",",
"1",
")",
";",
"var",
"data",
"=",
"amf0encObject",
"(",
"a",
")",
";",
"return",
"Buffer",
".",
"concat",
"(",
"[",
"buf",
",",
"data",
".",
"slice",
"(",
"1",
")",
"]",
")",
";",
"}"
] |
AMF0 Encode Array
|
[
"AMF0",
"Encode",
"Array"
] |
f9ef2d0df385f371c2f83a52200933f59eaebcce
|
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L683-L692
|
36,257 |
delian/node-amfutils
|
amfUtils.js
|
amf0cnvArray2Object
|
function amf0cnvArray2Object(aData) {
var buf = new Buffer(1);
buf.writeUInt8(0x3,0); // Object id
return Buffer.concat([buf,aData.slice(5)]);
}
|
javascript
|
function amf0cnvArray2Object(aData) {
var buf = new Buffer(1);
buf.writeUInt8(0x3,0); // Object id
return Buffer.concat([buf,aData.slice(5)]);
}
|
[
"function",
"amf0cnvArray2Object",
"(",
"aData",
")",
"{",
"var",
"buf",
"=",
"new",
"Buffer",
"(",
"1",
")",
";",
"buf",
".",
"writeUInt8",
"(",
"0x3",
",",
"0",
")",
";",
"// Object id",
"return",
"Buffer",
".",
"concat",
"(",
"[",
"buf",
",",
"aData",
".",
"slice",
"(",
"5",
")",
"]",
")",
";",
"}"
] |
AMF0 Encode Binary Array into binary Object
@param aData
@returns {Buffer}
|
[
"AMF0",
"Encode",
"Binary",
"Array",
"into",
"binary",
"Object"
] |
f9ef2d0df385f371c2f83a52200933f59eaebcce
|
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L699-L703
|
36,258 |
delian/node-amfutils
|
amfUtils.js
|
amf0cnvObject2Array
|
function amf0cnvObject2Array(oData) {
var buf = new Buffer(5);
var o = amf0decObject(oData);
var l = Object.keys(o).length;
buf.writeUInt32BE(l,1);
return Buffer.concat([buf,oData.slice(1)]);
}
|
javascript
|
function amf0cnvObject2Array(oData) {
var buf = new Buffer(5);
var o = amf0decObject(oData);
var l = Object.keys(o).length;
buf.writeUInt32BE(l,1);
return Buffer.concat([buf,oData.slice(1)]);
}
|
[
"function",
"amf0cnvObject2Array",
"(",
"oData",
")",
"{",
"var",
"buf",
"=",
"new",
"Buffer",
"(",
"5",
")",
";",
"var",
"o",
"=",
"amf0decObject",
"(",
"oData",
")",
";",
"var",
"l",
"=",
"Object",
".",
"keys",
"(",
"o",
")",
".",
"length",
";",
"buf",
".",
"writeUInt32BE",
"(",
"l",
",",
"1",
")",
";",
"return",
"Buffer",
".",
"concat",
"(",
"[",
"buf",
",",
"oData",
".",
"slice",
"(",
"1",
")",
"]",
")",
";",
"}"
] |
AMF0 Encode Binary Object into binary Array
@param oData
@returns {Buffer}
|
[
"AMF0",
"Encode",
"Binary",
"Object",
"into",
"binary",
"Array"
] |
f9ef2d0df385f371c2f83a52200933f59eaebcce
|
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L710-L716
|
36,259 |
delian/node-amfutils
|
amfUtils.js
|
amf0decXmlDoc
|
function amf0decXmlDoc(buf) {
var sLen = buf.readUInt16BE(1);
return { len: 3 + sLen, value: buf.toString('utf8', 3, 3 + sLen) }
}
|
javascript
|
function amf0decXmlDoc(buf) {
var sLen = buf.readUInt16BE(1);
return { len: 3 + sLen, value: buf.toString('utf8', 3, 3 + sLen) }
}
|
[
"function",
"amf0decXmlDoc",
"(",
"buf",
")",
"{",
"var",
"sLen",
"=",
"buf",
".",
"readUInt16BE",
"(",
"1",
")",
";",
"return",
"{",
"len",
":",
"3",
"+",
"sLen",
",",
"value",
":",
"buf",
".",
"toString",
"(",
"'utf8'",
",",
"3",
",",
"3",
"+",
"sLen",
")",
"}",
"}"
] |
AMF0 Decode XMLDoc
@param buf
@returns {{len: *, value: (*|string|String)}}
|
[
"AMF0",
"Decode",
"XMLDoc"
] |
f9ef2d0df385f371c2f83a52200933f59eaebcce
|
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L723-L726
|
36,260 |
delian/node-amfutils
|
amfUtils.js
|
amf0encXmlDoc
|
function amf0encXmlDoc(str) { // Essentially it is the same as string
var buf = new Buffer(3);
buf.writeUInt8(0x0F, 0);
buf.writeUInt16BE(str.length, 1);
return Buffer.concat([buf, new Buffer(str, 'utf8')]);
}
|
javascript
|
function amf0encXmlDoc(str) { // Essentially it is the same as string
var buf = new Buffer(3);
buf.writeUInt8(0x0F, 0);
buf.writeUInt16BE(str.length, 1);
return Buffer.concat([buf, new Buffer(str, 'utf8')]);
}
|
[
"function",
"amf0encXmlDoc",
"(",
"str",
")",
"{",
"// Essentially it is the same as string",
"var",
"buf",
"=",
"new",
"Buffer",
"(",
"3",
")",
";",
"buf",
".",
"writeUInt8",
"(",
"0x0F",
",",
"0",
")",
";",
"buf",
".",
"writeUInt16BE",
"(",
"str",
".",
"length",
",",
"1",
")",
";",
"return",
"Buffer",
".",
"concat",
"(",
"[",
"buf",
",",
"new",
"Buffer",
"(",
"str",
",",
"'utf8'",
")",
"]",
")",
";",
"}"
] |
AMF0 Encode XMLDoc
@param str
@returns {Buffer}
|
[
"AMF0",
"Encode",
"XMLDoc"
] |
f9ef2d0df385f371c2f83a52200933f59eaebcce
|
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L733-L738
|
36,261 |
delian/node-amfutils
|
amfUtils.js
|
amf0decSArray
|
function amf0decSArray(buf) {
var a = [];
var len = 5;
var ret;
for (var count = buf.readUInt32BE(1); count; count--) {
ret = amf0DecodeOne(buf.slice(len));
a.push(ret.value);
len += ret.len;
}
return { len: len, value: amf0markSArray(a) }
}
|
javascript
|
function amf0decSArray(buf) {
var a = [];
var len = 5;
var ret;
for (var count = buf.readUInt32BE(1); count; count--) {
ret = amf0DecodeOne(buf.slice(len));
a.push(ret.value);
len += ret.len;
}
return { len: len, value: amf0markSArray(a) }
}
|
[
"function",
"amf0decSArray",
"(",
"buf",
")",
"{",
"var",
"a",
"=",
"[",
"]",
";",
"var",
"len",
"=",
"5",
";",
"var",
"ret",
";",
"for",
"(",
"var",
"count",
"=",
"buf",
".",
"readUInt32BE",
"(",
"1",
")",
";",
"count",
";",
"count",
"--",
")",
"{",
"ret",
"=",
"amf0DecodeOne",
"(",
"buf",
".",
"slice",
"(",
"len",
")",
")",
";",
"a",
".",
"push",
"(",
"ret",
".",
"value",
")",
";",
"len",
"+=",
"ret",
".",
"len",
";",
"}",
"return",
"{",
"len",
":",
"len",
",",
"value",
":",
"amf0markSArray",
"(",
"a",
")",
"}",
"}"
] |
AMF0 Decode Strict Array
@param buf
@returns {{len: number, value: Array}}
|
[
"AMF0",
"Decode",
"Strict",
"Array"
] |
f9ef2d0df385f371c2f83a52200933f59eaebcce
|
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L745-L755
|
36,262 |
delian/node-amfutils
|
amfUtils.js
|
amf0encSArray
|
function amf0encSArray(a) {
console.log('Do strict array!');
var buf = new Buffer(5);
buf.writeUInt8(0x0A,0);
buf.writeUInt32BE(a.length,1);
var i;
for (i=0;i< a.length;i++) {
buf = Buffer.concat([buf,amf0EncodeOne(a[i])]);
}
return buf;
}
|
javascript
|
function amf0encSArray(a) {
console.log('Do strict array!');
var buf = new Buffer(5);
buf.writeUInt8(0x0A,0);
buf.writeUInt32BE(a.length,1);
var i;
for (i=0;i< a.length;i++) {
buf = Buffer.concat([buf,amf0EncodeOne(a[i])]);
}
return buf;
}
|
[
"function",
"amf0encSArray",
"(",
"a",
")",
"{",
"console",
".",
"log",
"(",
"'Do strict array!'",
")",
";",
"var",
"buf",
"=",
"new",
"Buffer",
"(",
"5",
")",
";",
"buf",
".",
"writeUInt8",
"(",
"0x0A",
",",
"0",
")",
";",
"buf",
".",
"writeUInt32BE",
"(",
"a",
".",
"length",
",",
"1",
")",
";",
"var",
"i",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"a",
".",
"length",
";",
"i",
"++",
")",
"{",
"buf",
"=",
"Buffer",
".",
"concat",
"(",
"[",
"buf",
",",
"amf0EncodeOne",
"(",
"a",
"[",
"i",
"]",
")",
"]",
")",
";",
"}",
"return",
"buf",
";",
"}"
] |
AMF0 Encode Strict Array
@param a Array
|
[
"AMF0",
"Encode",
"Strict",
"Array"
] |
f9ef2d0df385f371c2f83a52200933f59eaebcce
|
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L761-L771
|
36,263 |
delian/node-amfutils
|
amfUtils.js
|
amf0decTypedObj
|
function amf0decTypedObj(buf) {
var className = amf0decString(buf);
var obj = amf0decObject(buf.slice(className.len - 1));
obj.value.__className__ = className.value;
return { len: className.len + obj.len - 1, value: obj.value }
}
|
javascript
|
function amf0decTypedObj(buf) {
var className = amf0decString(buf);
var obj = amf0decObject(buf.slice(className.len - 1));
obj.value.__className__ = className.value;
return { len: className.len + obj.len - 1, value: obj.value }
}
|
[
"function",
"amf0decTypedObj",
"(",
"buf",
")",
"{",
"var",
"className",
"=",
"amf0decString",
"(",
"buf",
")",
";",
"var",
"obj",
"=",
"amf0decObject",
"(",
"buf",
".",
"slice",
"(",
"className",
".",
"len",
"-",
"1",
")",
")",
";",
"obj",
".",
"value",
".",
"__className__",
"=",
"className",
".",
"value",
";",
"return",
"{",
"len",
":",
"className",
".",
"len",
"+",
"obj",
".",
"len",
"-",
"1",
",",
"value",
":",
"obj",
".",
"value",
"}",
"}"
] |
AMF0 Decode Typed Object
@param buf
@returns {{len: number, value: ({}|*)}}
|
[
"AMF0",
"Decode",
"Typed",
"Object"
] |
f9ef2d0df385f371c2f83a52200933f59eaebcce
|
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L783-L788
|
36,264 |
delian/node-amfutils
|
amfUtils.js
|
amfXDecodeOne
|
function amfXDecodeOne(rules, buffer) {
if (!rules[buffer.readUInt8(0)]) {
console.log('Unknown field', buffer.readUInt8(0));
throw new Error("Error: Unknown field");
}
return rules[buffer.readUInt8(0)](buffer);
}
|
javascript
|
function amfXDecodeOne(rules, buffer) {
if (!rules[buffer.readUInt8(0)]) {
console.log('Unknown field', buffer.readUInt8(0));
throw new Error("Error: Unknown field");
}
return rules[buffer.readUInt8(0)](buffer);
}
|
[
"function",
"amfXDecodeOne",
"(",
"rules",
",",
"buffer",
")",
"{",
"if",
"(",
"!",
"rules",
"[",
"buffer",
".",
"readUInt8",
"(",
"0",
")",
"]",
")",
"{",
"console",
".",
"log",
"(",
"'Unknown field'",
",",
"buffer",
".",
"readUInt8",
"(",
"0",
")",
")",
";",
"throw",
"new",
"Error",
"(",
"\"Error: Unknown field\"",
")",
";",
"}",
"return",
"rules",
"[",
"buffer",
".",
"readUInt8",
"(",
"0",
")",
"]",
"(",
"buffer",
")",
";",
"}"
] |
Decode one value from the Buffer according to the applied rules
@param rules
@param buffer
@returns {*}
|
[
"Decode",
"one",
"value",
"from",
"the",
"Buffer",
"according",
"to",
"the",
"applied",
"rules"
] |
f9ef2d0df385f371c2f83a52200933f59eaebcce
|
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L803-L809
|
36,265 |
delian/node-amfutils
|
amfUtils.js
|
amfXDecode
|
function amfXDecode(rules, buffer) {
// We shall receive clean buffer and will respond with an array of values
var resp = [];
var res;
for (var i = 0; i < buffer.length;) {
res = amfXDecodeOne(rules, buffer.slice(i));
i += res.len;
resp.push(res.value); // Add the response
}
return resp;
}
|
javascript
|
function amfXDecode(rules, buffer) {
// We shall receive clean buffer and will respond with an array of values
var resp = [];
var res;
for (var i = 0; i < buffer.length;) {
res = amfXDecodeOne(rules, buffer.slice(i));
i += res.len;
resp.push(res.value); // Add the response
}
return resp;
}
|
[
"function",
"amfXDecode",
"(",
"rules",
",",
"buffer",
")",
"{",
"// We shall receive clean buffer and will respond with an array of values",
"var",
"resp",
"=",
"[",
"]",
";",
"var",
"res",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"buffer",
".",
"length",
";",
")",
"{",
"res",
"=",
"amfXDecodeOne",
"(",
"rules",
",",
"buffer",
".",
"slice",
"(",
"i",
")",
")",
";",
"i",
"+=",
"res",
".",
"len",
";",
"resp",
".",
"push",
"(",
"res",
".",
"value",
")",
";",
"// Add the response",
"}",
"return",
"resp",
";",
"}"
] |
Decode a whole buffer of AMF values according to rules and return in array
@param rules
@param buffer
@returns {Array}
|
[
"Decode",
"a",
"whole",
"buffer",
"of",
"AMF",
"values",
"according",
"to",
"rules",
"and",
"return",
"in",
"array"
] |
f9ef2d0df385f371c2f83a52200933f59eaebcce
|
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L835-L845
|
36,266 |
delian/node-amfutils
|
amfUtils.js
|
amfXEncodeOne
|
function amfXEncodeOne(rules, o) {
// console.log('amfXEncodeOne type',o,amfType(o),rules[amfType(o)]);
var f = rules[amfType(o)];
if (f) return f(o);
throw new Error('Unsupported type for encoding!');
}
|
javascript
|
function amfXEncodeOne(rules, o) {
// console.log('amfXEncodeOne type',o,amfType(o),rules[amfType(o)]);
var f = rules[amfType(o)];
if (f) return f(o);
throw new Error('Unsupported type for encoding!');
}
|
[
"function",
"amfXEncodeOne",
"(",
"rules",
",",
"o",
")",
"{",
"// console.log('amfXEncodeOne type',o,amfType(o),rules[amfType(o)]);",
"var",
"f",
"=",
"rules",
"[",
"amfType",
"(",
"o",
")",
"]",
";",
"if",
"(",
"f",
")",
"return",
"f",
"(",
"o",
")",
";",
"throw",
"new",
"Error",
"(",
"'Unsupported type for encoding!'",
")",
";",
"}"
] |
Encode one AMF value according to rules
@param rules
@param o
@returns {*}
|
[
"Encode",
"one",
"AMF",
"value",
"according",
"to",
"rules"
] |
f9ef2d0df385f371c2f83a52200933f59eaebcce
|
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L871-L876
|
36,267 |
delian/node-amfutils
|
amfUtils.js
|
decodeAMF0Cmd
|
function decodeAMF0Cmd(dbuf) {
var buffer = dbuf;
var resp = {};
var cmd = amf0DecodeOne(buffer);
resp.cmd = cmd.value;
buffer = buffer.slice(cmd.len);
if (rtmpCmdDecode[cmd.value]) {
rtmpCmdDecode[cmd.value].forEach(function (n) {
if (buffer.length > 0) {
var r = amf0DecodeOne(buffer);
buffer = buffer.slice(r.len);
resp[n] = r.value;
}
});
} else {
console.log('Unknown command', resp);
}
return resp
}
|
javascript
|
function decodeAMF0Cmd(dbuf) {
var buffer = dbuf;
var resp = {};
var cmd = amf0DecodeOne(buffer);
resp.cmd = cmd.value;
buffer = buffer.slice(cmd.len);
if (rtmpCmdDecode[cmd.value]) {
rtmpCmdDecode[cmd.value].forEach(function (n) {
if (buffer.length > 0) {
var r = amf0DecodeOne(buffer);
buffer = buffer.slice(r.len);
resp[n] = r.value;
}
});
} else {
console.log('Unknown command', resp);
}
return resp
}
|
[
"function",
"decodeAMF0Cmd",
"(",
"dbuf",
")",
"{",
"var",
"buffer",
"=",
"dbuf",
";",
"var",
"resp",
"=",
"{",
"}",
";",
"var",
"cmd",
"=",
"amf0DecodeOne",
"(",
"buffer",
")",
";",
"resp",
".",
"cmd",
"=",
"cmd",
".",
"value",
";",
"buffer",
"=",
"buffer",
".",
"slice",
"(",
"cmd",
".",
"len",
")",
";",
"if",
"(",
"rtmpCmdDecode",
"[",
"cmd",
".",
"value",
"]",
")",
"{",
"rtmpCmdDecode",
"[",
"cmd",
".",
"value",
"]",
".",
"forEach",
"(",
"function",
"(",
"n",
")",
"{",
"if",
"(",
"buffer",
".",
"length",
">",
"0",
")",
"{",
"var",
"r",
"=",
"amf0DecodeOne",
"(",
"buffer",
")",
";",
"buffer",
"=",
"buffer",
".",
"slice",
"(",
"r",
".",
"len",
")",
";",
"resp",
"[",
"n",
"]",
"=",
"r",
".",
"value",
";",
"}",
"}",
")",
";",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"'Unknown command'",
",",
"resp",
")",
";",
"}",
"return",
"resp",
"}"
] |
Decode a command!
@param dbuf
@returns {{cmd: (*|string|String|*), value: *}}
|
[
"Decode",
"a",
"command!"
] |
f9ef2d0df385f371c2f83a52200933f59eaebcce
|
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L951-L971
|
36,268 |
delian/node-amfutils
|
amfUtils.js
|
encodeAMF3Cmd
|
function encodeAMF3Cmd(opt) {
var data = amf0EncodeOne(opt.cmd);
if (rtmpCmdDecode[opt.cmd]) {
rtmpCmdDecode[opt.cmd].forEach(function (n) {
if (opt.hasOwnProperty(n))
data = Buffer.concat([data, amf3EncodeOne(opt[n])]);
});
} else {
console.log('Unknown command', opt);
}
return data
}
|
javascript
|
function encodeAMF3Cmd(opt) {
var data = amf0EncodeOne(opt.cmd);
if (rtmpCmdDecode[opt.cmd]) {
rtmpCmdDecode[opt.cmd].forEach(function (n) {
if (opt.hasOwnProperty(n))
data = Buffer.concat([data, amf3EncodeOne(opt[n])]);
});
} else {
console.log('Unknown command', opt);
}
return data
}
|
[
"function",
"encodeAMF3Cmd",
"(",
"opt",
")",
"{",
"var",
"data",
"=",
"amf0EncodeOne",
"(",
"opt",
".",
"cmd",
")",
";",
"if",
"(",
"rtmpCmdDecode",
"[",
"opt",
".",
"cmd",
"]",
")",
"{",
"rtmpCmdDecode",
"[",
"opt",
".",
"cmd",
"]",
".",
"forEach",
"(",
"function",
"(",
"n",
")",
"{",
"if",
"(",
"opt",
".",
"hasOwnProperty",
"(",
"n",
")",
")",
"data",
"=",
"Buffer",
".",
"concat",
"(",
"[",
"data",
",",
"amf3EncodeOne",
"(",
"opt",
"[",
"n",
"]",
")",
"]",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"'Unknown command'",
",",
"opt",
")",
";",
"}",
"return",
"data",
"}"
] |
Encode AMF3 Command
@param opt
@returns {*}
|
[
"Encode",
"AMF3",
"Command"
] |
f9ef2d0df385f371c2f83a52200933f59eaebcce
|
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L1025-L1037
|
36,269 |
ascartabelli/lamb
|
src/privates/_isArrayIndex.js
|
_isArrayIndex
|
function _isArrayIndex (target, key) {
var n = +key;
return Array.isArray(target) && n % 1 === 0 && !(n < 0 && _isEnumerable(target, key));
}
|
javascript
|
function _isArrayIndex (target, key) {
var n = +key;
return Array.isArray(target) && n % 1 === 0 && !(n < 0 && _isEnumerable(target, key));
}
|
[
"function",
"_isArrayIndex",
"(",
"target",
",",
"key",
")",
"{",
"var",
"n",
"=",
"+",
"key",
";",
"return",
"Array",
".",
"isArray",
"(",
"target",
")",
"&&",
"n",
"%",
"1",
"===",
"0",
"&&",
"!",
"(",
"n",
"<",
"0",
"&&",
"_isEnumerable",
"(",
"target",
",",
"key",
")",
")",
";",
"}"
] |
Accepts a target object and a key name and verifies that the target is an array and that
the key is an existing index.
@private
@param {Object} target
@param {String|Number} key
@returns {Boolean}
|
[
"Accepts",
"a",
"target",
"object",
"and",
"a",
"key",
"name",
"and",
"verifies",
"that",
"the",
"target",
"is",
"an",
"array",
"and",
"that",
"the",
"key",
"is",
"an",
"existing",
"index",
"."
] |
d36e45945c4789e4f1a2d8805936514b53f32362
|
https://github.com/ascartabelli/lamb/blob/d36e45945c4789e4f1a2d8805936514b53f32362/src/privates/_isArrayIndex.js#L11-L15
|
36,270 |
marionebl/eslint-plugin-flow-check
|
source/flow.js
|
flow
|
function flow(options) {
const result = spawnSync(bin, [
'check-contents',
'--json',
`--root=${options.root}`,
options.fileName
], {
input: options.source,
encoding: 'utf-8'
});
if (result.status !== 0) {
return [{
message: result.stderr,
loc: {
start: {
line: 1
},
end: {
line: 1
}
}
}];
}
const {errors} = JSON.parse(result.stdout);
return errors.map(error => {
const [leading, ...rest] = error.message;
const payload = rest.map(m => format(m, {
root: options.root
}));
return {
message: [leading.descr, ...payload].join(': '),
path: leading.path,
start: leading.loc.start.line,
end: leading.loc.end.line,
loc: leading.loc
};
});
}
|
javascript
|
function flow(options) {
const result = spawnSync(bin, [
'check-contents',
'--json',
`--root=${options.root}`,
options.fileName
], {
input: options.source,
encoding: 'utf-8'
});
if (result.status !== 0) {
return [{
message: result.stderr,
loc: {
start: {
line: 1
},
end: {
line: 1
}
}
}];
}
const {errors} = JSON.parse(result.stdout);
return errors.map(error => {
const [leading, ...rest] = error.message;
const payload = rest.map(m => format(m, {
root: options.root
}));
return {
message: [leading.descr, ...payload].join(': '),
path: leading.path,
start: leading.loc.start.line,
end: leading.loc.end.line,
loc: leading.loc
};
});
}
|
[
"function",
"flow",
"(",
"options",
")",
"{",
"const",
"result",
"=",
"spawnSync",
"(",
"bin",
",",
"[",
"'check-contents'",
",",
"'--json'",
",",
"`",
"${",
"options",
".",
"root",
"}",
"`",
",",
"options",
".",
"fileName",
"]",
",",
"{",
"input",
":",
"options",
".",
"source",
",",
"encoding",
":",
"'utf-8'",
"}",
")",
";",
"if",
"(",
"result",
".",
"status",
"!==",
"0",
")",
"{",
"return",
"[",
"{",
"message",
":",
"result",
".",
"stderr",
",",
"loc",
":",
"{",
"start",
":",
"{",
"line",
":",
"1",
"}",
",",
"end",
":",
"{",
"line",
":",
"1",
"}",
"}",
"}",
"]",
";",
"}",
"const",
"{",
"errors",
"}",
"=",
"JSON",
".",
"parse",
"(",
"result",
".",
"stdout",
")",
";",
"return",
"errors",
".",
"map",
"(",
"error",
"=>",
"{",
"const",
"[",
"leading",
",",
"...",
"rest",
"]",
"=",
"error",
".",
"message",
";",
"const",
"payload",
"=",
"rest",
".",
"map",
"(",
"m",
"=>",
"format",
"(",
"m",
",",
"{",
"root",
":",
"options",
".",
"root",
"}",
")",
")",
";",
"return",
"{",
"message",
":",
"[",
"leading",
".",
"descr",
",",
"...",
"payload",
"]",
".",
"join",
"(",
"': '",
")",
",",
"path",
":",
"leading",
".",
"path",
",",
"start",
":",
"leading",
".",
"loc",
".",
"start",
".",
"line",
",",
"end",
":",
"leading",
".",
"loc",
".",
"end",
".",
"line",
",",
"loc",
":",
"leading",
".",
"loc",
"}",
";",
"}",
")",
";",
"}"
] |
start a flow server
|
[
"start",
"a",
"flow",
"server"
] |
bd2332d114afe8a3fff03adbc4253cbd43bd926f
|
https://github.com/marionebl/eslint-plugin-flow-check/blob/bd2332d114afe8a3fff03adbc4253cbd43bd926f/source/flow.js#L9-L50
|
36,271 |
ascartabelli/lamb
|
src/privates/_getPathInfo.js
|
_getPathInfo
|
function _getPathInfo (obj, parts, walkNonEnumerables) {
if (isNil(obj)) {
throw _makeTypeErrorFor(obj, "object");
}
var target = obj;
var i = -1;
var len = parts.length;
var key;
while (++i < len) {
key = _getPathKey(target, parts[i], walkNonEnumerables);
if (isUndefined(key)) {
break;
}
target = target[key];
}
return i === len ? { isValid: true, target: target } : { isValid: false, target: void 0 };
}
|
javascript
|
function _getPathInfo (obj, parts, walkNonEnumerables) {
if (isNil(obj)) {
throw _makeTypeErrorFor(obj, "object");
}
var target = obj;
var i = -1;
var len = parts.length;
var key;
while (++i < len) {
key = _getPathKey(target, parts[i], walkNonEnumerables);
if (isUndefined(key)) {
break;
}
target = target[key];
}
return i === len ? { isValid: true, target: target } : { isValid: false, target: void 0 };
}
|
[
"function",
"_getPathInfo",
"(",
"obj",
",",
"parts",
",",
"walkNonEnumerables",
")",
"{",
"if",
"(",
"isNil",
"(",
"obj",
")",
")",
"{",
"throw",
"_makeTypeErrorFor",
"(",
"obj",
",",
"\"object\"",
")",
";",
"}",
"var",
"target",
"=",
"obj",
";",
"var",
"i",
"=",
"-",
"1",
";",
"var",
"len",
"=",
"parts",
".",
"length",
";",
"var",
"key",
";",
"while",
"(",
"++",
"i",
"<",
"len",
")",
"{",
"key",
"=",
"_getPathKey",
"(",
"target",
",",
"parts",
"[",
"i",
"]",
",",
"walkNonEnumerables",
")",
";",
"if",
"(",
"isUndefined",
"(",
"key",
")",
")",
"{",
"break",
";",
"}",
"target",
"=",
"target",
"[",
"key",
"]",
";",
"}",
"return",
"i",
"===",
"len",
"?",
"{",
"isValid",
":",
"true",
",",
"target",
":",
"target",
"}",
":",
"{",
"isValid",
":",
"false",
",",
"target",
":",
"void",
"0",
"}",
";",
"}"
] |
Checks if a path is valid in the given object and retrieves the path target.
@private
@param {Object} obj
@param {String[]} parts
@param {Boolean} walkNonEnumerables
@returns {Object}
|
[
"Checks",
"if",
"a",
"path",
"is",
"valid",
"in",
"the",
"given",
"object",
"and",
"retrieves",
"the",
"path",
"target",
"."
] |
d36e45945c4789e4f1a2d8805936514b53f32362
|
https://github.com/ascartabelli/lamb/blob/d36e45945c4789e4f1a2d8805936514b53f32362/src/privates/_getPathInfo.js#L14-L35
|
36,272 |
ascartabelli/lamb
|
src/privates/_flatten.js
|
_flatten
|
function _flatten (array, isDeep, output, idx) {
for (var i = 0, len = array.length, value, j, vLen; i < len; i++) {
value = array[i];
if (!Array.isArray(value)) {
output[idx++] = value;
} else if (isDeep) {
_flatten(value, true, output, idx);
idx = output.length;
} else {
vLen = value.length;
output.length += vLen;
for (j = 0; j < vLen; j++) {
output[idx++] = value[j];
}
}
}
return output;
}
|
javascript
|
function _flatten (array, isDeep, output, idx) {
for (var i = 0, len = array.length, value, j, vLen; i < len; i++) {
value = array[i];
if (!Array.isArray(value)) {
output[idx++] = value;
} else if (isDeep) {
_flatten(value, true, output, idx);
idx = output.length;
} else {
vLen = value.length;
output.length += vLen;
for (j = 0; j < vLen; j++) {
output[idx++] = value[j];
}
}
}
return output;
}
|
[
"function",
"_flatten",
"(",
"array",
",",
"isDeep",
",",
"output",
",",
"idx",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"array",
".",
"length",
",",
"value",
",",
"j",
",",
"vLen",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"value",
"=",
"array",
"[",
"i",
"]",
";",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"value",
")",
")",
"{",
"output",
"[",
"idx",
"++",
"]",
"=",
"value",
";",
"}",
"else",
"if",
"(",
"isDeep",
")",
"{",
"_flatten",
"(",
"value",
",",
"true",
",",
"output",
",",
"idx",
")",
";",
"idx",
"=",
"output",
".",
"length",
";",
"}",
"else",
"{",
"vLen",
"=",
"value",
".",
"length",
";",
"output",
".",
"length",
"+=",
"vLen",
";",
"for",
"(",
"j",
"=",
"0",
";",
"j",
"<",
"vLen",
";",
"j",
"++",
")",
"{",
"output",
"[",
"idx",
"++",
"]",
"=",
"value",
"[",
"j",
"]",
";",
"}",
"}",
"}",
"return",
"output",
";",
"}"
] |
Flattens an array.
@private
@param {Array} array - The source array
@param {Boolean} isDeep - Whether to perform a deep flattening or not
@param {Array} output - An array to collect the result
@param {Number} idx - The next index to be filled in the output
@returns {Array} The output array filled with the results
|
[
"Flattens",
"an",
"array",
"."
] |
d36e45945c4789e4f1a2d8805936514b53f32362
|
https://github.com/ascartabelli/lamb/blob/d36e45945c4789e4f1a2d8805936514b53f32362/src/privates/_flatten.js#L10-L30
|
36,273 |
fortunejs/fortune-mongodb
|
lib/helpers.js
|
mapValues
|
function mapValues (object, map) {
return Object.keys(object).reduce((clone, key) =>
Object.assign(clone, { [key]: map(object[key], key) }), {})
}
|
javascript
|
function mapValues (object, map) {
return Object.keys(object).reduce((clone, key) =>
Object.assign(clone, { [key]: map(object[key], key) }), {})
}
|
[
"function",
"mapValues",
"(",
"object",
",",
"map",
")",
"{",
"return",
"Object",
".",
"keys",
"(",
"object",
")",
".",
"reduce",
"(",
"(",
"clone",
",",
"key",
")",
"=>",
"Object",
".",
"assign",
"(",
"clone",
",",
"{",
"[",
"key",
"]",
":",
"map",
"(",
"object",
"[",
"key",
"]",
",",
"key",
")",
"}",
")",
",",
"{",
"}",
")",
"}"
] |
Create a new object with different key values.
@param {Object} object
@param {Function} map should return the first argument, which is the value
@return {Object}
|
[
"Create",
"a",
"new",
"object",
"with",
"different",
"key",
"values",
"."
] |
e1e5e4d830e37fdee92388ab194ba35a71dae27f
|
https://github.com/fortunejs/fortune-mongodb/blob/e1e5e4d830e37fdee92388ab194ba35a71dae27f/lib/helpers.js#L106-L109
|
36,274 |
fortunejs/fortune-mongodb
|
lib/helpers.js
|
toBuffer
|
function toBuffer (object) {
if (Buffer.isBuffer(object)) return object
if (object.buffer) return object.buffer
throw new TypeError('Could not output buffer type.')
}
|
javascript
|
function toBuffer (object) {
if (Buffer.isBuffer(object)) return object
if (object.buffer) return object.buffer
throw new TypeError('Could not output buffer type.')
}
|
[
"function",
"toBuffer",
"(",
"object",
")",
"{",
"if",
"(",
"Buffer",
".",
"isBuffer",
"(",
"object",
")",
")",
"return",
"object",
"if",
"(",
"object",
".",
"buffer",
")",
"return",
"object",
".",
"buffer",
"throw",
"new",
"TypeError",
"(",
"'Could not output buffer type.'",
")",
"}"
] |
There is an inconsistency when accessing a record depending on the method, it may be either a native `Buffer` or BSON object wrapper. We only want native buffers.
|
[
"There",
"is",
"an",
"inconsistency",
"when",
"accessing",
"a",
"record",
"depending",
"on",
"the",
"method",
"it",
"may",
"be",
"either",
"a",
"native",
"Buffer",
"or",
"BSON",
"object",
"wrapper",
".",
"We",
"only",
"want",
"native",
"buffers",
"."
] |
e1e5e4d830e37fdee92388ab194ba35a71dae27f
|
https://github.com/fortunejs/fortune-mongodb/blob/e1e5e4d830e37fdee92388ab194ba35a71dae27f/lib/helpers.js#L115-L119
|
36,275 |
fortunejs/fortune-mongodb
|
lib/helpers.js
|
generateQuery
|
function generateQuery (fields, options, not) {
let $and = []
const $or = []
const result = {}
for (const key in options)
switch (key) {
case 'and':
case 'or':
const query = {}
query[`$${key}`] = mapValues(options[key], value => {
return generateQuery(fields, value)
})
return query
case 'not':
return generateQuery(fields, options[key], true)
case 'range':
$and.push(generateRangeQuery(fields, options.range))
break
case 'match':
if ('or' in options.match)
for (const key in options.match.or) {
const q = {}
q[key] = options.match.or[key]
$or.push(q)
}
else $and.push(mapValues(options.match, value =>
Array.isArray(value) ? { $in: value } : value))
break
case 'exists':
$and.push(mapValues(options.exists, (value, key) => {
if (!(key in fields)) return void 0
if (fields[key].isArray)
return value ? { $ne: [] } : []
return value ? { $ne: null } : null
}))
break
default:
}
if (not)
$and = $and.map(applyNotOperator)
if ($and.length) result.$and = $and
if ($or.length) result.$or = $or
return result
}
|
javascript
|
function generateQuery (fields, options, not) {
let $and = []
const $or = []
const result = {}
for (const key in options)
switch (key) {
case 'and':
case 'or':
const query = {}
query[`$${key}`] = mapValues(options[key], value => {
return generateQuery(fields, value)
})
return query
case 'not':
return generateQuery(fields, options[key], true)
case 'range':
$and.push(generateRangeQuery(fields, options.range))
break
case 'match':
if ('or' in options.match)
for (const key in options.match.or) {
const q = {}
q[key] = options.match.or[key]
$or.push(q)
}
else $and.push(mapValues(options.match, value =>
Array.isArray(value) ? { $in: value } : value))
break
case 'exists':
$and.push(mapValues(options.exists, (value, key) => {
if (!(key in fields)) return void 0
if (fields[key].isArray)
return value ? { $ne: [] } : []
return value ? { $ne: null } : null
}))
break
default:
}
if (not)
$and = $and.map(applyNotOperator)
if ($and.length) result.$and = $and
if ($or.length) result.$or = $or
return result
}
|
[
"function",
"generateQuery",
"(",
"fields",
",",
"options",
",",
"not",
")",
"{",
"let",
"$and",
"=",
"[",
"]",
"const",
"$or",
"=",
"[",
"]",
"const",
"result",
"=",
"{",
"}",
"for",
"(",
"const",
"key",
"in",
"options",
")",
"switch",
"(",
"key",
")",
"{",
"case",
"'and'",
":",
"case",
"'or'",
":",
"const",
"query",
"=",
"{",
"}",
"query",
"[",
"`",
"${",
"key",
"}",
"`",
"]",
"=",
"mapValues",
"(",
"options",
"[",
"key",
"]",
",",
"value",
"=>",
"{",
"return",
"generateQuery",
"(",
"fields",
",",
"value",
")",
"}",
")",
"return",
"query",
"case",
"'not'",
":",
"return",
"generateQuery",
"(",
"fields",
",",
"options",
"[",
"key",
"]",
",",
"true",
")",
"case",
"'range'",
":",
"$and",
".",
"push",
"(",
"generateRangeQuery",
"(",
"fields",
",",
"options",
".",
"range",
")",
")",
"break",
"case",
"'match'",
":",
"if",
"(",
"'or'",
"in",
"options",
".",
"match",
")",
"for",
"(",
"const",
"key",
"in",
"options",
".",
"match",
".",
"or",
")",
"{",
"const",
"q",
"=",
"{",
"}",
"q",
"[",
"key",
"]",
"=",
"options",
".",
"match",
".",
"or",
"[",
"key",
"]",
"$or",
".",
"push",
"(",
"q",
")",
"}",
"else",
"$and",
".",
"push",
"(",
"mapValues",
"(",
"options",
".",
"match",
",",
"value",
"=>",
"Array",
".",
"isArray",
"(",
"value",
")",
"?",
"{",
"$in",
":",
"value",
"}",
":",
"value",
")",
")",
"break",
"case",
"'exists'",
":",
"$and",
".",
"push",
"(",
"mapValues",
"(",
"options",
".",
"exists",
",",
"(",
"value",
",",
"key",
")",
"=>",
"{",
"if",
"(",
"!",
"(",
"key",
"in",
"fields",
")",
")",
"return",
"void",
"0",
"if",
"(",
"fields",
"[",
"key",
"]",
".",
"isArray",
")",
"return",
"value",
"?",
"{",
"$ne",
":",
"[",
"]",
"}",
":",
"[",
"]",
"return",
"value",
"?",
"{",
"$ne",
":",
"null",
"}",
":",
"null",
"}",
")",
")",
"break",
"default",
":",
"}",
"if",
"(",
"not",
")",
"$and",
"=",
"$and",
".",
"map",
"(",
"applyNotOperator",
")",
"if",
"(",
"$and",
".",
"length",
")",
"result",
".",
"$and",
"=",
"$and",
"if",
"(",
"$or",
".",
"length",
")",
"result",
".",
"$or",
"=",
"$or",
"return",
"result",
"}"
] |
Generate a mongoDB query from a fortune query object
|
[
"Generate",
"a",
"mongoDB",
"query",
"from",
"a",
"fortune",
"query",
"object"
] |
e1e5e4d830e37fdee92388ab194ba35a71dae27f
|
https://github.com/fortunejs/fortune-mongodb/blob/e1e5e4d830e37fdee92388ab194ba35a71dae27f/lib/helpers.js#L152-L201
|
36,276 |
takashiki/cos-webpack
|
index.js
|
function(fileName) {
let file = assets[fileName] || {};
fileName = basePath + "/" + fileName.replace(/\\/g, '/');
let key = path.posix.join(uploadPath, fileName);
return new Promise((resolve, reject) => {
let begin = Date.now();
cos.putObject(
{
Bucket: bucket,
Region: region,
Key: key,
Body: fs.createReadStream(file.existsAt),
ContentLength: fs.statSync(file.existsAt).size
},
function(err, body) {
uploadedFiles++;
spinner.text = tip(uploadedFiles, totalFiles);
if (err) return reject(err);
body.duration = Date.now() - begin;
resolve(body);
}
);
});
}
|
javascript
|
function(fileName) {
let file = assets[fileName] || {};
fileName = basePath + "/" + fileName.replace(/\\/g, '/');
let key = path.posix.join(uploadPath, fileName);
return new Promise((resolve, reject) => {
let begin = Date.now();
cos.putObject(
{
Bucket: bucket,
Region: region,
Key: key,
Body: fs.createReadStream(file.existsAt),
ContentLength: fs.statSync(file.existsAt).size
},
function(err, body) {
uploadedFiles++;
spinner.text = tip(uploadedFiles, totalFiles);
if (err) return reject(err);
body.duration = Date.now() - begin;
resolve(body);
}
);
});
}
|
[
"function",
"(",
"fileName",
")",
"{",
"let",
"file",
"=",
"assets",
"[",
"fileName",
"]",
"||",
"{",
"}",
";",
"fileName",
"=",
"basePath",
"+",
"\"/\"",
"+",
"fileName",
".",
"replace",
"(",
"/",
"\\\\",
"/",
"g",
",",
"'/'",
")",
";",
"let",
"key",
"=",
"path",
".",
"posix",
".",
"join",
"(",
"uploadPath",
",",
"fileName",
")",
";",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"let",
"begin",
"=",
"Date",
".",
"now",
"(",
")",
";",
"cos",
".",
"putObject",
"(",
"{",
"Bucket",
":",
"bucket",
",",
"Region",
":",
"region",
",",
"Key",
":",
"key",
",",
"Body",
":",
"fs",
".",
"createReadStream",
"(",
"file",
".",
"existsAt",
")",
",",
"ContentLength",
":",
"fs",
".",
"statSync",
"(",
"file",
".",
"existsAt",
")",
".",
"size",
"}",
",",
"function",
"(",
"err",
",",
"body",
")",
"{",
"uploadedFiles",
"++",
";",
"spinner",
".",
"text",
"=",
"tip",
"(",
"uploadedFiles",
",",
"totalFiles",
")",
";",
"if",
"(",
"err",
")",
"return",
"reject",
"(",
"err",
")",
";",
"body",
".",
"duration",
"=",
"Date",
".",
"now",
"(",
")",
"-",
"begin",
";",
"resolve",
"(",
"body",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Perform upload to cos
|
[
"Perform",
"upload",
"to",
"cos"
] |
2a8d09a14b977930c00c87a8c63e11897e929ed6
|
https://github.com/takashiki/cos-webpack/blob/2a8d09a14b977930c00c87a8c63e11897e929ed6/index.js#L104-L129
|
|
36,277 |
takashiki/cos-webpack
|
index.js
|
function(err) {
if (err) {
// eslint-disable-next-line no-console
console.log("\n");
return Promise.reject(err);
}
// Get 20 files
let _files = filesNames.splice(0, batch);
if (_files.length) {
return Promise.all(_files.map(performUpload)).then(() => execStack(), execStack);
} else {
return Promise.resolve();
}
}
|
javascript
|
function(err) {
if (err) {
// eslint-disable-next-line no-console
console.log("\n");
return Promise.reject(err);
}
// Get 20 files
let _files = filesNames.splice(0, batch);
if (_files.length) {
return Promise.all(_files.map(performUpload)).then(() => execStack(), execStack);
} else {
return Promise.resolve();
}
}
|
[
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"// eslint-disable-next-line no-console",
"console",
".",
"log",
"(",
"\"\\n\"",
")",
";",
"return",
"Promise",
".",
"reject",
"(",
"err",
")",
";",
"}",
"// Get 20 files",
"let",
"_files",
"=",
"filesNames",
".",
"splice",
"(",
"0",
",",
"batch",
")",
";",
"if",
"(",
"_files",
".",
"length",
")",
"{",
"return",
"Promise",
".",
"all",
"(",
"_files",
".",
"map",
"(",
"performUpload",
")",
")",
".",
"then",
"(",
"(",
")",
"=>",
"execStack",
"(",
")",
",",
"execStack",
")",
";",
"}",
"else",
"{",
"return",
"Promise",
".",
"resolve",
"(",
")",
";",
"}",
"}"
] |
Execute stack according to `batch` option
|
[
"Execute",
"stack",
"according",
"to",
"batch",
"option"
] |
2a8d09a14b977930c00c87a8c63e11897e929ed6
|
https://github.com/takashiki/cos-webpack/blob/2a8d09a14b977930c00c87a8c63e11897e929ed6/index.js#L132-L147
|
|
36,278 |
aMarCruz/jspreproc
|
lib/compactor.js
|
indent
|
function indent(level) {
var val = options.indent
_indent = ''
if (_lastch === null)
_lastch = _to // as-is, this is the first file
else if (_lastch !== _to) {
_lastch = _to
// istanbul ignore else
if (output)
output.emit('data', _to) // force eol after insert file
}
if (level > 0 && val && !/^0+\D?/.test(val)) {
// format is 2, 2t, 2s, etc. default is spaces
var match = /^(\d+)\s*(t?)/.exec(val),
count = level * (match[1] | 0)
_indent = Array(count + 1).join(match[2] ? '\t' : ' ')
}
}
|
javascript
|
function indent(level) {
var val = options.indent
_indent = ''
if (_lastch === null)
_lastch = _to // as-is, this is the first file
else if (_lastch !== _to) {
_lastch = _to
// istanbul ignore else
if (output)
output.emit('data', _to) // force eol after insert file
}
if (level > 0 && val && !/^0+\D?/.test(val)) {
// format is 2, 2t, 2s, etc. default is spaces
var match = /^(\d+)\s*(t?)/.exec(val),
count = level * (match[1] | 0)
_indent = Array(count + 1).join(match[2] ? '\t' : ' ')
}
}
|
[
"function",
"indent",
"(",
"level",
")",
"{",
"var",
"val",
"=",
"options",
".",
"indent",
"_indent",
"=",
"''",
"if",
"(",
"_lastch",
"===",
"null",
")",
"_lastch",
"=",
"_to",
"// as-is, this is the first file",
"else",
"if",
"(",
"_lastch",
"!==",
"_to",
")",
"{",
"_lastch",
"=",
"_to",
"// istanbul ignore else",
"if",
"(",
"output",
")",
"output",
".",
"emit",
"(",
"'data'",
",",
"_to",
")",
"// force eol after insert file",
"}",
"if",
"(",
"level",
">",
"0",
"&&",
"val",
"&&",
"!",
"/",
"^0+\\D?",
"/",
".",
"test",
"(",
"val",
")",
")",
"{",
"// format is 2, 2t, 2s, etc. default is spaces",
"var",
"match",
"=",
"/",
"^(\\d+)\\s*(t?)",
"/",
".",
"exec",
"(",
"val",
")",
",",
"count",
"=",
"level",
"*",
"(",
"match",
"[",
"1",
"]",
"|",
"0",
")",
"_indent",
"=",
"Array",
"(",
"count",
"+",
"1",
")",
".",
"join",
"(",
"match",
"[",
"2",
"]",
"?",
"'\\t'",
":",
"' '",
")",
"}",
"}"
] |
On file change, reset indentation
|
[
"On",
"file",
"change",
"reset",
"indentation"
] |
5f31820d702a329e8aa25f0f3983f13097610250
|
https://github.com/aMarCruz/jspreproc/blob/5f31820d702a329e8aa25f0f3983f13097610250/lib/compactor.js#L32-L51
|
36,279 |
aMarCruz/jspreproc
|
lib/compactor.js
|
write
|
function write(buffer) {
// first, trim trailing whitespace for fast searching
buffer = buffer.replace(/[ \t]+$/gm, '')
// compact lines if emptyLines != -1
if (_elines >= 0)
buffer = trimBuffer(buffer)
if (!buffer) return
// finished the surrounding lines, now the inners
if (!_elines) {
// remove empty lines and change eols in one unique operation
buffer = buffer.replace(/\n{2,}/g, _to)
}
else {
// keep max n empty lines (n+1 sucesive eols), -1 keep all
if (_elines > 0)
buffer = buffer.replace(_re, '$1')
// change line terminator if not unix
if (_to !== '\n') buffer = buffer.replace(/\n/g, _to)
}
// apply indentation, regex `^.` with `/m` matches non-empty lines
if (_indent)
buffer = buffer.replace(/^./mg, _indent + '$&')
_lastch = buffer.slice(-1)
// istanbul ignore else
if (output)
output.emit('data', buffer)
}
|
javascript
|
function write(buffer) {
// first, trim trailing whitespace for fast searching
buffer = buffer.replace(/[ \t]+$/gm, '')
// compact lines if emptyLines != -1
if (_elines >= 0)
buffer = trimBuffer(buffer)
if (!buffer) return
// finished the surrounding lines, now the inners
if (!_elines) {
// remove empty lines and change eols in one unique operation
buffer = buffer.replace(/\n{2,}/g, _to)
}
else {
// keep max n empty lines (n+1 sucesive eols), -1 keep all
if (_elines > 0)
buffer = buffer.replace(_re, '$1')
// change line terminator if not unix
if (_to !== '\n') buffer = buffer.replace(/\n/g, _to)
}
// apply indentation, regex `^.` with `/m` matches non-empty lines
if (_indent)
buffer = buffer.replace(/^./mg, _indent + '$&')
_lastch = buffer.slice(-1)
// istanbul ignore else
if (output)
output.emit('data', buffer)
}
|
[
"function",
"write",
"(",
"buffer",
")",
"{",
"// first, trim trailing whitespace for fast searching",
"buffer",
"=",
"buffer",
".",
"replace",
"(",
"/",
"[ \\t]+$",
"/",
"gm",
",",
"''",
")",
"// compact lines if emptyLines != -1",
"if",
"(",
"_elines",
">=",
"0",
")",
"buffer",
"=",
"trimBuffer",
"(",
"buffer",
")",
"if",
"(",
"!",
"buffer",
")",
"return",
"// finished the surrounding lines, now the inners",
"if",
"(",
"!",
"_elines",
")",
"{",
"// remove empty lines and change eols in one unique operation",
"buffer",
"=",
"buffer",
".",
"replace",
"(",
"/",
"\\n{2,}",
"/",
"g",
",",
"_to",
")",
"}",
"else",
"{",
"// keep max n empty lines (n+1 sucesive eols), -1 keep all",
"if",
"(",
"_elines",
">",
"0",
")",
"buffer",
"=",
"buffer",
".",
"replace",
"(",
"_re",
",",
"'$1'",
")",
"// change line terminator if not unix",
"if",
"(",
"_to",
"!==",
"'\\n'",
")",
"buffer",
"=",
"buffer",
".",
"replace",
"(",
"/",
"\\n",
"/",
"g",
",",
"_to",
")",
"}",
"// apply indentation, regex `^.` with `/m` matches non-empty lines",
"if",
"(",
"_indent",
")",
"buffer",
"=",
"buffer",
".",
"replace",
"(",
"/",
"^.",
"/",
"mg",
",",
"_indent",
"+",
"'$&'",
")",
"_lastch",
"=",
"buffer",
".",
"slice",
"(",
"-",
"1",
")",
"// istanbul ignore else",
"if",
"(",
"output",
")",
"output",
".",
"emit",
"(",
"'data'",
",",
"buffer",
")",
"}"
] |
On new data, trim trailing whitespace and normalize eols
|
[
"On",
"new",
"data",
"trim",
"trailing",
"whitespace",
"and",
"normalize",
"eols"
] |
5f31820d702a329e8aa25f0f3983f13097610250
|
https://github.com/aMarCruz/jspreproc/blob/5f31820d702a329e8aa25f0f3983f13097610250/lib/compactor.js#L55-L88
|
36,280 |
jgkim/mocha-gherkin
|
src/spec.js
|
GherkinSpec
|
function GherkinSpec(runner) {
Base.call(this, runner);
let indents = 0;
let n = 0;
if (!Base.useColors) {
colors.enabled = false;
}
function indent() {
return Array(indents).join(' ');
}
runner.on('start', () => {
console.log();
});
runner.on('suite', (suite) => {
indents += 1;
let text = suite.title;
switch (suite.name) {
case 'Feature':
text = colors.underline.bold(suite.title);
suite.stories.forEach((story) => {
text += `\n${indent()} ${story}`;
});
break;
case 'Scenario':
text = colors.green(suite.title);
break;
default:
text = Base.color('suite', text);
}
console.log(indent() + text);
});
runner.on('suite end', () => {
indents -= 1;
if (indents === 1) {
console.log();
}
});
runner.on('pending', (test) => {
console.log(`${indent()} ${colors.cyan(`- ${test.title}`)}`);
});
runner.on('pass', (test) => {
let fmt = indent() + colors.green(` ${Base.symbols.ok} %s`);
if (test.speed === 'fast') {
cursor.CR();
console.log(fmt, test.title);
} else {
fmt += Base.color(test.speed, ' (%dms)');
cursor.CR();
console.log(fmt, test.title, test.duration);
}
});
runner.on('fail', (test) => {
cursor.CR();
n += 1;
console.log(`${indent()} ${colors.red('%d) %s')}`, n, test.title);
});
runner.on('end', this.epilogue.bind(this));
}
|
javascript
|
function GherkinSpec(runner) {
Base.call(this, runner);
let indents = 0;
let n = 0;
if (!Base.useColors) {
colors.enabled = false;
}
function indent() {
return Array(indents).join(' ');
}
runner.on('start', () => {
console.log();
});
runner.on('suite', (suite) => {
indents += 1;
let text = suite.title;
switch (suite.name) {
case 'Feature':
text = colors.underline.bold(suite.title);
suite.stories.forEach((story) => {
text += `\n${indent()} ${story}`;
});
break;
case 'Scenario':
text = colors.green(suite.title);
break;
default:
text = Base.color('suite', text);
}
console.log(indent() + text);
});
runner.on('suite end', () => {
indents -= 1;
if (indents === 1) {
console.log();
}
});
runner.on('pending', (test) => {
console.log(`${indent()} ${colors.cyan(`- ${test.title}`)}`);
});
runner.on('pass', (test) => {
let fmt = indent() + colors.green(` ${Base.symbols.ok} %s`);
if (test.speed === 'fast') {
cursor.CR();
console.log(fmt, test.title);
} else {
fmt += Base.color(test.speed, ' (%dms)');
cursor.CR();
console.log(fmt, test.title, test.duration);
}
});
runner.on('fail', (test) => {
cursor.CR();
n += 1;
console.log(`${indent()} ${colors.red('%d) %s')}`, n, test.title);
});
runner.on('end', this.epilogue.bind(this));
}
|
[
"function",
"GherkinSpec",
"(",
"runner",
")",
"{",
"Base",
".",
"call",
"(",
"this",
",",
"runner",
")",
";",
"let",
"indents",
"=",
"0",
";",
"let",
"n",
"=",
"0",
";",
"if",
"(",
"!",
"Base",
".",
"useColors",
")",
"{",
"colors",
".",
"enabled",
"=",
"false",
";",
"}",
"function",
"indent",
"(",
")",
"{",
"return",
"Array",
"(",
"indents",
")",
".",
"join",
"(",
"' '",
")",
";",
"}",
"runner",
".",
"on",
"(",
"'start'",
",",
"(",
")",
"=>",
"{",
"console",
".",
"log",
"(",
")",
";",
"}",
")",
";",
"runner",
".",
"on",
"(",
"'suite'",
",",
"(",
"suite",
")",
"=>",
"{",
"indents",
"+=",
"1",
";",
"let",
"text",
"=",
"suite",
".",
"title",
";",
"switch",
"(",
"suite",
".",
"name",
")",
"{",
"case",
"'Feature'",
":",
"text",
"=",
"colors",
".",
"underline",
".",
"bold",
"(",
"suite",
".",
"title",
")",
";",
"suite",
".",
"stories",
".",
"forEach",
"(",
"(",
"story",
")",
"=>",
"{",
"text",
"+=",
"`",
"\\n",
"${",
"indent",
"(",
")",
"}",
"${",
"story",
"}",
"`",
";",
"}",
")",
";",
"break",
";",
"case",
"'Scenario'",
":",
"text",
"=",
"colors",
".",
"green",
"(",
"suite",
".",
"title",
")",
";",
"break",
";",
"default",
":",
"text",
"=",
"Base",
".",
"color",
"(",
"'suite'",
",",
"text",
")",
";",
"}",
"console",
".",
"log",
"(",
"indent",
"(",
")",
"+",
"text",
")",
";",
"}",
")",
";",
"runner",
".",
"on",
"(",
"'suite end'",
",",
"(",
")",
"=>",
"{",
"indents",
"-=",
"1",
";",
"if",
"(",
"indents",
"===",
"1",
")",
"{",
"console",
".",
"log",
"(",
")",
";",
"}",
"}",
")",
";",
"runner",
".",
"on",
"(",
"'pending'",
",",
"(",
"test",
")",
"=>",
"{",
"console",
".",
"log",
"(",
"`",
"${",
"indent",
"(",
")",
"}",
"${",
"colors",
".",
"cyan",
"(",
"`",
"${",
"test",
".",
"title",
"}",
"`",
")",
"}",
"`",
")",
";",
"}",
")",
";",
"runner",
".",
"on",
"(",
"'pass'",
",",
"(",
"test",
")",
"=>",
"{",
"let",
"fmt",
"=",
"indent",
"(",
")",
"+",
"colors",
".",
"green",
"(",
"`",
"${",
"Base",
".",
"symbols",
".",
"ok",
"}",
"`",
")",
";",
"if",
"(",
"test",
".",
"speed",
"===",
"'fast'",
")",
"{",
"cursor",
".",
"CR",
"(",
")",
";",
"console",
".",
"log",
"(",
"fmt",
",",
"test",
".",
"title",
")",
";",
"}",
"else",
"{",
"fmt",
"+=",
"Base",
".",
"color",
"(",
"test",
".",
"speed",
",",
"' (%dms)'",
")",
";",
"cursor",
".",
"CR",
"(",
")",
";",
"console",
".",
"log",
"(",
"fmt",
",",
"test",
".",
"title",
",",
"test",
".",
"duration",
")",
";",
"}",
"}",
")",
";",
"runner",
".",
"on",
"(",
"'fail'",
",",
"(",
"test",
")",
"=>",
"{",
"cursor",
".",
"CR",
"(",
")",
";",
"n",
"+=",
"1",
";",
"console",
".",
"log",
"(",
"`",
"${",
"indent",
"(",
")",
"}",
"${",
"colors",
".",
"red",
"(",
"'%d) %s'",
")",
"}",
"`",
",",
"n",
",",
"test",
".",
"title",
")",
";",
"}",
")",
";",
"runner",
".",
"on",
"(",
"'end'",
",",
"this",
".",
"epilogue",
".",
"bind",
"(",
"this",
")",
")",
";",
"}"
] |
Initialize a new `GherkinSpec` test reporter.
@api public
@param {Runner} runner
|
[
"Initialize",
"a",
"new",
"GherkinSpec",
"test",
"reporter",
"."
] |
9542725a3c5b557b153bc51ce6d61d1b11dfd3a5
|
https://github.com/jgkim/mocha-gherkin/blob/9542725a3c5b557b153bc51ce6d61d1b11dfd3a5/src/spec.js#L14-L82
|
36,281 |
LaxarJS/webpack-jasmine-html-runner-plugin
|
index.js
|
entry
|
function entry() {
const patterns = Array.from( arguments );
const entry = {};
patterns.forEach( globPattern => {
// backwards compatibility:
const pattern = globPattern.replace( '[name]', '**' );
return glob.sync( pattern ).forEach( path => {
const baseName = path.replace( /\.[^.]+$/, '' );
entry[ baseName ] = path;
} );
} );
return entry;
}
|
javascript
|
function entry() {
const patterns = Array.from( arguments );
const entry = {};
patterns.forEach( globPattern => {
// backwards compatibility:
const pattern = globPattern.replace( '[name]', '**' );
return glob.sync( pattern ).forEach( path => {
const baseName = path.replace( /\.[^.]+$/, '' );
entry[ baseName ] = path;
} );
} );
return entry;
}
|
[
"function",
"entry",
"(",
")",
"{",
"const",
"patterns",
"=",
"Array",
".",
"from",
"(",
"arguments",
")",
";",
"const",
"entry",
"=",
"{",
"}",
";",
"patterns",
".",
"forEach",
"(",
"globPattern",
"=>",
"{",
"// backwards compatibility:",
"const",
"pattern",
"=",
"globPattern",
".",
"replace",
"(",
"'[name]'",
",",
"'**'",
")",
";",
"return",
"glob",
".",
"sync",
"(",
"pattern",
")",
".",
"forEach",
"(",
"path",
"=>",
"{",
"const",
"baseName",
"=",
"path",
".",
"replace",
"(",
"/",
"\\.[^.]+$",
"/",
",",
"''",
")",
";",
"entry",
"[",
"baseName",
"]",
"=",
"path",
";",
"}",
")",
";",
"}",
")",
";",
"return",
"entry",
";",
"}"
] |
Generates webpack entry points suitable for use with the WebpackJasmineHtmlRunnerPlugin plugin.
Basically, each file matching one of the provided glob-patterns becomes an entry point which is named
like that file, but without the extension.
@param {...String} patterns
File patterns in glob-syntax (may contain * and **).
@return {Object} entry points for use as webpack `entry` configuration, as an object.
|
[
"Generates",
"webpack",
"entry",
"points",
"suitable",
"for",
"use",
"with",
"the",
"WebpackJasmineHtmlRunnerPlugin",
"plugin",
".",
"Basically",
"each",
"file",
"matching",
"one",
"of",
"the",
"provided",
"glob",
"-",
"patterns",
"becomes",
"an",
"entry",
"point",
"which",
"is",
"named",
"like",
"that",
"file",
"but",
"without",
"the",
"extension",
"."
] |
6a6671385dc54db67f44446fb52308d7513e66f7
|
https://github.com/LaxarJS/webpack-jasmine-html-runner-plugin/blob/6a6671385dc54db67f44446fb52308d7513e66f7/index.js#L34-L46
|
36,282 |
Inspired-by-Boredom/generator-vintage-frontend
|
generators/app/templates/gulp/tasks/templates.js
|
compileHtml
|
function compileHtml(src, dest) {
return gulp.src([src])
.pipe(plumber(config.plumberOptions))
.pipe(pug(pugOptions))
.pipe(prettify())
.pipe(gulp.dest(dest));
}
|
javascript
|
function compileHtml(src, dest) {
return gulp.src([src])
.pipe(plumber(config.plumberOptions))
.pipe(pug(pugOptions))
.pipe(prettify())
.pipe(gulp.dest(dest));
}
|
[
"function",
"compileHtml",
"(",
"src",
",",
"dest",
")",
"{",
"return",
"gulp",
".",
"src",
"(",
"[",
"src",
"]",
")",
".",
"pipe",
"(",
"plumber",
"(",
"config",
".",
"plumberOptions",
")",
")",
".",
"pipe",
"(",
"pug",
"(",
"pugOptions",
")",
")",
".",
"pipe",
"(",
"prettify",
"(",
")",
")",
".",
"pipe",
"(",
"gulp",
".",
"dest",
"(",
"dest",
")",
")",
";",
"}"
] |
Default HTML compilation function.
@param {String} src
@param {String} dest
|
[
"Default",
"HTML",
"compilation",
"function",
"."
] |
316ebc981961a39d3c47ba830f377350d529452b
|
https://github.com/Inspired-by-Boredom/generator-vintage-frontend/blob/316ebc981961a39d3c47ba830f377350d529452b/generators/app/templates/gulp/tasks/templates.js#L46-L52
|
36,283 |
ILLGrenoble/guacamole-common-js
|
src/Tunnel.js
|
addExtraHeaders
|
function addExtraHeaders(request, headers) {
for (var name in headers) {
request.setRequestHeader(name, headers[name]);
}
}
|
javascript
|
function addExtraHeaders(request, headers) {
for (var name in headers) {
request.setRequestHeader(name, headers[name]);
}
}
|
[
"function",
"addExtraHeaders",
"(",
"request",
",",
"headers",
")",
"{",
"for",
"(",
"var",
"name",
"in",
"headers",
")",
"{",
"request",
".",
"setRequestHeader",
"(",
"name",
",",
"headers",
"[",
"name",
"]",
")",
";",
"}",
"}"
] |
Adds the configured additional headers to the given request.
@param {XMLHttpRequest} request
The request where the configured extra headers will be added.
@param {Object} headers
The headers to be added to the request.
@private
|
[
"Adds",
"the",
"configured",
"additional",
"headers",
"to",
"the",
"given",
"request",
"."
] |
71925794155ea3fc37d2a125adbca6f8be532887
|
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/Tunnel.js#L242-L246
|
36,284 |
ILLGrenoble/guacamole-common-js
|
src/Tunnel.js
|
reset_timeout
|
function reset_timeout() {
// Get rid of old timeout (if any)
window.clearTimeout(receive_timeout);
// Set new timeout
receive_timeout = window.setTimeout(function () {
close_tunnel(new Guacamole.Status(Guacamole.Status.Code.UPSTREAM_TIMEOUT, "Server timeout."));
}, tunnel.receiveTimeout);
}
|
javascript
|
function reset_timeout() {
// Get rid of old timeout (if any)
window.clearTimeout(receive_timeout);
// Set new timeout
receive_timeout = window.setTimeout(function () {
close_tunnel(new Guacamole.Status(Guacamole.Status.Code.UPSTREAM_TIMEOUT, "Server timeout."));
}, tunnel.receiveTimeout);
}
|
[
"function",
"reset_timeout",
"(",
")",
"{",
"// Get rid of old timeout (if any)",
"window",
".",
"clearTimeout",
"(",
"receive_timeout",
")",
";",
"// Set new timeout",
"receive_timeout",
"=",
"window",
".",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"close_tunnel",
"(",
"new",
"Guacamole",
".",
"Status",
"(",
"Guacamole",
".",
"Status",
".",
"Code",
".",
"UPSTREAM_TIMEOUT",
",",
"\"Server timeout.\"",
")",
")",
";",
"}",
",",
"tunnel",
".",
"receiveTimeout",
")",
";",
"}"
] |
Initiates a timeout which, if data is not received, causes the tunnel
to close with an error.
@private
|
[
"Initiates",
"a",
"timeout",
"which",
"if",
"data",
"is",
"not",
"received",
"causes",
"the",
"tunnel",
"to",
"close",
"with",
"an",
"error",
"."
] |
71925794155ea3fc37d2a125adbca6f8be532887
|
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/Tunnel.js#L254-L264
|
36,285 |
ILLGrenoble/guacamole-common-js
|
src/Tunnel.js
|
attach
|
function attach(tunnel) {
// Set own functions to tunnel's functions
chained_tunnel.disconnect = tunnel.disconnect;
chained_tunnel.sendMessage = tunnel.sendMessage;
/**
* Fails the currently-attached tunnel, attaching a new tunnel if
* possible.
*
* @private
* @param {Guacamole.Status} [status]
* An object representing the failure that occured in the
* currently-attached tunnel, if known.
*
* @return {Guacamole.Tunnel}
* The next tunnel, or null if there are no more tunnels to try or
* if no more tunnels should be tried.
*/
var failTunnel = function failTunnel(status) {
// Do not attempt to continue using next tunnel on server timeout
if (status && status.code === Guacamole.Status.Code.UPSTREAM_TIMEOUT) {
tunnels = [];
return null;
}
// Get next tunnel
var next_tunnel = tunnels.shift();
// If there IS a next tunnel, try using it.
if (next_tunnel) {
tunnel.onerror = null;
tunnel.oninstruction = null;
tunnel.onstatechange = null;
attach(next_tunnel);
}
return next_tunnel;
};
/**
* Use the current tunnel from this point forward. Do not try any more
* tunnels, even if the current tunnel fails.
*
* @private
*/
function commit_tunnel() {
tunnel.onstatechange = chained_tunnel.onstatechange;
tunnel.oninstruction = chained_tunnel.oninstruction;
tunnel.onerror = chained_tunnel.onerror;
chained_tunnel.uuid = tunnel.uuid;
committedTunnel = tunnel;
}
// Wrap own onstatechange within current tunnel
tunnel.onstatechange = function(state) {
switch (state) {
// If open, use this tunnel from this point forward.
case Guacamole.Tunnel.State.OPEN:
commit_tunnel();
if (chained_tunnel.onstatechange)
chained_tunnel.onstatechange(state);
break;
// If closed, mark failure, attempt next tunnel
case Guacamole.Tunnel.State.CLOSED:
if (!failTunnel() && chained_tunnel.onstatechange)
chained_tunnel.onstatechange(state);
break;
}
};
// Wrap own oninstruction within current tunnel
tunnel.oninstruction = function(opcode, elements) {
// Accept current tunnel
commit_tunnel();
// Invoke handler
if (chained_tunnel.oninstruction)
chained_tunnel.oninstruction(opcode, elements);
};
// Attach next tunnel on error
tunnel.onerror = function(status) {
// Mark failure, attempt next tunnel
if (!failTunnel(status) && chained_tunnel.onerror)
chained_tunnel.onerror(status);
};
// Attempt connection
tunnel.connect(connect_data);
}
|
javascript
|
function attach(tunnel) {
// Set own functions to tunnel's functions
chained_tunnel.disconnect = tunnel.disconnect;
chained_tunnel.sendMessage = tunnel.sendMessage;
/**
* Fails the currently-attached tunnel, attaching a new tunnel if
* possible.
*
* @private
* @param {Guacamole.Status} [status]
* An object representing the failure that occured in the
* currently-attached tunnel, if known.
*
* @return {Guacamole.Tunnel}
* The next tunnel, or null if there are no more tunnels to try or
* if no more tunnels should be tried.
*/
var failTunnel = function failTunnel(status) {
// Do not attempt to continue using next tunnel on server timeout
if (status && status.code === Guacamole.Status.Code.UPSTREAM_TIMEOUT) {
tunnels = [];
return null;
}
// Get next tunnel
var next_tunnel = tunnels.shift();
// If there IS a next tunnel, try using it.
if (next_tunnel) {
tunnel.onerror = null;
tunnel.oninstruction = null;
tunnel.onstatechange = null;
attach(next_tunnel);
}
return next_tunnel;
};
/**
* Use the current tunnel from this point forward. Do not try any more
* tunnels, even if the current tunnel fails.
*
* @private
*/
function commit_tunnel() {
tunnel.onstatechange = chained_tunnel.onstatechange;
tunnel.oninstruction = chained_tunnel.oninstruction;
tunnel.onerror = chained_tunnel.onerror;
chained_tunnel.uuid = tunnel.uuid;
committedTunnel = tunnel;
}
// Wrap own onstatechange within current tunnel
tunnel.onstatechange = function(state) {
switch (state) {
// If open, use this tunnel from this point forward.
case Guacamole.Tunnel.State.OPEN:
commit_tunnel();
if (chained_tunnel.onstatechange)
chained_tunnel.onstatechange(state);
break;
// If closed, mark failure, attempt next tunnel
case Guacamole.Tunnel.State.CLOSED:
if (!failTunnel() && chained_tunnel.onstatechange)
chained_tunnel.onstatechange(state);
break;
}
};
// Wrap own oninstruction within current tunnel
tunnel.oninstruction = function(opcode, elements) {
// Accept current tunnel
commit_tunnel();
// Invoke handler
if (chained_tunnel.oninstruction)
chained_tunnel.oninstruction(opcode, elements);
};
// Attach next tunnel on error
tunnel.onerror = function(status) {
// Mark failure, attempt next tunnel
if (!failTunnel(status) && chained_tunnel.onerror)
chained_tunnel.onerror(status);
};
// Attempt connection
tunnel.connect(connect_data);
}
|
[
"function",
"attach",
"(",
"tunnel",
")",
"{",
"// Set own functions to tunnel's functions",
"chained_tunnel",
".",
"disconnect",
"=",
"tunnel",
".",
"disconnect",
";",
"chained_tunnel",
".",
"sendMessage",
"=",
"tunnel",
".",
"sendMessage",
";",
"/**\n * Fails the currently-attached tunnel, attaching a new tunnel if\n * possible.\n *\n * @private\n * @param {Guacamole.Status} [status]\n * An object representing the failure that occured in the\n * currently-attached tunnel, if known.\n *\n * @return {Guacamole.Tunnel}\n * The next tunnel, or null if there are no more tunnels to try or\n * if no more tunnels should be tried.\n */",
"var",
"failTunnel",
"=",
"function",
"failTunnel",
"(",
"status",
")",
"{",
"// Do not attempt to continue using next tunnel on server timeout",
"if",
"(",
"status",
"&&",
"status",
".",
"code",
"===",
"Guacamole",
".",
"Status",
".",
"Code",
".",
"UPSTREAM_TIMEOUT",
")",
"{",
"tunnels",
"=",
"[",
"]",
";",
"return",
"null",
";",
"}",
"// Get next tunnel",
"var",
"next_tunnel",
"=",
"tunnels",
".",
"shift",
"(",
")",
";",
"// If there IS a next tunnel, try using it.",
"if",
"(",
"next_tunnel",
")",
"{",
"tunnel",
".",
"onerror",
"=",
"null",
";",
"tunnel",
".",
"oninstruction",
"=",
"null",
";",
"tunnel",
".",
"onstatechange",
"=",
"null",
";",
"attach",
"(",
"next_tunnel",
")",
";",
"}",
"return",
"next_tunnel",
";",
"}",
";",
"/**\n * Use the current tunnel from this point forward. Do not try any more\n * tunnels, even if the current tunnel fails.\n * \n * @private\n */",
"function",
"commit_tunnel",
"(",
")",
"{",
"tunnel",
".",
"onstatechange",
"=",
"chained_tunnel",
".",
"onstatechange",
";",
"tunnel",
".",
"oninstruction",
"=",
"chained_tunnel",
".",
"oninstruction",
";",
"tunnel",
".",
"onerror",
"=",
"chained_tunnel",
".",
"onerror",
";",
"chained_tunnel",
".",
"uuid",
"=",
"tunnel",
".",
"uuid",
";",
"committedTunnel",
"=",
"tunnel",
";",
"}",
"// Wrap own onstatechange within current tunnel",
"tunnel",
".",
"onstatechange",
"=",
"function",
"(",
"state",
")",
"{",
"switch",
"(",
"state",
")",
"{",
"// If open, use this tunnel from this point forward.",
"case",
"Guacamole",
".",
"Tunnel",
".",
"State",
".",
"OPEN",
":",
"commit_tunnel",
"(",
")",
";",
"if",
"(",
"chained_tunnel",
".",
"onstatechange",
")",
"chained_tunnel",
".",
"onstatechange",
"(",
"state",
")",
";",
"break",
";",
"// If closed, mark failure, attempt next tunnel",
"case",
"Guacamole",
".",
"Tunnel",
".",
"State",
".",
"CLOSED",
":",
"if",
"(",
"!",
"failTunnel",
"(",
")",
"&&",
"chained_tunnel",
".",
"onstatechange",
")",
"chained_tunnel",
".",
"onstatechange",
"(",
"state",
")",
";",
"break",
";",
"}",
"}",
";",
"// Wrap own oninstruction within current tunnel",
"tunnel",
".",
"oninstruction",
"=",
"function",
"(",
"opcode",
",",
"elements",
")",
"{",
"// Accept current tunnel",
"commit_tunnel",
"(",
")",
";",
"// Invoke handler",
"if",
"(",
"chained_tunnel",
".",
"oninstruction",
")",
"chained_tunnel",
".",
"oninstruction",
"(",
"opcode",
",",
"elements",
")",
";",
"}",
";",
"// Attach next tunnel on error",
"tunnel",
".",
"onerror",
"=",
"function",
"(",
"status",
")",
"{",
"// Mark failure, attempt next tunnel",
"if",
"(",
"!",
"failTunnel",
"(",
"status",
")",
"&&",
"chained_tunnel",
".",
"onerror",
")",
"chained_tunnel",
".",
"onerror",
"(",
"status",
")",
";",
"}",
";",
"// Attempt connection",
"tunnel",
".",
"connect",
"(",
"connect_data",
")",
";",
"}"
] |
Sets the current tunnel.
@private
@param {Guacamole.Tunnel} tunnel The tunnel to set as the current tunnel.
|
[
"Sets",
"the",
"current",
"tunnel",
"."
] |
71925794155ea3fc37d2a125adbca6f8be532887
|
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/Tunnel.js#L954-L1056
|
36,286 |
ILLGrenoble/guacamole-common-js
|
src/Tunnel.js
|
failTunnel
|
function failTunnel(status) {
// Do not attempt to continue using next tunnel on server timeout
if (status && status.code === Guacamole.Status.Code.UPSTREAM_TIMEOUT) {
tunnels = [];
return null;
}
// Get next tunnel
var next_tunnel = tunnels.shift();
// If there IS a next tunnel, try using it.
if (next_tunnel) {
tunnel.onerror = null;
tunnel.oninstruction = null;
tunnel.onstatechange = null;
attach(next_tunnel);
}
return next_tunnel;
}
|
javascript
|
function failTunnel(status) {
// Do not attempt to continue using next tunnel on server timeout
if (status && status.code === Guacamole.Status.Code.UPSTREAM_TIMEOUT) {
tunnels = [];
return null;
}
// Get next tunnel
var next_tunnel = tunnels.shift();
// If there IS a next tunnel, try using it.
if (next_tunnel) {
tunnel.onerror = null;
tunnel.oninstruction = null;
tunnel.onstatechange = null;
attach(next_tunnel);
}
return next_tunnel;
}
|
[
"function",
"failTunnel",
"(",
"status",
")",
"{",
"// Do not attempt to continue using next tunnel on server timeout",
"if",
"(",
"status",
"&&",
"status",
".",
"code",
"===",
"Guacamole",
".",
"Status",
".",
"Code",
".",
"UPSTREAM_TIMEOUT",
")",
"{",
"tunnels",
"=",
"[",
"]",
";",
"return",
"null",
";",
"}",
"// Get next tunnel",
"var",
"next_tunnel",
"=",
"tunnels",
".",
"shift",
"(",
")",
";",
"// If there IS a next tunnel, try using it.",
"if",
"(",
"next_tunnel",
")",
"{",
"tunnel",
".",
"onerror",
"=",
"null",
";",
"tunnel",
".",
"oninstruction",
"=",
"null",
";",
"tunnel",
".",
"onstatechange",
"=",
"null",
";",
"attach",
"(",
"next_tunnel",
")",
";",
"}",
"return",
"next_tunnel",
";",
"}"
] |
Fails the currently-attached tunnel, attaching a new tunnel if
possible.
@private
@param {Guacamole.Status} [status]
An object representing the failure that occured in the
currently-attached tunnel, if known.
@return {Guacamole.Tunnel}
The next tunnel, or null if there are no more tunnels to try or
if no more tunnels should be tried.
|
[
"Fails",
"the",
"currently",
"-",
"attached",
"tunnel",
"attaching",
"a",
"new",
"tunnel",
"if",
"possible",
"."
] |
71925794155ea3fc37d2a125adbca6f8be532887
|
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/Tunnel.js#L973-L994
|
36,287 |
ILLGrenoble/guacamole-common-js
|
src/Tunnel.js
|
commit_tunnel
|
function commit_tunnel() {
tunnel.onstatechange = chained_tunnel.onstatechange;
tunnel.oninstruction = chained_tunnel.oninstruction;
tunnel.onerror = chained_tunnel.onerror;
chained_tunnel.uuid = tunnel.uuid;
committedTunnel = tunnel;
}
|
javascript
|
function commit_tunnel() {
tunnel.onstatechange = chained_tunnel.onstatechange;
tunnel.oninstruction = chained_tunnel.oninstruction;
tunnel.onerror = chained_tunnel.onerror;
chained_tunnel.uuid = tunnel.uuid;
committedTunnel = tunnel;
}
|
[
"function",
"commit_tunnel",
"(",
")",
"{",
"tunnel",
".",
"onstatechange",
"=",
"chained_tunnel",
".",
"onstatechange",
";",
"tunnel",
".",
"oninstruction",
"=",
"chained_tunnel",
".",
"oninstruction",
";",
"tunnel",
".",
"onerror",
"=",
"chained_tunnel",
".",
"onerror",
";",
"chained_tunnel",
".",
"uuid",
"=",
"tunnel",
".",
"uuid",
";",
"committedTunnel",
"=",
"tunnel",
";",
"}"
] |
Use the current tunnel from this point forward. Do not try any more
tunnels, even if the current tunnel fails.
@private
|
[
"Use",
"the",
"current",
"tunnel",
"from",
"this",
"point",
"forward",
".",
"Do",
"not",
"try",
"any",
"more",
"tunnels",
"even",
"if",
"the",
"current",
"tunnel",
"fails",
"."
] |
71925794155ea3fc37d2a125adbca6f8be532887
|
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/Tunnel.js#L1002-L1008
|
36,288 |
ILLGrenoble/guacamole-common-js
|
src/Tunnel.js
|
getGuacamoleStatusCode
|
function getGuacamoleStatusCode(httpStatus) {
// Translate status codes with known equivalents
switch (httpStatus) {
// HTTP 400 - Bad request
case 400:
return Guacamole.Status.Code.CLIENT_BAD_REQUEST;
// HTTP 403 - Forbidden
case 403:
return Guacamole.Status.Code.CLIENT_FORBIDDEN;
// HTTP 404 - Resource not found
case 404:
return Guacamole.Status.Code.RESOURCE_NOT_FOUND;
// HTTP 429 - Too many requests
case 429:
return Guacamole.Status.Code.CLIENT_TOO_MANY;
// HTTP 503 - Server unavailable
case 503:
return Guacamole.Status.Code.SERVER_BUSY;
}
// Default all other codes to generic internal error
return Guacamole.Status.Code.SERVER_ERROR;
}
|
javascript
|
function getGuacamoleStatusCode(httpStatus) {
// Translate status codes with known equivalents
switch (httpStatus) {
// HTTP 400 - Bad request
case 400:
return Guacamole.Status.Code.CLIENT_BAD_REQUEST;
// HTTP 403 - Forbidden
case 403:
return Guacamole.Status.Code.CLIENT_FORBIDDEN;
// HTTP 404 - Resource not found
case 404:
return Guacamole.Status.Code.RESOURCE_NOT_FOUND;
// HTTP 429 - Too many requests
case 429:
return Guacamole.Status.Code.CLIENT_TOO_MANY;
// HTTP 503 - Server unavailable
case 503:
return Guacamole.Status.Code.SERVER_BUSY;
}
// Default all other codes to generic internal error
return Guacamole.Status.Code.SERVER_ERROR;
}
|
[
"function",
"getGuacamoleStatusCode",
"(",
"httpStatus",
")",
"{",
"// Translate status codes with known equivalents",
"switch",
"(",
"httpStatus",
")",
"{",
"// HTTP 400 - Bad request",
"case",
"400",
":",
"return",
"Guacamole",
".",
"Status",
".",
"Code",
".",
"CLIENT_BAD_REQUEST",
";",
"// HTTP 403 - Forbidden",
"case",
"403",
":",
"return",
"Guacamole",
".",
"Status",
".",
"Code",
".",
"CLIENT_FORBIDDEN",
";",
"// HTTP 404 - Resource not found",
"case",
"404",
":",
"return",
"Guacamole",
".",
"Status",
".",
"Code",
".",
"RESOURCE_NOT_FOUND",
";",
"// HTTP 429 - Too many requests",
"case",
"429",
":",
"return",
"Guacamole",
".",
"Status",
".",
"Code",
".",
"CLIENT_TOO_MANY",
";",
"// HTTP 503 - Server unavailable",
"case",
"503",
":",
"return",
"Guacamole",
".",
"Status",
".",
"Code",
".",
"SERVER_BUSY",
";",
"}",
"// Default all other codes to generic internal error",
"return",
"Guacamole",
".",
"Status",
".",
"Code",
".",
"SERVER_ERROR",
";",
"}"
] |
Returns the Guacamole protocol status code which most closely
represents the given HTTP status code.
@private
@param {Number} httpStatus
The HTTP status code to translate into a Guacamole protocol status
code.
@returns {Number}
The Guacamole protocol status code which most closely represents the
given HTTP status code.
|
[
"Returns",
"the",
"Guacamole",
"protocol",
"status",
"code",
"which",
"most",
"closely",
"represents",
"the",
"given",
"HTTP",
"status",
"code",
"."
] |
71925794155ea3fc37d2a125adbca6f8be532887
|
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/Tunnel.js#L1157-L1187
|
36,289 |
smshuja/parse-server-accountkit-auth
|
index.js
|
validateAuthData
|
function validateAuthData(authData, config) {
var appSecretProof = crypto.createHmac('sha256', config.appSecret).update(authData.access_token).digest('hex');
return graphRequest('me/?access_token=' + authData.access_token + '&appsecret_proof=' + appSecretProof)
.then((data) => {
if (data && data.id == authData.id) {
return;
}
throw new Parse.Error(
Parse.Error.OBJECT_NOT_FOUND,
'AccountKit auth is invalid for this user.');
});
}
|
javascript
|
function validateAuthData(authData, config) {
var appSecretProof = crypto.createHmac('sha256', config.appSecret).update(authData.access_token).digest('hex');
return graphRequest('me/?access_token=' + authData.access_token + '&appsecret_proof=' + appSecretProof)
.then((data) => {
if (data && data.id == authData.id) {
return;
}
throw new Parse.Error(
Parse.Error.OBJECT_NOT_FOUND,
'AccountKit auth is invalid for this user.');
});
}
|
[
"function",
"validateAuthData",
"(",
"authData",
",",
"config",
")",
"{",
"var",
"appSecretProof",
"=",
"crypto",
".",
"createHmac",
"(",
"'sha256'",
",",
"config",
".",
"appSecret",
")",
".",
"update",
"(",
"authData",
".",
"access_token",
")",
".",
"digest",
"(",
"'hex'",
")",
";",
"return",
"graphRequest",
"(",
"'me/?access_token='",
"+",
"authData",
".",
"access_token",
"+",
"'&appsecret_proof='",
"+",
"appSecretProof",
")",
".",
"then",
"(",
"(",
"data",
")",
"=>",
"{",
"if",
"(",
"data",
"&&",
"data",
".",
"id",
"==",
"authData",
".",
"id",
")",
"{",
"return",
";",
"}",
"throw",
"new",
"Parse",
".",
"Error",
"(",
"Parse",
".",
"Error",
".",
"OBJECT_NOT_FOUND",
",",
"'AccountKit auth is invalid for this user.'",
")",
";",
"}",
")",
";",
"}"
] |
Returns a promise that fulfills iff this user id is valid.
|
[
"Returns",
"a",
"promise",
"that",
"fulfills",
"iff",
"this",
"user",
"id",
"is",
"valid",
"."
] |
6a47523ce08f0bc8f39c372e1a99d15d4d9e4aca
|
https://github.com/smshuja/parse-server-accountkit-auth/blob/6a47523ce08f0bc8f39c372e1a99d15d4d9e4aca/index.js#L7-L18
|
36,290 |
GiladShoham/seven-boom
|
lib/wrappedBoomFunction.js
|
getWrappedFunc
|
function getWrappedFunc(funcName, func, ...args) {
const funcDefaultArgs = defaultArgs[funcName] || defaultArgs['default'];
const allArgs = funcDefaultArgs.concat(args);
return function(...allArgs) {
const boomArgs = _.take(allArgs, funcDefaultArgs.length);
let result = func.call(null, ...boomArgs);
for (var i = 0; i < args.length; i++) {
let currArgVal = allArgs[i + funcDefaultArgs.length];
const argDef = args[i];
// Check if we need to use the defaults
if (currArgVal === undefined){
// Run the function from the args def
if (_.isFunction(argDef.default)) {
result.output.payload[argDef.name] = argDef.default();
// Add the default value to result
} else if (argDef.default) {
result.output.payload[argDef.name] = argDef.default;
}
// Add the passed value to result
} else {
result.output.payload[argDef.name] = currArgVal;
}
}
return result;
};
}
|
javascript
|
function getWrappedFunc(funcName, func, ...args) {
const funcDefaultArgs = defaultArgs[funcName] || defaultArgs['default'];
const allArgs = funcDefaultArgs.concat(args);
return function(...allArgs) {
const boomArgs = _.take(allArgs, funcDefaultArgs.length);
let result = func.call(null, ...boomArgs);
for (var i = 0; i < args.length; i++) {
let currArgVal = allArgs[i + funcDefaultArgs.length];
const argDef = args[i];
// Check if we need to use the defaults
if (currArgVal === undefined){
// Run the function from the args def
if (_.isFunction(argDef.default)) {
result.output.payload[argDef.name] = argDef.default();
// Add the default value to result
} else if (argDef.default) {
result.output.payload[argDef.name] = argDef.default;
}
// Add the passed value to result
} else {
result.output.payload[argDef.name] = currArgVal;
}
}
return result;
};
}
|
[
"function",
"getWrappedFunc",
"(",
"funcName",
",",
"func",
",",
"...",
"args",
")",
"{",
"const",
"funcDefaultArgs",
"=",
"defaultArgs",
"[",
"funcName",
"]",
"||",
"defaultArgs",
"[",
"'default'",
"]",
";",
"const",
"allArgs",
"=",
"funcDefaultArgs",
".",
"concat",
"(",
"args",
")",
";",
"return",
"function",
"(",
"...",
"allArgs",
")",
"{",
"const",
"boomArgs",
"=",
"_",
".",
"take",
"(",
"allArgs",
",",
"funcDefaultArgs",
".",
"length",
")",
";",
"let",
"result",
"=",
"func",
".",
"call",
"(",
"null",
",",
"...",
"boomArgs",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"args",
".",
"length",
";",
"i",
"++",
")",
"{",
"let",
"currArgVal",
"=",
"allArgs",
"[",
"i",
"+",
"funcDefaultArgs",
".",
"length",
"]",
";",
"const",
"argDef",
"=",
"args",
"[",
"i",
"]",
";",
"// Check if we need to use the defaults",
"if",
"(",
"currArgVal",
"===",
"undefined",
")",
"{",
"// Run the function from the args def",
"if",
"(",
"_",
".",
"isFunction",
"(",
"argDef",
".",
"default",
")",
")",
"{",
"result",
".",
"output",
".",
"payload",
"[",
"argDef",
".",
"name",
"]",
"=",
"argDef",
".",
"default",
"(",
")",
";",
"// Add the default value to result",
"}",
"else",
"if",
"(",
"argDef",
".",
"default",
")",
"{",
"result",
".",
"output",
".",
"payload",
"[",
"argDef",
".",
"name",
"]",
"=",
"argDef",
".",
"default",
";",
"}",
"// Add the passed value to result",
"}",
"else",
"{",
"result",
".",
"output",
".",
"payload",
"[",
"argDef",
".",
"name",
"]",
"=",
"currArgVal",
";",
"}",
"}",
"return",
"result",
";",
"}",
";",
"}"
] |
This function gets a boom function and arguments in new format and return
a wrapped boom function
|
[
"This",
"function",
"gets",
"a",
"boom",
"function",
"and",
"arguments",
"in",
"new",
"format",
"and",
"return",
"a",
"wrapped",
"boom",
"function"
] |
38b1469260743b5b083f8ca185786ef74a693844
|
https://github.com/GiladShoham/seven-boom/blob/38b1469260743b5b083f8ca185786ef74a693844/lib/wrappedBoomFunction.js#L15-L41
|
36,291 |
ILLGrenoble/guacamole-common-js
|
src/Display.js
|
__flush_frames
|
function __flush_frames() {
var rendered_frames = 0;
// Draw all pending frames, if ready
while (rendered_frames < frames.length) {
var frame = frames[rendered_frames];
if (!frame.isReady())
break;
frame.flush();
rendered_frames++;
}
// Remove rendered frames from array
frames.splice(0, rendered_frames);
}
|
javascript
|
function __flush_frames() {
var rendered_frames = 0;
// Draw all pending frames, if ready
while (rendered_frames < frames.length) {
var frame = frames[rendered_frames];
if (!frame.isReady())
break;
frame.flush();
rendered_frames++;
}
// Remove rendered frames from array
frames.splice(0, rendered_frames);
}
|
[
"function",
"__flush_frames",
"(",
")",
"{",
"var",
"rendered_frames",
"=",
"0",
";",
"// Draw all pending frames, if ready",
"while",
"(",
"rendered_frames",
"<",
"frames",
".",
"length",
")",
"{",
"var",
"frame",
"=",
"frames",
"[",
"rendered_frames",
"]",
";",
"if",
"(",
"!",
"frame",
".",
"isReady",
"(",
")",
")",
"break",
";",
"frame",
".",
"flush",
"(",
")",
";",
"rendered_frames",
"++",
";",
"}",
"// Remove rendered frames from array",
"frames",
".",
"splice",
"(",
"0",
",",
"rendered_frames",
")",
";",
"}"
] |
Flushes all pending frames.
@private
|
[
"Flushes",
"all",
"pending",
"frames",
"."
] |
71925794155ea3fc37d2a125adbca6f8be532887
|
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/Display.js#L159-L178
|
36,292 |
ILLGrenoble/guacamole-common-js
|
src/Display.js
|
Task
|
function Task(taskHandler, blocked) {
var task = this;
/**
* Whether this Task is blocked.
*
* @type {boolean}
*/
this.blocked = blocked;
/**
* Unblocks this Task, allowing it to run.
*/
this.unblock = function() {
if (task.blocked) {
task.blocked = false;
__flush_frames();
}
};
/**
* Calls the handler associated with this task IMMEDIATELY. This
* function does not track whether this task is marked as blocked.
* Enforcing the blocked status of tasks is up to the caller.
*/
this.execute = function() {
if (taskHandler) taskHandler();
};
}
|
javascript
|
function Task(taskHandler, blocked) {
var task = this;
/**
* Whether this Task is blocked.
*
* @type {boolean}
*/
this.blocked = blocked;
/**
* Unblocks this Task, allowing it to run.
*/
this.unblock = function() {
if (task.blocked) {
task.blocked = false;
__flush_frames();
}
};
/**
* Calls the handler associated with this task IMMEDIATELY. This
* function does not track whether this task is marked as blocked.
* Enforcing the blocked status of tasks is up to the caller.
*/
this.execute = function() {
if (taskHandler) taskHandler();
};
}
|
[
"function",
"Task",
"(",
"taskHandler",
",",
"blocked",
")",
"{",
"var",
"task",
"=",
"this",
";",
"/**\n * Whether this Task is blocked.\n * \n * @type {boolean}\n */",
"this",
".",
"blocked",
"=",
"blocked",
";",
"/**\n * Unblocks this Task, allowing it to run.\n */",
"this",
".",
"unblock",
"=",
"function",
"(",
")",
"{",
"if",
"(",
"task",
".",
"blocked",
")",
"{",
"task",
".",
"blocked",
"=",
"false",
";",
"__flush_frames",
"(",
")",
";",
"}",
"}",
";",
"/**\n * Calls the handler associated with this task IMMEDIATELY. This\n * function does not track whether this task is marked as blocked.\n * Enforcing the blocked status of tasks is up to the caller.\n */",
"this",
".",
"execute",
"=",
"function",
"(",
")",
"{",
"if",
"(",
"taskHandler",
")",
"taskHandler",
"(",
")",
";",
"}",
";",
"}"
] |
A container for an task handler. Each operation which must be ordered
is associated with a Task that goes into a task queue. Tasks in this
queue are executed in order once their handlers are set, while Tasks
without handlers block themselves and any following Tasks from running.
@constructor
@private
@param {function} taskHandler The function to call when this task
runs, if any.
@param {boolean} blocked Whether this task should start blocked.
|
[
"A",
"container",
"for",
"an",
"task",
"handler",
".",
"Each",
"operation",
"which",
"must",
"be",
"ordered",
"is",
"associated",
"with",
"a",
"Task",
"that",
"goes",
"into",
"a",
"task",
"queue",
".",
"Tasks",
"in",
"this",
"queue",
"are",
"executed",
"in",
"order",
"once",
"their",
"handlers",
"are",
"set",
"while",
"Tasks",
"without",
"handlers",
"block",
"themselves",
"and",
"any",
"following",
"Tasks",
"from",
"running",
"."
] |
71925794155ea3fc37d2a125adbca6f8be532887
|
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/Display.js#L244-L274
|
36,293 |
ILLGrenoble/guacamole-common-js
|
src/Display.js
|
get_children
|
function get_children(layer) {
// Build array of children
var children = [];
for (var index in layer.children)
children.push(layer.children[index]);
// Sort
children.sort(function children_comparator(a, b) {
// Compare based on Z order
var diff = a.z - b.z;
if (diff !== 0)
return diff;
// If Z order identical, use document order
var a_element = a.getElement();
var b_element = b.getElement();
var position = b_element.compareDocumentPosition(a_element);
if (position & Node.DOCUMENT_POSITION_PRECEDING) return -1;
if (position & Node.DOCUMENT_POSITION_FOLLOWING) return 1;
// Otherwise, assume same
return 0;
});
// Done
return children;
}
|
javascript
|
function get_children(layer) {
// Build array of children
var children = [];
for (var index in layer.children)
children.push(layer.children[index]);
// Sort
children.sort(function children_comparator(a, b) {
// Compare based on Z order
var diff = a.z - b.z;
if (diff !== 0)
return diff;
// If Z order identical, use document order
var a_element = a.getElement();
var b_element = b.getElement();
var position = b_element.compareDocumentPosition(a_element);
if (position & Node.DOCUMENT_POSITION_PRECEDING) return -1;
if (position & Node.DOCUMENT_POSITION_FOLLOWING) return 1;
// Otherwise, assume same
return 0;
});
// Done
return children;
}
|
[
"function",
"get_children",
"(",
"layer",
")",
"{",
"// Build array of children",
"var",
"children",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"index",
"in",
"layer",
".",
"children",
")",
"children",
".",
"push",
"(",
"layer",
".",
"children",
"[",
"index",
"]",
")",
";",
"// Sort",
"children",
".",
"sort",
"(",
"function",
"children_comparator",
"(",
"a",
",",
"b",
")",
"{",
"// Compare based on Z order",
"var",
"diff",
"=",
"a",
".",
"z",
"-",
"b",
".",
"z",
";",
"if",
"(",
"diff",
"!==",
"0",
")",
"return",
"diff",
";",
"// If Z order identical, use document order",
"var",
"a_element",
"=",
"a",
".",
"getElement",
"(",
")",
";",
"var",
"b_element",
"=",
"b",
".",
"getElement",
"(",
")",
";",
"var",
"position",
"=",
"b_element",
".",
"compareDocumentPosition",
"(",
"a_element",
")",
";",
"if",
"(",
"position",
"&",
"Node",
".",
"DOCUMENT_POSITION_PRECEDING",
")",
"return",
"-",
"1",
";",
"if",
"(",
"position",
"&",
"Node",
".",
"DOCUMENT_POSITION_FOLLOWING",
")",
"return",
"1",
";",
"// Otherwise, assume same",
"return",
"0",
";",
"}",
")",
";",
"// Done",
"return",
"children",
";",
"}"
] |
Returns sorted array of children
|
[
"Returns",
"sorted",
"array",
"of",
"children"
] |
71925794155ea3fc37d2a125adbca6f8be532887
|
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/Display.js#L1141-L1172
|
36,294 |
ILLGrenoble/guacamole-common-js
|
src/Display.js
|
draw_layer
|
function draw_layer(layer, x, y) {
// Draw layer
if (layer.width > 0 && layer.height > 0) {
// Save and update alpha
var initial_alpha = context.globalAlpha;
context.globalAlpha *= layer.alpha / 255.0;
// Copy data
context.drawImage(layer.getCanvas(), x, y);
// Draw all children
var children = get_children(layer);
for (var i=0; i<children.length; i++) {
var child = children[i];
draw_layer(child, x + child.x, y + child.y);
}
// Restore alpha
context.globalAlpha = initial_alpha;
}
}
|
javascript
|
function draw_layer(layer, x, y) {
// Draw layer
if (layer.width > 0 && layer.height > 0) {
// Save and update alpha
var initial_alpha = context.globalAlpha;
context.globalAlpha *= layer.alpha / 255.0;
// Copy data
context.drawImage(layer.getCanvas(), x, y);
// Draw all children
var children = get_children(layer);
for (var i=0; i<children.length; i++) {
var child = children[i];
draw_layer(child, x + child.x, y + child.y);
}
// Restore alpha
context.globalAlpha = initial_alpha;
}
}
|
[
"function",
"draw_layer",
"(",
"layer",
",",
"x",
",",
"y",
")",
"{",
"// Draw layer",
"if",
"(",
"layer",
".",
"width",
">",
"0",
"&&",
"layer",
".",
"height",
">",
"0",
")",
"{",
"// Save and update alpha",
"var",
"initial_alpha",
"=",
"context",
".",
"globalAlpha",
";",
"context",
".",
"globalAlpha",
"*=",
"layer",
".",
"alpha",
"/",
"255.0",
";",
"// Copy data",
"context",
".",
"drawImage",
"(",
"layer",
".",
"getCanvas",
"(",
")",
",",
"x",
",",
"y",
")",
";",
"// Draw all children",
"var",
"children",
"=",
"get_children",
"(",
"layer",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"children",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"child",
"=",
"children",
"[",
"i",
"]",
";",
"draw_layer",
"(",
"child",
",",
"x",
"+",
"child",
".",
"x",
",",
"y",
"+",
"child",
".",
"y",
")",
";",
"}",
"// Restore alpha",
"context",
".",
"globalAlpha",
"=",
"initial_alpha",
";",
"}",
"}"
] |
Draws the contents of the given layer at the given coordinates
|
[
"Draws",
"the",
"contents",
"of",
"the",
"given",
"layer",
"at",
"the",
"given",
"coordinates"
] |
71925794155ea3fc37d2a125adbca6f8be532887
|
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/Display.js#L1175-L1199
|
36,295 |
ILLGrenoble/guacamole-common-js
|
src/AudioPlayer.js
|
joinAudioPackets
|
function joinAudioPackets(packets) {
// Do not bother joining if one or fewer packets are in the queue
if (packets.length <= 1)
return packets[0];
// Determine total sample length of the entire queue
var totalLength = 0;
packets.forEach(function addPacketLengths(packet) {
totalLength += packet.length;
});
// Append each packet within queue
var offset = 0;
var joined = new SampleArray(totalLength);
packets.forEach(function appendPacket(packet) {
joined.set(packet, offset);
offset += packet.length;
});
return joined;
}
|
javascript
|
function joinAudioPackets(packets) {
// Do not bother joining if one or fewer packets are in the queue
if (packets.length <= 1)
return packets[0];
// Determine total sample length of the entire queue
var totalLength = 0;
packets.forEach(function addPacketLengths(packet) {
totalLength += packet.length;
});
// Append each packet within queue
var offset = 0;
var joined = new SampleArray(totalLength);
packets.forEach(function appendPacket(packet) {
joined.set(packet, offset);
offset += packet.length;
});
return joined;
}
|
[
"function",
"joinAudioPackets",
"(",
"packets",
")",
"{",
"// Do not bother joining if one or fewer packets are in the queue",
"if",
"(",
"packets",
".",
"length",
"<=",
"1",
")",
"return",
"packets",
"[",
"0",
"]",
";",
"// Determine total sample length of the entire queue",
"var",
"totalLength",
"=",
"0",
";",
"packets",
".",
"forEach",
"(",
"function",
"addPacketLengths",
"(",
"packet",
")",
"{",
"totalLength",
"+=",
"packet",
".",
"length",
";",
"}",
")",
";",
"// Append each packet within queue",
"var",
"offset",
"=",
"0",
";",
"var",
"joined",
"=",
"new",
"SampleArray",
"(",
"totalLength",
")",
";",
"packets",
".",
"forEach",
"(",
"function",
"appendPacket",
"(",
"packet",
")",
"{",
"joined",
".",
"set",
"(",
"packet",
",",
"offset",
")",
";",
"offset",
"+=",
"packet",
".",
"length",
";",
"}",
")",
";",
"return",
"joined",
";",
"}"
] |
Given an array of audio packets, returns a single audio packet
containing the concatenation of those packets.
@private
@param {SampleArray[]} packets
The array of audio packets to concatenate.
@returns {SampleArray}
A single audio packet containing the concatenation of all given
audio packets. If no packets are provided, this will be undefined.
|
[
"Given",
"an",
"array",
"of",
"audio",
"packets",
"returns",
"a",
"single",
"audio",
"packet",
"containing",
"the",
"concatenation",
"of",
"those",
"packets",
"."
] |
71925794155ea3fc37d2a125adbca6f8be532887
|
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/AudioPlayer.js#L228-L250
|
36,296 |
ILLGrenoble/guacamole-common-js
|
src/AudioPlayer.js
|
splitAudioPacket
|
function splitAudioPacket(data) {
var minValue = Number.MAX_VALUE;
var optimalSplitLength = data.length;
// Calculate number of whole samples in the provided audio packet AND
// in the minimum possible split packet
var samples = Math.floor(data.length / format.channels);
var minSplitSamples = Math.floor(format.rate * MIN_SPLIT_SIZE);
// Calculate the beginning of the "end" of the audio packet
var start = Math.max(
format.channels * minSplitSamples,
format.channels * (samples - minSplitSamples)
);
// For all samples at the end of the given packet, find a point where
// the perceptible volume across all channels is lowest (and thus is
// the optimal point to split)
for (var offset = start; offset < data.length; offset += format.channels) {
// Calculate the sum of all values across all channels (the result
// will be proportional to the average volume of a sample)
var totalValue = 0;
for (var channel = 0; channel < format.channels; channel++) {
totalValue += Math.abs(data[offset + channel]);
}
// If this is the smallest average value thus far, set the split
// length such that the first packet ends with the current sample
if (totalValue <= minValue) {
optimalSplitLength = offset + format.channels;
minValue = totalValue;
}
}
// If packet is not split, return the supplied packet untouched
if (optimalSplitLength === data.length)
return [data];
// Otherwise, split the packet into two new packets according to the
// calculated optimal split length
return [
new SampleArray(data.buffer.slice(0, optimalSplitLength * format.bytesPerSample)),
new SampleArray(data.buffer.slice(optimalSplitLength * format.bytesPerSample))
];
}
|
javascript
|
function splitAudioPacket(data) {
var minValue = Number.MAX_VALUE;
var optimalSplitLength = data.length;
// Calculate number of whole samples in the provided audio packet AND
// in the minimum possible split packet
var samples = Math.floor(data.length / format.channels);
var minSplitSamples = Math.floor(format.rate * MIN_SPLIT_SIZE);
// Calculate the beginning of the "end" of the audio packet
var start = Math.max(
format.channels * minSplitSamples,
format.channels * (samples - minSplitSamples)
);
// For all samples at the end of the given packet, find a point where
// the perceptible volume across all channels is lowest (and thus is
// the optimal point to split)
for (var offset = start; offset < data.length; offset += format.channels) {
// Calculate the sum of all values across all channels (the result
// will be proportional to the average volume of a sample)
var totalValue = 0;
for (var channel = 0; channel < format.channels; channel++) {
totalValue += Math.abs(data[offset + channel]);
}
// If this is the smallest average value thus far, set the split
// length such that the first packet ends with the current sample
if (totalValue <= minValue) {
optimalSplitLength = offset + format.channels;
minValue = totalValue;
}
}
// If packet is not split, return the supplied packet untouched
if (optimalSplitLength === data.length)
return [data];
// Otherwise, split the packet into two new packets according to the
// calculated optimal split length
return [
new SampleArray(data.buffer.slice(0, optimalSplitLength * format.bytesPerSample)),
new SampleArray(data.buffer.slice(optimalSplitLength * format.bytesPerSample))
];
}
|
[
"function",
"splitAudioPacket",
"(",
"data",
")",
"{",
"var",
"minValue",
"=",
"Number",
".",
"MAX_VALUE",
";",
"var",
"optimalSplitLength",
"=",
"data",
".",
"length",
";",
"// Calculate number of whole samples in the provided audio packet AND",
"// in the minimum possible split packet",
"var",
"samples",
"=",
"Math",
".",
"floor",
"(",
"data",
".",
"length",
"/",
"format",
".",
"channels",
")",
";",
"var",
"minSplitSamples",
"=",
"Math",
".",
"floor",
"(",
"format",
".",
"rate",
"*",
"MIN_SPLIT_SIZE",
")",
";",
"// Calculate the beginning of the \"end\" of the audio packet",
"var",
"start",
"=",
"Math",
".",
"max",
"(",
"format",
".",
"channels",
"*",
"minSplitSamples",
",",
"format",
".",
"channels",
"*",
"(",
"samples",
"-",
"minSplitSamples",
")",
")",
";",
"// For all samples at the end of the given packet, find a point where",
"// the perceptible volume across all channels is lowest (and thus is",
"// the optimal point to split)",
"for",
"(",
"var",
"offset",
"=",
"start",
";",
"offset",
"<",
"data",
".",
"length",
";",
"offset",
"+=",
"format",
".",
"channels",
")",
"{",
"// Calculate the sum of all values across all channels (the result",
"// will be proportional to the average volume of a sample)",
"var",
"totalValue",
"=",
"0",
";",
"for",
"(",
"var",
"channel",
"=",
"0",
";",
"channel",
"<",
"format",
".",
"channels",
";",
"channel",
"++",
")",
"{",
"totalValue",
"+=",
"Math",
".",
"abs",
"(",
"data",
"[",
"offset",
"+",
"channel",
"]",
")",
";",
"}",
"// If this is the smallest average value thus far, set the split",
"// length such that the first packet ends with the current sample",
"if",
"(",
"totalValue",
"<=",
"minValue",
")",
"{",
"optimalSplitLength",
"=",
"offset",
"+",
"format",
".",
"channels",
";",
"minValue",
"=",
"totalValue",
";",
"}",
"}",
"// If packet is not split, return the supplied packet untouched",
"if",
"(",
"optimalSplitLength",
"===",
"data",
".",
"length",
")",
"return",
"[",
"data",
"]",
";",
"// Otherwise, split the packet into two new packets according to the",
"// calculated optimal split length",
"return",
"[",
"new",
"SampleArray",
"(",
"data",
".",
"buffer",
".",
"slice",
"(",
"0",
",",
"optimalSplitLength",
"*",
"format",
".",
"bytesPerSample",
")",
")",
",",
"new",
"SampleArray",
"(",
"data",
".",
"buffer",
".",
"slice",
"(",
"optimalSplitLength",
"*",
"format",
".",
"bytesPerSample",
")",
")",
"]",
";",
"}"
] |
Given a single packet of audio data, splits off an arbitrary length of
audio data from the beginning of that packet, returning the split result
as an array of two packets. The split location is determined through an
algorithm intended to minimize the liklihood of audible clicking between
packets. If no such split location is possible, an array containing only
the originally-provided audio packet is returned.
@private
@param {SampleArray} data
The audio packet to split.
@returns {SampleArray[]}
An array of audio packets containing the result of splitting the
provided audio packet. If splitting is possible, this array will
contain two packets. If splitting is not possible, this array will
contain only the originally-provided packet.
|
[
"Given",
"a",
"single",
"packet",
"of",
"audio",
"data",
"splits",
"off",
"an",
"arbitrary",
"length",
"of",
"audio",
"data",
"from",
"the",
"beginning",
"of",
"that",
"packet",
"returning",
"the",
"split",
"result",
"as",
"an",
"array",
"of",
"two",
"packets",
".",
"The",
"split",
"location",
"is",
"determined",
"through",
"an",
"algorithm",
"intended",
"to",
"minimize",
"the",
"liklihood",
"of",
"audible",
"clicking",
"between",
"packets",
".",
"If",
"no",
"such",
"split",
"location",
"is",
"possible",
"an",
"array",
"containing",
"only",
"the",
"originally",
"-",
"provided",
"audio",
"packet",
"is",
"returned",
"."
] |
71925794155ea3fc37d2a125adbca6f8be532887
|
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/AudioPlayer.js#L270-L318
|
36,297 |
ILLGrenoble/guacamole-common-js
|
src/AudioPlayer.js
|
toAudioBuffer
|
function toAudioBuffer(data) {
// Calculate total number of samples
var samples = data.length / format.channels;
// Determine exactly when packet CAN play
var packetTime = context.currentTime;
if (nextPacketTime < packetTime)
nextPacketTime = packetTime;
// Get audio buffer for specified format
var audioBuffer = context.createBuffer(format.channels, samples, format.rate);
// Convert each channel
for (var channel = 0; channel < format.channels; channel++) {
var audioData = audioBuffer.getChannelData(channel);
// Fill audio buffer with data for channel
var offset = channel;
for (var i = 0; i < samples; i++) {
audioData[i] = data[offset] / maxSampleValue;
offset += format.channels;
}
}
return audioBuffer;
}
|
javascript
|
function toAudioBuffer(data) {
// Calculate total number of samples
var samples = data.length / format.channels;
// Determine exactly when packet CAN play
var packetTime = context.currentTime;
if (nextPacketTime < packetTime)
nextPacketTime = packetTime;
// Get audio buffer for specified format
var audioBuffer = context.createBuffer(format.channels, samples, format.rate);
// Convert each channel
for (var channel = 0; channel < format.channels; channel++) {
var audioData = audioBuffer.getChannelData(channel);
// Fill audio buffer with data for channel
var offset = channel;
for (var i = 0; i < samples; i++) {
audioData[i] = data[offset] / maxSampleValue;
offset += format.channels;
}
}
return audioBuffer;
}
|
[
"function",
"toAudioBuffer",
"(",
"data",
")",
"{",
"// Calculate total number of samples",
"var",
"samples",
"=",
"data",
".",
"length",
"/",
"format",
".",
"channels",
";",
"// Determine exactly when packet CAN play",
"var",
"packetTime",
"=",
"context",
".",
"currentTime",
";",
"if",
"(",
"nextPacketTime",
"<",
"packetTime",
")",
"nextPacketTime",
"=",
"packetTime",
";",
"// Get audio buffer for specified format",
"var",
"audioBuffer",
"=",
"context",
".",
"createBuffer",
"(",
"format",
".",
"channels",
",",
"samples",
",",
"format",
".",
"rate",
")",
";",
"// Convert each channel",
"for",
"(",
"var",
"channel",
"=",
"0",
";",
"channel",
"<",
"format",
".",
"channels",
";",
"channel",
"++",
")",
"{",
"var",
"audioData",
"=",
"audioBuffer",
".",
"getChannelData",
"(",
"channel",
")",
";",
"// Fill audio buffer with data for channel",
"var",
"offset",
"=",
"channel",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"samples",
";",
"i",
"++",
")",
"{",
"audioData",
"[",
"i",
"]",
"=",
"data",
"[",
"offset",
"]",
"/",
"maxSampleValue",
";",
"offset",
"+=",
"format",
".",
"channels",
";",
"}",
"}",
"return",
"audioBuffer",
";",
"}"
] |
Converts the given audio packet into an AudioBuffer, ready for playback
by the Web Audio API. Unlike the raw audio packets received by this
audio player, AudioBuffers require floating point samples and are split
into isolated planes of channel-specific data.
@private
@param {SampleArray} data
The raw audio packet that should be converted into a Web Audio API
AudioBuffer.
@returns {AudioBuffer}
A new Web Audio API AudioBuffer containing the provided audio data,
converted to the format used by the Web Audio API.
|
[
"Converts",
"the",
"given",
"audio",
"packet",
"into",
"an",
"AudioBuffer",
"ready",
"for",
"playback",
"by",
"the",
"Web",
"Audio",
"API",
".",
"Unlike",
"the",
"raw",
"audio",
"packets",
"received",
"by",
"this",
"audio",
"player",
"AudioBuffers",
"require",
"floating",
"point",
"samples",
"and",
"are",
"split",
"into",
"isolated",
"planes",
"of",
"channel",
"-",
"specific",
"data",
"."
] |
71925794155ea3fc37d2a125adbca6f8be532887
|
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/AudioPlayer.js#L378-L407
|
36,298 |
kibertoad/objection-swagger
|
lib/enrichers/schema.relationships.enricher.js
|
enrichSchemaWithRelationships
|
function enrichSchemaWithRelationships(
schema,
relationships,
isIncludeParentRelationships,
fromModelClass
) {
const processedSchema = _.cloneDeep(schema);
_.forOwn(relationships, (value, key) => {
let relationshipValue;
if (value.relation.name === constants.HasOneRelation) {
//protect from endless recursion
const modelProperties =
value.modelClass !== fromModelClass
? _resolveModelProperties(
value.modelClass,
true,
isIncludeParentRelationships
)
: { type: "object" };
relationshipValue = {
...modelProperties
};
} else if (
isIncludeParentRelationships &&
value.relation.name === constants.BelongsToOneRelation
) {
//protect from endless recursion
const modelProperties =
value.modelClass !== fromModelClass
? _resolveModelProperties(
value.modelClass,
false,
isIncludeParentRelationships
)
: { type: "object" };
relationshipValue = {
...modelProperties
};
} else if (value.relation.name === constants.HasManyRelation) {
//protect from endless recursion
const modelProperties =
value.modelClass !== fromModelClass
? _resolveModelProperties(
value.modelClass,
true,
isIncludeParentRelationships
)
: { type: "object" };
relationshipValue = {
type: "array",
items: {
...modelProperties
}
};
} else if (
isIncludeParentRelationships &&
value.relation.name === constants.ManyToManyRelation
) {
//protect from endless recursion
const modelProperties =
value.modelClass !== fromModelClass
? _resolveModelProperties(
value.modelClass,
false,
isIncludeParentRelationships
)
: { type: "object" };
relationshipValue = {
type: "array",
items: {
...modelProperties
}
};
}
if (relationshipValue) {
processedSchema.properties[key] = relationshipValue;
}
});
return processedSchema;
}
|
javascript
|
function enrichSchemaWithRelationships(
schema,
relationships,
isIncludeParentRelationships,
fromModelClass
) {
const processedSchema = _.cloneDeep(schema);
_.forOwn(relationships, (value, key) => {
let relationshipValue;
if (value.relation.name === constants.HasOneRelation) {
//protect from endless recursion
const modelProperties =
value.modelClass !== fromModelClass
? _resolveModelProperties(
value.modelClass,
true,
isIncludeParentRelationships
)
: { type: "object" };
relationshipValue = {
...modelProperties
};
} else if (
isIncludeParentRelationships &&
value.relation.name === constants.BelongsToOneRelation
) {
//protect from endless recursion
const modelProperties =
value.modelClass !== fromModelClass
? _resolveModelProperties(
value.modelClass,
false,
isIncludeParentRelationships
)
: { type: "object" };
relationshipValue = {
...modelProperties
};
} else if (value.relation.name === constants.HasManyRelation) {
//protect from endless recursion
const modelProperties =
value.modelClass !== fromModelClass
? _resolveModelProperties(
value.modelClass,
true,
isIncludeParentRelationships
)
: { type: "object" };
relationshipValue = {
type: "array",
items: {
...modelProperties
}
};
} else if (
isIncludeParentRelationships &&
value.relation.name === constants.ManyToManyRelation
) {
//protect from endless recursion
const modelProperties =
value.modelClass !== fromModelClass
? _resolveModelProperties(
value.modelClass,
false,
isIncludeParentRelationships
)
: { type: "object" };
relationshipValue = {
type: "array",
items: {
...modelProperties
}
};
}
if (relationshipValue) {
processedSchema.properties[key] = relationshipValue;
}
});
return processedSchema;
}
|
[
"function",
"enrichSchemaWithRelationships",
"(",
"schema",
",",
"relationships",
",",
"isIncludeParentRelationships",
",",
"fromModelClass",
")",
"{",
"const",
"processedSchema",
"=",
"_",
".",
"cloneDeep",
"(",
"schema",
")",
";",
"_",
".",
"forOwn",
"(",
"relationships",
",",
"(",
"value",
",",
"key",
")",
"=>",
"{",
"let",
"relationshipValue",
";",
"if",
"(",
"value",
".",
"relation",
".",
"name",
"===",
"constants",
".",
"HasOneRelation",
")",
"{",
"//protect from endless recursion",
"const",
"modelProperties",
"=",
"value",
".",
"modelClass",
"!==",
"fromModelClass",
"?",
"_resolveModelProperties",
"(",
"value",
".",
"modelClass",
",",
"true",
",",
"isIncludeParentRelationships",
")",
":",
"{",
"type",
":",
"\"object\"",
"}",
";",
"relationshipValue",
"=",
"{",
"...",
"modelProperties",
"}",
";",
"}",
"else",
"if",
"(",
"isIncludeParentRelationships",
"&&",
"value",
".",
"relation",
".",
"name",
"===",
"constants",
".",
"BelongsToOneRelation",
")",
"{",
"//protect from endless recursion",
"const",
"modelProperties",
"=",
"value",
".",
"modelClass",
"!==",
"fromModelClass",
"?",
"_resolveModelProperties",
"(",
"value",
".",
"modelClass",
",",
"false",
",",
"isIncludeParentRelationships",
")",
":",
"{",
"type",
":",
"\"object\"",
"}",
";",
"relationshipValue",
"=",
"{",
"...",
"modelProperties",
"}",
";",
"}",
"else",
"if",
"(",
"value",
".",
"relation",
".",
"name",
"===",
"constants",
".",
"HasManyRelation",
")",
"{",
"//protect from endless recursion",
"const",
"modelProperties",
"=",
"value",
".",
"modelClass",
"!==",
"fromModelClass",
"?",
"_resolveModelProperties",
"(",
"value",
".",
"modelClass",
",",
"true",
",",
"isIncludeParentRelationships",
")",
":",
"{",
"type",
":",
"\"object\"",
"}",
";",
"relationshipValue",
"=",
"{",
"type",
":",
"\"array\"",
",",
"items",
":",
"{",
"...",
"modelProperties",
"}",
"}",
";",
"}",
"else",
"if",
"(",
"isIncludeParentRelationships",
"&&",
"value",
".",
"relation",
".",
"name",
"===",
"constants",
".",
"ManyToManyRelation",
")",
"{",
"//protect from endless recursion",
"const",
"modelProperties",
"=",
"value",
".",
"modelClass",
"!==",
"fromModelClass",
"?",
"_resolveModelProperties",
"(",
"value",
".",
"modelClass",
",",
"false",
",",
"isIncludeParentRelationships",
")",
":",
"{",
"type",
":",
"\"object\"",
"}",
";",
"relationshipValue",
"=",
"{",
"type",
":",
"\"array\"",
",",
"items",
":",
"{",
"...",
"modelProperties",
"}",
"}",
";",
"}",
"if",
"(",
"relationshipValue",
")",
"{",
"processedSchema",
".",
"properties",
"[",
"key",
"]",
"=",
"relationshipValue",
";",
"}",
"}",
")",
";",
"return",
"processedSchema",
";",
"}"
] |
Creates copy of provided schema and enriches it with attributes that are derived from relationships
@param {Object} schema - JSON Schema
@param {Object} relationships - Objection.js relationMappings
@param {boolean} isIncludeParentRelationships - whether ManyToManyRelation and BelongsToOneRelation relationships should be included
@param {Object} [fromModelClass] - model class from which enrichment was initiated
@returns {Object} JSON Schema object
|
[
"Creates",
"copy",
"of",
"provided",
"schema",
"and",
"enriches",
"it",
"with",
"attributes",
"that",
"are",
"derived",
"from",
"relationships"
] |
2109b58ce323e78252729a46bcc94e617035b541
|
https://github.com/kibertoad/objection-swagger/blob/2109b58ce323e78252729a46bcc94e617035b541/lib/enrichers/schema.relationships.enricher.js#L12-L93
|
36,299 |
aMarCruz/jspreproc
|
spec/uglify/core.js
|
mktag
|
function mktag(name, html, css, attrs, js, pcex) {
var
c = ', ',
s = '}' + (pcex.length ? ', ' + q(pcex._bp[8]) : '') + ');'
// give more consistency to the output
if (js && js.slice(-1) !== '\n') s = '\n' + s
return 'riot.tag2(\'' + name + "'" + c + q(html) + c + q(css) + c + q(attrs) +
', function(opts) {\n' + js + s
}
|
javascript
|
function mktag(name, html, css, attrs, js, pcex) {
var
c = ', ',
s = '}' + (pcex.length ? ', ' + q(pcex._bp[8]) : '') + ');'
// give more consistency to the output
if (js && js.slice(-1) !== '\n') s = '\n' + s
return 'riot.tag2(\'' + name + "'" + c + q(html) + c + q(css) + c + q(attrs) +
', function(opts) {\n' + js + s
}
|
[
"function",
"mktag",
"(",
"name",
",",
"html",
",",
"css",
",",
"attrs",
",",
"js",
",",
"pcex",
")",
"{",
"var",
"c",
"=",
"', '",
",",
"s",
"=",
"'}'",
"+",
"(",
"pcex",
".",
"length",
"?",
"', '",
"+",
"q",
"(",
"pcex",
".",
"_bp",
"[",
"8",
"]",
")",
":",
"''",
")",
"+",
"');'",
"// give more consistency to the output",
"if",
"(",
"js",
"&&",
"js",
".",
"slice",
"(",
"-",
"1",
")",
"!==",
"'\\n'",
")",
"s",
"=",
"'\\n'",
"+",
"s",
"return",
"'riot.tag2(\\''",
"+",
"name",
"+",
"\"'\"",
"+",
"c",
"+",
"q",
"(",
"html",
")",
"+",
"c",
"+",
"q",
"(",
"css",
")",
"+",
"c",
"+",
"q",
"(",
"attrs",
")",
"+",
"', function(opts) {\\n'",
"+",
"js",
"+",
"s",
"}"
] |
Generates the `riot.tag2` call with the processed parts.
|
[
"Generates",
"the",
"riot",
".",
"tag2",
"call",
"with",
"the",
"processed",
"parts",
"."
] |
5f31820d702a329e8aa25f0f3983f13097610250
|
https://github.com/aMarCruz/jspreproc/blob/5f31820d702a329e8aa25f0f3983f13097610250/spec/uglify/core.js#L57-L67
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.