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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
19,800
|
wilzbach/msa
|
src/g/zoomer.js
|
function(max) {
// TODO!
// make seqlogo height configurable
var val = this.getMaxAlignmentHeight();
if (max !== undefined && max > 0) {
val = Math.min(val, max);
}
return this.set("alignmentHeight", val);
}
|
javascript
|
function(max) {
// TODO!
// make seqlogo height configurable
var val = this.getMaxAlignmentHeight();
if (max !== undefined && max > 0) {
val = Math.min(val, max);
}
return this.set("alignmentHeight", val);
}
|
[
"function",
"(",
"max",
")",
"{",
"// TODO!",
"// make seqlogo height configurable",
"var",
"val",
"=",
"this",
".",
"getMaxAlignmentHeight",
"(",
")",
";",
"if",
"(",
"max",
"!==",
"undefined",
"&&",
"max",
">",
"0",
")",
"{",
"val",
"=",
"Math",
".",
"min",
"(",
"val",
",",
"max",
")",
";",
"}",
"return",
"this",
".",
"set",
"(",
"\"alignmentHeight\"",
",",
"val",
")",
";",
"}"
] |
max is the maximal allowed height
|
[
"max",
"is",
"the",
"maximal",
"allowed",
"height"
] |
47042e8c3574fb62fad3b94de04183e5a0b09a97
|
https://github.com/wilzbach/msa/blob/47042e8c3574fb62fad3b94de04183e5a0b09a97/src/g/zoomer.js#L161-L170
|
|
19,801
|
izolate/html2pug
|
src/cli.js
|
main
|
async function main({ isFragment, needsHelp, showVersion, useTabs }) {
/* eslint-disable no-console */
const stdin = await getStdin()
if (showVersion) {
return console.log(version)
}
if (needsHelp || !stdin) {
return console.log(help)
}
const pug = html2pug(stdin, { isFragment, useTabs })
return console.log(pug)
/* eslint-enable no-console */
}
|
javascript
|
async function main({ isFragment, needsHelp, showVersion, useTabs }) {
/* eslint-disable no-console */
const stdin = await getStdin()
if (showVersion) {
return console.log(version)
}
if (needsHelp || !stdin) {
return console.log(help)
}
const pug = html2pug(stdin, { isFragment, useTabs })
return console.log(pug)
/* eslint-enable no-console */
}
|
[
"async",
"function",
"main",
"(",
"{",
"isFragment",
",",
"needsHelp",
",",
"showVersion",
",",
"useTabs",
"}",
")",
"{",
"/* eslint-disable no-console */",
"const",
"stdin",
"=",
"await",
"getStdin",
"(",
")",
"if",
"(",
"showVersion",
")",
"{",
"return",
"console",
".",
"log",
"(",
"version",
")",
"}",
"if",
"(",
"needsHelp",
"||",
"!",
"stdin",
")",
"{",
"return",
"console",
".",
"log",
"(",
"help",
")",
"}",
"const",
"pug",
"=",
"html2pug",
"(",
"stdin",
",",
"{",
"isFragment",
",",
"useTabs",
"}",
")",
"return",
"console",
".",
"log",
"(",
"pug",
")",
"/* eslint-enable no-console */",
"}"
] |
Convert HTML from stdin to Pug
|
[
"Convert",
"HTML",
"from",
"stdin",
"to",
"Pug"
] |
79157c8fa1f7d2f4690a90dbccec8ae0efe6c8f9
|
https://github.com/izolate/html2pug/blob/79157c8fa1f7d2f4690a90dbccec8ae0efe6c8f9/src/cli.js#L28-L44
|
19,802
|
rmariuzzo/laravel-localization-loader
|
index.js
|
laravelLocalizationLoader
|
function laravelLocalizationLoader(source) {
var isPHP = ~source.indexOf('<?php')
if (isPHP) {
return phpArrayLoader(source)
} else {
return jsonLoader(source)
}
}
|
javascript
|
function laravelLocalizationLoader(source) {
var isPHP = ~source.indexOf('<?php')
if (isPHP) {
return phpArrayLoader(source)
} else {
return jsonLoader(source)
}
}
|
[
"function",
"laravelLocalizationLoader",
"(",
"source",
")",
"{",
"var",
"isPHP",
"=",
"~",
"source",
".",
"indexOf",
"(",
"'<?php'",
")",
"if",
"(",
"isPHP",
")",
"{",
"return",
"phpArrayLoader",
"(",
"source",
")",
"}",
"else",
"{",
"return",
"jsonLoader",
"(",
"source",
")",
"}",
"}"
] |
The Laravel Localization loader.
@param {string} source The source contents.
@return {string} The parsed contents.
|
[
"The",
"Laravel",
"Localization",
"loader",
"."
] |
0ae7f411ec7c7d5816f2e035d51cb0f443677693
|
https://github.com/rmariuzzo/laravel-localization-loader/blob/0ae7f411ec7c7d5816f2e035d51cb0f443677693/index.js#L23-L31
|
19,803
|
Charmatzis/react-leaflet-google
|
src/leaflet.google.js
|
createTile
|
function createTile(coords, done) {
let key = this._tileCoordsToKey(coords);
// console.log('Need:', key);
if ( key in this._freshTiles ) {
let tile = this._freshTiles[ key ].pop();
if ( !this._freshTiles[ key ].length ) {
delete this._freshTiles[ key ];
}
L.Util.requestAnimFrame(done);
// console.log('Got ', key, ' from _freshTiles');
return tile;
}
let tileContainer = L.DomUtil.create("div");
this._tileCallbacks[ key ] = this._tileCallbacks[ key ] || [];
this._tileCallbacks[ key ].push(
(function(c /* , k*/) {
return function(imgNode) {
let parent = imgNode.parentNode;
if ( parent ) {
parent.removeChild(imgNode);
parent.removeChild = L.Util.falseFn;
// imgNode.parentNode.replaceChild(L.DomUtil.create('img'), imgNode);
}
c.appendChild(imgNode);
done();
// console.log('Sent ', k, ' to _tileCallbacks');
};
})(tileContainer /* , key*/)
);
return tileContainer;
}
|
javascript
|
function createTile(coords, done) {
let key = this._tileCoordsToKey(coords);
// console.log('Need:', key);
if ( key in this._freshTiles ) {
let tile = this._freshTiles[ key ].pop();
if ( !this._freshTiles[ key ].length ) {
delete this._freshTiles[ key ];
}
L.Util.requestAnimFrame(done);
// console.log('Got ', key, ' from _freshTiles');
return tile;
}
let tileContainer = L.DomUtil.create("div");
this._tileCallbacks[ key ] = this._tileCallbacks[ key ] || [];
this._tileCallbacks[ key ].push(
(function(c /* , k*/) {
return function(imgNode) {
let parent = imgNode.parentNode;
if ( parent ) {
parent.removeChild(imgNode);
parent.removeChild = L.Util.falseFn;
// imgNode.parentNode.replaceChild(L.DomUtil.create('img'), imgNode);
}
c.appendChild(imgNode);
done();
// console.log('Sent ', k, ' to _tileCallbacks');
};
})(tileContainer /* , key*/)
);
return tileContainer;
}
|
[
"function",
"createTile",
"(",
"coords",
",",
"done",
")",
"{",
"let",
"key",
"=",
"this",
".",
"_tileCoordsToKey",
"(",
"coords",
")",
";",
"// console.log('Need:', key);",
"if",
"(",
"key",
"in",
"this",
".",
"_freshTiles",
")",
"{",
"let",
"tile",
"=",
"this",
".",
"_freshTiles",
"[",
"key",
"]",
".",
"pop",
"(",
")",
";",
"if",
"(",
"!",
"this",
".",
"_freshTiles",
"[",
"key",
"]",
".",
"length",
")",
"{",
"delete",
"this",
".",
"_freshTiles",
"[",
"key",
"]",
";",
"}",
"L",
".",
"Util",
".",
"requestAnimFrame",
"(",
"done",
")",
";",
"// \t\t\tconsole.log('Got ', key, ' from _freshTiles');",
"return",
"tile",
";",
"}",
"let",
"tileContainer",
"=",
"L",
".",
"DomUtil",
".",
"create",
"(",
"\"div\"",
")",
";",
"this",
".",
"_tileCallbacks",
"[",
"key",
"]",
"=",
"this",
".",
"_tileCallbacks",
"[",
"key",
"]",
"||",
"[",
"]",
";",
"this",
".",
"_tileCallbacks",
"[",
"key",
"]",
".",
"push",
"(",
"(",
"function",
"(",
"c",
"/* , k*/",
")",
"{",
"return",
"function",
"(",
"imgNode",
")",
"{",
"let",
"parent",
"=",
"imgNode",
".",
"parentNode",
";",
"if",
"(",
"parent",
")",
"{",
"parent",
".",
"removeChild",
"(",
"imgNode",
")",
";",
"parent",
".",
"removeChild",
"=",
"L",
".",
"Util",
".",
"falseFn",
";",
"// \t\t\t\t\t\timgNode.parentNode.replaceChild(L.DomUtil.create('img'), imgNode);",
"}",
"c",
".",
"appendChild",
"(",
"imgNode",
")",
";",
"done",
"(",
")",
";",
"// \t\t\t\t\tconsole.log('Sent ', k, ' to _tileCallbacks');",
"}",
";",
"}",
")",
"(",
"tileContainer",
"/* , key*/",
")",
")",
";",
"return",
"tileContainer",
";",
"}"
] |
This will be used as this.createTile for 'roadmap', 'sat', 'terrain'
|
[
"This",
"will",
"be",
"used",
"as",
"this",
".",
"createTile",
"for",
"roadmap",
"sat",
"terrain"
] |
4ac149142ac0d44e19855785d7b1e665d8e454a2
|
https://github.com/Charmatzis/react-leaflet-google/blob/4ac149142ac0d44e19855785d7b1e665d8e454a2/src/leaflet.google.js#L291-L323
|
19,804
|
Charmatzis/react-leaflet-google
|
src/leaflet.google.js
|
createTile
|
function createTile(coords, done) {
let key = this._tileCoordsToKey(coords);
let tileContainer = L.DomUtil.create("div");
tileContainer.dataset.pending = this._imagesPerTile;
for ( let i = 0; i < this._imagesPerTile; i++ ) {
let key2 = key + "/" + i;
if ( key2 in this._freshTiles ) {
tileContainer.appendChild(this._freshTiles[ key2 ].pop());
if ( !this._freshTiles[ key2 ].length ) {
delete this._freshTiles[ key2 ];
}
tileContainer.dataset.pending--;
// console.log('Got ', key2, ' from _freshTiles');
} else {
this._tileCallbacks[ key2 ] = this._tileCallbacks[ key2 ] || [];
this._tileCallbacks[ key2 ].push(
(function(c /* , k2*/) {
return function(imgNode) {
let parent = imgNode.parentNode;
if ( parent ) {
parent.removeChild(imgNode);
parent.removeChild = L.Util.falseFn;
// imgNode.parentNode.replaceChild(L.DomUtil.create('img'), imgNode);
}
c.appendChild(imgNode);
c.dataset.pending--;
if ( !parseInt(c.dataset.pending) ) {
done();
}
// console.log('Sent ', k2, ' to _tileCallbacks, still ', c.dataset.pending, ' images to go');
};
})(tileContainer /* , key2*/)
);
}
}
if ( !parseInt(tileContainer.dataset.pending) ) {
L.Util.requestAnimFrame(done);
}
return tileContainer;
}
|
javascript
|
function createTile(coords, done) {
let key = this._tileCoordsToKey(coords);
let tileContainer = L.DomUtil.create("div");
tileContainer.dataset.pending = this._imagesPerTile;
for ( let i = 0; i < this._imagesPerTile; i++ ) {
let key2 = key + "/" + i;
if ( key2 in this._freshTiles ) {
tileContainer.appendChild(this._freshTiles[ key2 ].pop());
if ( !this._freshTiles[ key2 ].length ) {
delete this._freshTiles[ key2 ];
}
tileContainer.dataset.pending--;
// console.log('Got ', key2, ' from _freshTiles');
} else {
this._tileCallbacks[ key2 ] = this._tileCallbacks[ key2 ] || [];
this._tileCallbacks[ key2 ].push(
(function(c /* , k2*/) {
return function(imgNode) {
let parent = imgNode.parentNode;
if ( parent ) {
parent.removeChild(imgNode);
parent.removeChild = L.Util.falseFn;
// imgNode.parentNode.replaceChild(L.DomUtil.create('img'), imgNode);
}
c.appendChild(imgNode);
c.dataset.pending--;
if ( !parseInt(c.dataset.pending) ) {
done();
}
// console.log('Sent ', k2, ' to _tileCallbacks, still ', c.dataset.pending, ' images to go');
};
})(tileContainer /* , key2*/)
);
}
}
if ( !parseInt(tileContainer.dataset.pending) ) {
L.Util.requestAnimFrame(done);
}
return tileContainer;
}
|
[
"function",
"createTile",
"(",
"coords",
",",
"done",
")",
"{",
"let",
"key",
"=",
"this",
".",
"_tileCoordsToKey",
"(",
"coords",
")",
";",
"let",
"tileContainer",
"=",
"L",
".",
"DomUtil",
".",
"create",
"(",
"\"div\"",
")",
";",
"tileContainer",
".",
"dataset",
".",
"pending",
"=",
"this",
".",
"_imagesPerTile",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"_imagesPerTile",
";",
"i",
"++",
")",
"{",
"let",
"key2",
"=",
"key",
"+",
"\"/\"",
"+",
"i",
";",
"if",
"(",
"key2",
"in",
"this",
".",
"_freshTiles",
")",
"{",
"tileContainer",
".",
"appendChild",
"(",
"this",
".",
"_freshTiles",
"[",
"key2",
"]",
".",
"pop",
"(",
")",
")",
";",
"if",
"(",
"!",
"this",
".",
"_freshTiles",
"[",
"key2",
"]",
".",
"length",
")",
"{",
"delete",
"this",
".",
"_freshTiles",
"[",
"key2",
"]",
";",
"}",
"tileContainer",
".",
"dataset",
".",
"pending",
"--",
";",
"// \t\t\t\tconsole.log('Got ', key2, ' from _freshTiles');",
"}",
"else",
"{",
"this",
".",
"_tileCallbacks",
"[",
"key2",
"]",
"=",
"this",
".",
"_tileCallbacks",
"[",
"key2",
"]",
"||",
"[",
"]",
";",
"this",
".",
"_tileCallbacks",
"[",
"key2",
"]",
".",
"push",
"(",
"(",
"function",
"(",
"c",
"/* , k2*/",
")",
"{",
"return",
"function",
"(",
"imgNode",
")",
"{",
"let",
"parent",
"=",
"imgNode",
".",
"parentNode",
";",
"if",
"(",
"parent",
")",
"{",
"parent",
".",
"removeChild",
"(",
"imgNode",
")",
";",
"parent",
".",
"removeChild",
"=",
"L",
".",
"Util",
".",
"falseFn",
";",
"// \t\t\t\t\t\t\timgNode.parentNode.replaceChild(L.DomUtil.create('img'), imgNode);",
"}",
"c",
".",
"appendChild",
"(",
"imgNode",
")",
";",
"c",
".",
"dataset",
".",
"pending",
"--",
";",
"if",
"(",
"!",
"parseInt",
"(",
"c",
".",
"dataset",
".",
"pending",
")",
")",
"{",
"done",
"(",
")",
";",
"}",
"// \t\t\t\t\t\tconsole.log('Sent ', k2, ' to _tileCallbacks, still ', c.dataset.pending, ' images to go');",
"}",
";",
"}",
")",
"(",
"tileContainer",
"/* , key2*/",
")",
")",
";",
"}",
"}",
"if",
"(",
"!",
"parseInt",
"(",
"tileContainer",
".",
"dataset",
".",
"pending",
")",
")",
"{",
"L",
".",
"Util",
".",
"requestAnimFrame",
"(",
"done",
")",
";",
"}",
"return",
"tileContainer",
";",
"}"
] |
This will be used as this.createTile for 'hybrid'
|
[
"This",
"will",
"be",
"used",
"as",
"this",
".",
"createTile",
"for",
"hybrid"
] |
4ac149142ac0d44e19855785d7b1e665d8e454a2
|
https://github.com/Charmatzis/react-leaflet-google/blob/4ac149142ac0d44e19855785d7b1e665d8e454a2/src/leaflet.google.js#L326-L368
|
19,805
|
mongodb-js/kerberos
|
lib/auth_processes/mongodb.js
|
performGssapiCanonicalizeHostName
|
function performGssapiCanonicalizeHostName(canonicalizeHostName, host, callback) {
if (!canonicalizeHostName) return callback();
// Attempt to resolve the host name
dns.resolveCname(host, (err, r) => {
if (err) return callback(err);
// Get the first resolve host id
if (Array.isArray(r) && r.length > 0) {
self.host = r[0];
}
callback();
});
}
|
javascript
|
function performGssapiCanonicalizeHostName(canonicalizeHostName, host, callback) {
if (!canonicalizeHostName) return callback();
// Attempt to resolve the host name
dns.resolveCname(host, (err, r) => {
if (err) return callback(err);
// Get the first resolve host id
if (Array.isArray(r) && r.length > 0) {
self.host = r[0];
}
callback();
});
}
|
[
"function",
"performGssapiCanonicalizeHostName",
"(",
"canonicalizeHostName",
",",
"host",
",",
"callback",
")",
"{",
"if",
"(",
"!",
"canonicalizeHostName",
")",
"return",
"callback",
"(",
")",
";",
"// Attempt to resolve the host name",
"dns",
".",
"resolveCname",
"(",
"host",
",",
"(",
"err",
",",
"r",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"return",
"callback",
"(",
"err",
")",
";",
"// Get the first resolve host id",
"if",
"(",
"Array",
".",
"isArray",
"(",
"r",
")",
"&&",
"r",
".",
"length",
">",
"0",
")",
"{",
"self",
".",
"host",
"=",
"r",
"[",
"0",
"]",
";",
"}",
"callback",
"(",
")",
";",
"}",
")",
";",
"}"
] |
Canonicialize host name if needed
|
[
"Canonicialize",
"host",
"name",
"if",
"needed"
] |
28fd17bf10ca29cf11650eb0165af1e07c19cab8
|
https://github.com/mongodb-js/kerberos/blob/28fd17bf10ca29cf11650eb0165af1e07c19cab8/lib/auth_processes/mongodb.js#L33-L47
|
19,806
|
mongodb-js/kerberos
|
lib/util.js
|
defineOperation
|
function defineOperation(fn, paramDefs) {
return function() {
const args = Array.prototype.slice.call(arguments);
const params = [];
for (let i = 0, argIdx = 0; i < paramDefs.length; ++i, ++argIdx) {
const def = paramDefs[i];
let arg = args[argIdx];
if (def.hasOwnProperty('default') && arg == null) arg = def.default;
if (def.type === 'object' && def.default != null) {
arg = Object.assign({}, def.default, arg);
}
// special case to allow `options` to be optional
if (def.name === 'options' && (typeof arg === 'function' || arg == null)) {
arg = {};
}
if (validateParameter(arg, paramDefs, i)) {
params.push(arg);
} else {
argIdx--;
}
}
const callback = arguments[arguments.length - 1];
if (typeof callback !== 'function') {
return new Promise((resolve, reject) => {
params.push((err, response) => {
if (err) return reject(err);
resolve(response);
});
fn.apply(this, params);
});
}
fn.apply(this, params);
};
}
|
javascript
|
function defineOperation(fn, paramDefs) {
return function() {
const args = Array.prototype.slice.call(arguments);
const params = [];
for (let i = 0, argIdx = 0; i < paramDefs.length; ++i, ++argIdx) {
const def = paramDefs[i];
let arg = args[argIdx];
if (def.hasOwnProperty('default') && arg == null) arg = def.default;
if (def.type === 'object' && def.default != null) {
arg = Object.assign({}, def.default, arg);
}
// special case to allow `options` to be optional
if (def.name === 'options' && (typeof arg === 'function' || arg == null)) {
arg = {};
}
if (validateParameter(arg, paramDefs, i)) {
params.push(arg);
} else {
argIdx--;
}
}
const callback = arguments[arguments.length - 1];
if (typeof callback !== 'function') {
return new Promise((resolve, reject) => {
params.push((err, response) => {
if (err) return reject(err);
resolve(response);
});
fn.apply(this, params);
});
}
fn.apply(this, params);
};
}
|
[
"function",
"defineOperation",
"(",
"fn",
",",
"paramDefs",
")",
"{",
"return",
"function",
"(",
")",
"{",
"const",
"args",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
")",
";",
"const",
"params",
"=",
"[",
"]",
";",
"for",
"(",
"let",
"i",
"=",
"0",
",",
"argIdx",
"=",
"0",
";",
"i",
"<",
"paramDefs",
".",
"length",
";",
"++",
"i",
",",
"++",
"argIdx",
")",
"{",
"const",
"def",
"=",
"paramDefs",
"[",
"i",
"]",
";",
"let",
"arg",
"=",
"args",
"[",
"argIdx",
"]",
";",
"if",
"(",
"def",
".",
"hasOwnProperty",
"(",
"'default'",
")",
"&&",
"arg",
"==",
"null",
")",
"arg",
"=",
"def",
".",
"default",
";",
"if",
"(",
"def",
".",
"type",
"===",
"'object'",
"&&",
"def",
".",
"default",
"!=",
"null",
")",
"{",
"arg",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"def",
".",
"default",
",",
"arg",
")",
";",
"}",
"// special case to allow `options` to be optional",
"if",
"(",
"def",
".",
"name",
"===",
"'options'",
"&&",
"(",
"typeof",
"arg",
"===",
"'function'",
"||",
"arg",
"==",
"null",
")",
")",
"{",
"arg",
"=",
"{",
"}",
";",
"}",
"if",
"(",
"validateParameter",
"(",
"arg",
",",
"paramDefs",
",",
"i",
")",
")",
"{",
"params",
".",
"push",
"(",
"arg",
")",
";",
"}",
"else",
"{",
"argIdx",
"--",
";",
"}",
"}",
"const",
"callback",
"=",
"arguments",
"[",
"arguments",
".",
"length",
"-",
"1",
"]",
";",
"if",
"(",
"typeof",
"callback",
"!==",
"'function'",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"params",
".",
"push",
"(",
"(",
"err",
",",
"response",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"return",
"reject",
"(",
"err",
")",
";",
"resolve",
"(",
"response",
")",
";",
"}",
")",
";",
"fn",
".",
"apply",
"(",
"this",
",",
"params",
")",
";",
"}",
")",
";",
"}",
"fn",
".",
"apply",
"(",
"this",
",",
"params",
")",
";",
"}",
";",
"}"
] |
Monkey-patches an existing method to support parameter validation, as well
as adding support for returning Promises if callbacks are not provided.
@private
@param {function} fn the function to override
@param {Array<Object>} paramDefs the definitions of each parameter to the function
|
[
"Monkey",
"-",
"patches",
"an",
"existing",
"method",
"to",
"support",
"parameter",
"validation",
"as",
"well",
"as",
"adding",
"support",
"for",
"returning",
"Promises",
"if",
"callbacks",
"are",
"not",
"provided",
"."
] |
28fd17bf10ca29cf11650eb0165af1e07c19cab8
|
https://github.com/mongodb-js/kerberos/blob/28fd17bf10ca29cf11650eb0165af1e07c19cab8/lib/util.js#L39-L78
|
19,807
|
mapbox/decrypt-kms-env
|
index.js
|
decrypt
|
function decrypt(env, callback) {
if (!env.AWS_DEFAULT_REGION) return callback(new Error('AWS_DEFAULT_REGION env var must be set'));
var kms = new AWS.KMS({
region: env.AWS_DEFAULT_REGION,
maxRetries: 10
});
var q = queue();
for (var key in env) {
if (!(/^secure:/).test(env[key])) continue;
q.defer(function(key, val, done) {
kms.decrypt({
CiphertextBlob: new Buffer(val, 'base64')
}, function(err, data) {
if (err) return done(err);
done(null, { key: key, val: val, decrypted: (new Buffer(data.Plaintext, 'base64')).toString('utf8') });
});
}, key, env[key].replace(/^secure:/,''));
}
q.awaitAll(function(err, results) {
if (err) return callback(err);
callback(null, results);
});
}
|
javascript
|
function decrypt(env, callback) {
if (!env.AWS_DEFAULT_REGION) return callback(new Error('AWS_DEFAULT_REGION env var must be set'));
var kms = new AWS.KMS({
region: env.AWS_DEFAULT_REGION,
maxRetries: 10
});
var q = queue();
for (var key in env) {
if (!(/^secure:/).test(env[key])) continue;
q.defer(function(key, val, done) {
kms.decrypt({
CiphertextBlob: new Buffer(val, 'base64')
}, function(err, data) {
if (err) return done(err);
done(null, { key: key, val: val, decrypted: (new Buffer(data.Plaintext, 'base64')).toString('utf8') });
});
}, key, env[key].replace(/^secure:/,''));
}
q.awaitAll(function(err, results) {
if (err) return callback(err);
callback(null, results);
});
}
|
[
"function",
"decrypt",
"(",
"env",
",",
"callback",
")",
"{",
"if",
"(",
"!",
"env",
".",
"AWS_DEFAULT_REGION",
")",
"return",
"callback",
"(",
"new",
"Error",
"(",
"'AWS_DEFAULT_REGION env var must be set'",
")",
")",
";",
"var",
"kms",
"=",
"new",
"AWS",
".",
"KMS",
"(",
"{",
"region",
":",
"env",
".",
"AWS_DEFAULT_REGION",
",",
"maxRetries",
":",
"10",
"}",
")",
";",
"var",
"q",
"=",
"queue",
"(",
")",
";",
"for",
"(",
"var",
"key",
"in",
"env",
")",
"{",
"if",
"(",
"!",
"(",
"/",
"^secure:",
"/",
")",
".",
"test",
"(",
"env",
"[",
"key",
"]",
")",
")",
"continue",
";",
"q",
".",
"defer",
"(",
"function",
"(",
"key",
",",
"val",
",",
"done",
")",
"{",
"kms",
".",
"decrypt",
"(",
"{",
"CiphertextBlob",
":",
"new",
"Buffer",
"(",
"val",
",",
"'base64'",
")",
"}",
",",
"function",
"(",
"err",
",",
"data",
")",
"{",
"if",
"(",
"err",
")",
"return",
"done",
"(",
"err",
")",
";",
"done",
"(",
"null",
",",
"{",
"key",
":",
"key",
",",
"val",
":",
"val",
",",
"decrypted",
":",
"(",
"new",
"Buffer",
"(",
"data",
".",
"Plaintext",
",",
"'base64'",
")",
")",
".",
"toString",
"(",
"'utf8'",
")",
"}",
")",
";",
"}",
")",
";",
"}",
",",
"key",
",",
"env",
"[",
"key",
"]",
".",
"replace",
"(",
"/",
"^secure:",
"/",
",",
"''",
")",
")",
";",
"}",
"q",
".",
"awaitAll",
"(",
"function",
"(",
"err",
",",
"results",
")",
"{",
"if",
"(",
"err",
")",
"return",
"callback",
"(",
"err",
")",
";",
"callback",
"(",
"null",
",",
"results",
")",
";",
"}",
")",
";",
"}"
] |
Private decrypt function that does not scrub output. Not exposed as a public API.
@param {object} env Object with variables to decrypt.
@param {function} callback Callback function.
|
[
"Private",
"decrypt",
"function",
"that",
"does",
"not",
"scrub",
"output",
".",
"Not",
"exposed",
"as",
"a",
"public",
"API",
"."
] |
5debeeac04f064ebb311df94652bf6ab7e5dd89b
|
https://github.com/mapbox/decrypt-kms-env/blob/5debeeac04f064ebb311df94652bf6ab7e5dd89b/index.js#L47-L69
|
19,808
|
jensarps/IDBWrapper
|
example/lib/requirejs/require.js
|
configurePackageDir
|
function configurePackageDir(pkgs, currentPackages, dir) {
var i, location, pkgObj;
for (i = 0; (pkgObj = currentPackages[i]); i++) {
pkgObj = typeof pkgObj === "string" ? { name: pkgObj } : pkgObj;
location = pkgObj.location;
//Add dir to the path, but avoid paths that start with a slash
//or have a colon (indicates a protocol)
if (dir && (!location || (location.indexOf("/") !== 0 && location.indexOf(":") === -1))) {
location = dir + "/" + (location || pkgObj.name);
}
//Create a brand new object on pkgs, since currentPackages can
//be passed in again, and config.pkgs is the internal transformed
//state for all package configs.
pkgs[pkgObj.name] = {
name: pkgObj.name,
location: location || pkgObj.name,
//Remove leading dot in main, so main paths are normalized,
//and remove any trailing .js, since different package
//envs have different conventions: some use a module name,
//some use a file name.
main: (pkgObj.main || "main")
.replace(currDirRegExp, '')
.replace(jsSuffixRegExp, '')
};
}
}
|
javascript
|
function configurePackageDir(pkgs, currentPackages, dir) {
var i, location, pkgObj;
for (i = 0; (pkgObj = currentPackages[i]); i++) {
pkgObj = typeof pkgObj === "string" ? { name: pkgObj } : pkgObj;
location = pkgObj.location;
//Add dir to the path, but avoid paths that start with a slash
//or have a colon (indicates a protocol)
if (dir && (!location || (location.indexOf("/") !== 0 && location.indexOf(":") === -1))) {
location = dir + "/" + (location || pkgObj.name);
}
//Create a brand new object on pkgs, since currentPackages can
//be passed in again, and config.pkgs is the internal transformed
//state for all package configs.
pkgs[pkgObj.name] = {
name: pkgObj.name,
location: location || pkgObj.name,
//Remove leading dot in main, so main paths are normalized,
//and remove any trailing .js, since different package
//envs have different conventions: some use a module name,
//some use a file name.
main: (pkgObj.main || "main")
.replace(currDirRegExp, '')
.replace(jsSuffixRegExp, '')
};
}
}
|
[
"function",
"configurePackageDir",
"(",
"pkgs",
",",
"currentPackages",
",",
"dir",
")",
"{",
"var",
"i",
",",
"location",
",",
"pkgObj",
";",
"for",
"(",
"i",
"=",
"0",
";",
"(",
"pkgObj",
"=",
"currentPackages",
"[",
"i",
"]",
")",
";",
"i",
"++",
")",
"{",
"pkgObj",
"=",
"typeof",
"pkgObj",
"===",
"\"string\"",
"?",
"{",
"name",
":",
"pkgObj",
"}",
":",
"pkgObj",
";",
"location",
"=",
"pkgObj",
".",
"location",
";",
"//Add dir to the path, but avoid paths that start with a slash",
"//or have a colon (indicates a protocol)",
"if",
"(",
"dir",
"&&",
"(",
"!",
"location",
"||",
"(",
"location",
".",
"indexOf",
"(",
"\"/\"",
")",
"!==",
"0",
"&&",
"location",
".",
"indexOf",
"(",
"\":\"",
")",
"===",
"-",
"1",
")",
")",
")",
"{",
"location",
"=",
"dir",
"+",
"\"/\"",
"+",
"(",
"location",
"||",
"pkgObj",
".",
"name",
")",
";",
"}",
"//Create a brand new object on pkgs, since currentPackages can",
"//be passed in again, and config.pkgs is the internal transformed",
"//state for all package configs.",
"pkgs",
"[",
"pkgObj",
".",
"name",
"]",
"=",
"{",
"name",
":",
"pkgObj",
".",
"name",
",",
"location",
":",
"location",
"||",
"pkgObj",
".",
"name",
",",
"//Remove leading dot in main, so main paths are normalized,",
"//and remove any trailing .js, since different package",
"//envs have different conventions: some use a module name,",
"//some use a file name.",
"main",
":",
"(",
"pkgObj",
".",
"main",
"||",
"\"main\"",
")",
".",
"replace",
"(",
"currDirRegExp",
",",
"''",
")",
".",
"replace",
"(",
"jsSuffixRegExp",
",",
"''",
")",
"}",
";",
"}",
"}"
] |
Used to set up package paths from a packagePaths or packages config object.
@param {Object} pkgs the object to store the new package config
@param {Array} currentPackages an array of packages to configure
@param {String} [dir] a prefix dir to use.
|
[
"Used",
"to",
"set",
"up",
"package",
"paths",
"from",
"a",
"packagePaths",
"or",
"packages",
"config",
"object",
"."
] |
f7e23b140506159ff926b19c6a526e51d87d1b93
|
https://github.com/jensarps/IDBWrapper/blob/f7e23b140506159ff926b19c6a526e51d87d1b93/example/lib/requirejs/require.js#L92-L120
|
19,809
|
jensarps/IDBWrapper
|
example/lib/requirejs/require.js
|
isPriorityDone
|
function isPriorityDone() {
var priorityDone = true,
priorityWait = config.priorityWait,
priorityName, i;
if (priorityWait) {
for (i = 0; (priorityName = priorityWait[i]); i++) {
if (!loaded[priorityName]) {
priorityDone = false;
break;
}
}
if (priorityDone) {
delete config.priorityWait;
}
}
return priorityDone;
}
|
javascript
|
function isPriorityDone() {
var priorityDone = true,
priorityWait = config.priorityWait,
priorityName, i;
if (priorityWait) {
for (i = 0; (priorityName = priorityWait[i]); i++) {
if (!loaded[priorityName]) {
priorityDone = false;
break;
}
}
if (priorityDone) {
delete config.priorityWait;
}
}
return priorityDone;
}
|
[
"function",
"isPriorityDone",
"(",
")",
"{",
"var",
"priorityDone",
"=",
"true",
",",
"priorityWait",
"=",
"config",
".",
"priorityWait",
",",
"priorityName",
",",
"i",
";",
"if",
"(",
"priorityWait",
")",
"{",
"for",
"(",
"i",
"=",
"0",
";",
"(",
"priorityName",
"=",
"priorityWait",
"[",
"i",
"]",
")",
";",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"loaded",
"[",
"priorityName",
"]",
")",
"{",
"priorityDone",
"=",
"false",
";",
"break",
";",
"}",
"}",
"if",
"(",
"priorityDone",
")",
"{",
"delete",
"config",
".",
"priorityWait",
";",
"}",
"}",
"return",
"priorityDone",
";",
"}"
] |
Determine if priority loading is done. If so clear the priorityWait
|
[
"Determine",
"if",
"priority",
"loading",
"is",
"done",
".",
"If",
"so",
"clear",
"the",
"priorityWait"
] |
f7e23b140506159ff926b19c6a526e51d87d1b93
|
https://github.com/jensarps/IDBWrapper/blob/f7e23b140506159ff926b19c6a526e51d87d1b93/example/lib/requirejs/require.js#L358-L374
|
19,810
|
jensarps/IDBWrapper
|
example/lib/requirejs/require.js
|
updateNormalizedNames
|
function updateNormalizedNames(pluginName) {
var oldFullName, oldModuleMap, moduleMap, fullName, callbacks,
i, j, k, depArray, existingCallbacks,
maps = normalizedWaiting[pluginName];
if (maps) {
for (i = 0; (oldModuleMap = maps[i]); i++) {
oldFullName = oldModuleMap.fullName;
moduleMap = makeModuleMap(oldModuleMap.originalName, oldModuleMap.parentMap);
fullName = moduleMap.fullName;
//Callbacks could be undefined if the same plugin!name was
//required twice in a row, so use empty array in that case.
callbacks = managerCallbacks[oldFullName] || [];
existingCallbacks = managerCallbacks[fullName];
if (fullName !== oldFullName) {
//Update the specified object, but only if it is already
//in there. In sync environments, it may not be yet.
if (oldFullName in specified) {
delete specified[oldFullName];
specified[fullName] = true;
}
//Update managerCallbacks to use the correct normalized name.
//If there are already callbacks for the normalized name,
//just add to them.
if (existingCallbacks) {
managerCallbacks[fullName] = existingCallbacks.concat(callbacks);
} else {
managerCallbacks[fullName] = callbacks;
}
delete managerCallbacks[oldFullName];
//In each manager callback, update the normalized name in the depArray.
for (j = 0; j < callbacks.length; j++) {
depArray = callbacks[j].depArray;
for (k = 0; k < depArray.length; k++) {
if (depArray[k] === oldFullName) {
depArray[k] = fullName;
}
}
}
}
}
}
delete normalizedWaiting[pluginName];
}
|
javascript
|
function updateNormalizedNames(pluginName) {
var oldFullName, oldModuleMap, moduleMap, fullName, callbacks,
i, j, k, depArray, existingCallbacks,
maps = normalizedWaiting[pluginName];
if (maps) {
for (i = 0; (oldModuleMap = maps[i]); i++) {
oldFullName = oldModuleMap.fullName;
moduleMap = makeModuleMap(oldModuleMap.originalName, oldModuleMap.parentMap);
fullName = moduleMap.fullName;
//Callbacks could be undefined if the same plugin!name was
//required twice in a row, so use empty array in that case.
callbacks = managerCallbacks[oldFullName] || [];
existingCallbacks = managerCallbacks[fullName];
if (fullName !== oldFullName) {
//Update the specified object, but only if it is already
//in there. In sync environments, it may not be yet.
if (oldFullName in specified) {
delete specified[oldFullName];
specified[fullName] = true;
}
//Update managerCallbacks to use the correct normalized name.
//If there are already callbacks for the normalized name,
//just add to them.
if (existingCallbacks) {
managerCallbacks[fullName] = existingCallbacks.concat(callbacks);
} else {
managerCallbacks[fullName] = callbacks;
}
delete managerCallbacks[oldFullName];
//In each manager callback, update the normalized name in the depArray.
for (j = 0; j < callbacks.length; j++) {
depArray = callbacks[j].depArray;
for (k = 0; k < depArray.length; k++) {
if (depArray[k] === oldFullName) {
depArray[k] = fullName;
}
}
}
}
}
}
delete normalizedWaiting[pluginName];
}
|
[
"function",
"updateNormalizedNames",
"(",
"pluginName",
")",
"{",
"var",
"oldFullName",
",",
"oldModuleMap",
",",
"moduleMap",
",",
"fullName",
",",
"callbacks",
",",
"i",
",",
"j",
",",
"k",
",",
"depArray",
",",
"existingCallbacks",
",",
"maps",
"=",
"normalizedWaiting",
"[",
"pluginName",
"]",
";",
"if",
"(",
"maps",
")",
"{",
"for",
"(",
"i",
"=",
"0",
";",
"(",
"oldModuleMap",
"=",
"maps",
"[",
"i",
"]",
")",
";",
"i",
"++",
")",
"{",
"oldFullName",
"=",
"oldModuleMap",
".",
"fullName",
";",
"moduleMap",
"=",
"makeModuleMap",
"(",
"oldModuleMap",
".",
"originalName",
",",
"oldModuleMap",
".",
"parentMap",
")",
";",
"fullName",
"=",
"moduleMap",
".",
"fullName",
";",
"//Callbacks could be undefined if the same plugin!name was",
"//required twice in a row, so use empty array in that case.",
"callbacks",
"=",
"managerCallbacks",
"[",
"oldFullName",
"]",
"||",
"[",
"]",
";",
"existingCallbacks",
"=",
"managerCallbacks",
"[",
"fullName",
"]",
";",
"if",
"(",
"fullName",
"!==",
"oldFullName",
")",
"{",
"//Update the specified object, but only if it is already",
"//in there. In sync environments, it may not be yet.",
"if",
"(",
"oldFullName",
"in",
"specified",
")",
"{",
"delete",
"specified",
"[",
"oldFullName",
"]",
";",
"specified",
"[",
"fullName",
"]",
"=",
"true",
";",
"}",
"//Update managerCallbacks to use the correct normalized name.",
"//If there are already callbacks for the normalized name,",
"//just add to them.",
"if",
"(",
"existingCallbacks",
")",
"{",
"managerCallbacks",
"[",
"fullName",
"]",
"=",
"existingCallbacks",
".",
"concat",
"(",
"callbacks",
")",
";",
"}",
"else",
"{",
"managerCallbacks",
"[",
"fullName",
"]",
"=",
"callbacks",
";",
"}",
"delete",
"managerCallbacks",
"[",
"oldFullName",
"]",
";",
"//In each manager callback, update the normalized name in the depArray.",
"for",
"(",
"j",
"=",
"0",
";",
"j",
"<",
"callbacks",
".",
"length",
";",
"j",
"++",
")",
"{",
"depArray",
"=",
"callbacks",
"[",
"j",
"]",
".",
"depArray",
";",
"for",
"(",
"k",
"=",
"0",
";",
"k",
"<",
"depArray",
".",
"length",
";",
"k",
"++",
")",
"{",
"if",
"(",
"depArray",
"[",
"k",
"]",
"===",
"oldFullName",
")",
"{",
"depArray",
"[",
"k",
"]",
"=",
"fullName",
";",
"}",
"}",
"}",
"}",
"}",
"}",
"delete",
"normalizedWaiting",
"[",
"pluginName",
"]",
";",
"}"
] |
Used to update the normalized name for plugin-based dependencies
after a plugin loads, since it can have its own normalization structure.
@param {String} pluginName the normalized plugin module name.
|
[
"Used",
"to",
"update",
"the",
"normalized",
"name",
"for",
"plugin",
"-",
"based",
"dependencies",
"after",
"a",
"plugin",
"loads",
"since",
"it",
"can",
"have",
"its",
"own",
"normalization",
"structure",
"."
] |
f7e23b140506159ff926b19c6a526e51d87d1b93
|
https://github.com/jensarps/IDBWrapper/blob/f7e23b140506159ff926b19c6a526e51d87d1b93/example/lib/requirejs/require.js#L431-L479
|
19,811
|
joaonuno/flat-to-nested-js
|
index.js
|
FlatToNested
|
function FlatToNested(config) {
this.config = config = config || {};
this.config.id = config.id || 'id';
this.config.parent = config.parent || 'parent';
this.config.children = config.children || 'children';
this.config.options = config.options || { deleteParent: true };
}
|
javascript
|
function FlatToNested(config) {
this.config = config = config || {};
this.config.id = config.id || 'id';
this.config.parent = config.parent || 'parent';
this.config.children = config.children || 'children';
this.config.options = config.options || { deleteParent: true };
}
|
[
"function",
"FlatToNested",
"(",
"config",
")",
"{",
"this",
".",
"config",
"=",
"config",
"=",
"config",
"||",
"{",
"}",
";",
"this",
".",
"config",
".",
"id",
"=",
"config",
".",
"id",
"||",
"'id'",
";",
"this",
".",
"config",
".",
"parent",
"=",
"config",
".",
"parent",
"||",
"'parent'",
";",
"this",
".",
"config",
".",
"children",
"=",
"config",
".",
"children",
"||",
"'children'",
";",
"this",
".",
"config",
".",
"options",
"=",
"config",
".",
"options",
"||",
"{",
"deleteParent",
":",
"true",
"}",
";",
"}"
] |
Create a new FlatToNested object.
@constructor
@param {object} config The configuration object.
|
[
"Create",
"a",
"new",
"FlatToNested",
"object",
"."
] |
1d2748909d015d05940051f4e79c0fd819e210f7
|
https://github.com/joaonuno/flat-to-nested-js/blob/1d2748909d015d05940051f4e79c0fd819e210f7/index.js#L10-L16
|
19,812
|
lovell/farmhash
|
index.js
|
function (input) {
if (typeof input === 'string') {
return farmhash.Hash32String(input);
}
if (Buffer.isBuffer(input)) {
return farmhash.Hash32Buffer(input);
}
throw new Error('Expected a String or Buffer for input');
}
|
javascript
|
function (input) {
if (typeof input === 'string') {
return farmhash.Hash32String(input);
}
if (Buffer.isBuffer(input)) {
return farmhash.Hash32Buffer(input);
}
throw new Error('Expected a String or Buffer for input');
}
|
[
"function",
"(",
"input",
")",
"{",
"if",
"(",
"typeof",
"input",
"===",
"'string'",
")",
"{",
"return",
"farmhash",
".",
"Hash32String",
"(",
"input",
")",
";",
"}",
"if",
"(",
"Buffer",
".",
"isBuffer",
"(",
"input",
")",
")",
"{",
"return",
"farmhash",
".",
"Hash32Buffer",
"(",
"input",
")",
";",
"}",
"throw",
"new",
"Error",
"(",
"'Expected a String or Buffer for input'",
")",
";",
"}"
] |
Hash methods - platform dependent
|
[
"Hash",
"methods",
"-",
"platform",
"dependent"
] |
742f3fa9120dbf8a455813820cf0c7116770be19
|
https://github.com/lovell/farmhash/blob/742f3fa9120dbf8a455813820cf0c7116770be19/index.js#L14-L22
|
|
19,813
|
lovell/farmhash
|
index.js
|
function (input) {
if (typeof input === 'string') {
return farmhash.Fingerprint32String(input);
}
if (Buffer.isBuffer(input)) {
return farmhash.Fingerprint32Buffer(input);
}
throw new Error('Expected a String or Buffer for input');
}
|
javascript
|
function (input) {
if (typeof input === 'string') {
return farmhash.Fingerprint32String(input);
}
if (Buffer.isBuffer(input)) {
return farmhash.Fingerprint32Buffer(input);
}
throw new Error('Expected a String or Buffer for input');
}
|
[
"function",
"(",
"input",
")",
"{",
"if",
"(",
"typeof",
"input",
"===",
"'string'",
")",
"{",
"return",
"farmhash",
".",
"Fingerprint32String",
"(",
"input",
")",
";",
"}",
"if",
"(",
"Buffer",
".",
"isBuffer",
"(",
"input",
")",
")",
"{",
"return",
"farmhash",
".",
"Fingerprint32Buffer",
"(",
"input",
")",
";",
"}",
"throw",
"new",
"Error",
"(",
"'Expected a String or Buffer for input'",
")",
";",
"}"
] |
Fingerprint methods - platform independent
|
[
"Fingerprint",
"methods",
"-",
"platform",
"independent"
] |
742f3fa9120dbf8a455813820cf0c7116770be19
|
https://github.com/lovell/farmhash/blob/742f3fa9120dbf8a455813820cf0c7116770be19/index.js#L64-L72
|
|
19,814
|
luckymarmot/API-Flow
|
scripts/flow-runner.js
|
runSuite
|
function runSuite() {
execFile(flow, [ 'status', '--color', 'always' ], (err, stdout) => {
process.stdout.write('\x1Bc')
/* eslint-disable no-console */
console.log(stdout)
/* eslint-enable no-console */
})
}
|
javascript
|
function runSuite() {
execFile(flow, [ 'status', '--color', 'always' ], (err, stdout) => {
process.stdout.write('\x1Bc')
/* eslint-disable no-console */
console.log(stdout)
/* eslint-enable no-console */
})
}
|
[
"function",
"runSuite",
"(",
")",
"{",
"execFile",
"(",
"flow",
",",
"[",
"'status'",
",",
"'--color'",
",",
"'always'",
"]",
",",
"(",
"err",
",",
"stdout",
")",
"=>",
"{",
"process",
".",
"stdout",
".",
"write",
"(",
"'\\x1Bc'",
")",
"/* eslint-disable no-console */",
"console",
".",
"log",
"(",
"stdout",
")",
"/* eslint-enable no-console */",
"}",
")",
"}"
] |
A helper function to run flow tests. Clears the window and the prints
the status of flow.
@returns {void} nothing
|
[
"A",
"helper",
"function",
"to",
"run",
"flow",
"tests",
".",
"Clears",
"the",
"window",
"and",
"the",
"prints",
"the",
"status",
"of",
"flow",
"."
] |
24cc71aec64ca6be2c8b7807c9f97041a52b8cdb
|
https://github.com/luckymarmot/API-Flow/blob/24cc71aec64ca6be2c8b7807c9f97041a52b8cdb/scripts/flow-runner.js#L10-L17
|
19,815
|
ajfisher/node-pixel
|
lib/pixel.js
|
create_gamma_table
|
function create_gamma_table(steps, gamma, warning) {
// used to build a gamma table for a particular value
if (! warning && gamma == GAMMA_DEFAULT && ! global.IS_TEST_MODE) {
console.info("INFO: Default gamma behaviour is changing");
console.info("0.9 - gamma=1.0 - consistent with pre-gamma values");
console.info("0.10 - gamma=2.8 - default fix for WS2812 LEDs");
warning = true;
}
var g_table = new Array(steps);
for (let i = 0; i < steps; i++) {
g_table[i] = Math.floor(Math.pow((i / 255.0), gamma) * 255 + 0.5);
}
return g_table;
}
|
javascript
|
function create_gamma_table(steps, gamma, warning) {
// used to build a gamma table for a particular value
if (! warning && gamma == GAMMA_DEFAULT && ! global.IS_TEST_MODE) {
console.info("INFO: Default gamma behaviour is changing");
console.info("0.9 - gamma=1.0 - consistent with pre-gamma values");
console.info("0.10 - gamma=2.8 - default fix for WS2812 LEDs");
warning = true;
}
var g_table = new Array(steps);
for (let i = 0; i < steps; i++) {
g_table[i] = Math.floor(Math.pow((i / 255.0), gamma) * 255 + 0.5);
}
return g_table;
}
|
[
"function",
"create_gamma_table",
"(",
"steps",
",",
"gamma",
",",
"warning",
")",
"{",
"// used to build a gamma table for a particular value",
"if",
"(",
"!",
"warning",
"&&",
"gamma",
"==",
"GAMMA_DEFAULT",
"&&",
"!",
"global",
".",
"IS_TEST_MODE",
")",
"{",
"console",
".",
"info",
"(",
"\"INFO: Default gamma behaviour is changing\"",
")",
";",
"console",
".",
"info",
"(",
"\"0.9 - gamma=1.0 - consistent with pre-gamma values\"",
")",
";",
"console",
".",
"info",
"(",
"\"0.10 - gamma=2.8 - default fix for WS2812 LEDs\"",
")",
";",
"warning",
"=",
"true",
";",
"}",
"var",
"g_table",
"=",
"new",
"Array",
"(",
"steps",
")",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"steps",
";",
"i",
"++",
")",
"{",
"g_table",
"[",
"i",
"]",
"=",
"Math",
".",
"floor",
"(",
"Math",
".",
"pow",
"(",
"(",
"i",
"/",
"255.0",
")",
",",
"gamma",
")",
"*",
"255",
"+",
"0.5",
")",
";",
"}",
"return",
"g_table",
";",
"}"
] |
helper function for building gamma values
|
[
"helper",
"function",
"for",
"building",
"gamma",
"values"
] |
bfce32df41a40a6b86b5f5d04f190dc9029d629c
|
https://github.com/ajfisher/node-pixel/blob/bfce32df41a40a6b86b5f5d04f190dc9029d629c/lib/pixel.js#L401-L417
|
19,816
|
ajfisher/node-pixel
|
examples/rainbow-static.js
|
colorWheel
|
function colorWheel( WheelPos ){
var r,g,b;
WheelPos = 255 - WheelPos;
if ( WheelPos < 85 ) {
r = 255 - WheelPos * 3;
g = 0;
b = WheelPos * 3;
} else if (WheelPos < 170) {
WheelPos -= 85;
r = 0;
g = WheelPos * 3;
b = 255 - WheelPos * 3;
} else {
WheelPos -= 170;
r = WheelPos * 3;
g = 255 - WheelPos * 3;
b = 0;
}
// returns a string with the rgb value to be used as the parameter
return "rgb(" + r +"," + g + "," + b + ")";
}
|
javascript
|
function colorWheel( WheelPos ){
var r,g,b;
WheelPos = 255 - WheelPos;
if ( WheelPos < 85 ) {
r = 255 - WheelPos * 3;
g = 0;
b = WheelPos * 3;
} else if (WheelPos < 170) {
WheelPos -= 85;
r = 0;
g = WheelPos * 3;
b = 255 - WheelPos * 3;
} else {
WheelPos -= 170;
r = WheelPos * 3;
g = 255 - WheelPos * 3;
b = 0;
}
// returns a string with the rgb value to be used as the parameter
return "rgb(" + r +"," + g + "," + b + ")";
}
|
[
"function",
"colorWheel",
"(",
"WheelPos",
")",
"{",
"var",
"r",
",",
"g",
",",
"b",
";",
"WheelPos",
"=",
"255",
"-",
"WheelPos",
";",
"if",
"(",
"WheelPos",
"<",
"85",
")",
"{",
"r",
"=",
"255",
"-",
"WheelPos",
"*",
"3",
";",
"g",
"=",
"0",
";",
"b",
"=",
"WheelPos",
"*",
"3",
";",
"}",
"else",
"if",
"(",
"WheelPos",
"<",
"170",
")",
"{",
"WheelPos",
"-=",
"85",
";",
"r",
"=",
"0",
";",
"g",
"=",
"WheelPos",
"*",
"3",
";",
"b",
"=",
"255",
"-",
"WheelPos",
"*",
"3",
";",
"}",
"else",
"{",
"WheelPos",
"-=",
"170",
";",
"r",
"=",
"WheelPos",
"*",
"3",
";",
"g",
"=",
"255",
"-",
"WheelPos",
"*",
"3",
";",
"b",
"=",
"0",
";",
"}",
"// returns a string with the rgb value to be used as the parameter",
"return",
"\"rgb(\"",
"+",
"r",
"+",
"\",\"",
"+",
"g",
"+",
"\",\"",
"+",
"b",
"+",
"\")\"",
";",
"}"
] |
Input a value 0 to 255 to get a color value. The colours are a transition r - g - b - back to r.
|
[
"Input",
"a",
"value",
"0",
"to",
"255",
"to",
"get",
"a",
"color",
"value",
".",
"The",
"colours",
"are",
"a",
"transition",
"r",
"-",
"g",
"-",
"b",
"-",
"back",
"to",
"r",
"."
] |
bfce32df41a40a6b86b5f5d04f190dc9029d629c
|
https://github.com/ajfisher/node-pixel/blob/bfce32df41a40a6b86b5f5d04f190dc9029d629c/examples/rainbow-static.js#L47-L68
|
19,817
|
eggjs/egg-logrotator
|
app/lib/rotator.js
|
renameOrDelete
|
async function renameOrDelete(srcPath, targetPath) {
if (srcPath === targetPath) {
return;
}
const srcExists = await fs.exists(srcPath);
if (!srcExists) {
return;
}
const targetExists = await fs.exists(targetPath);
// if target file exists, then throw
// because the target file always be renamed first.
if (targetExists) {
const err = new Error(`targetFile ${targetPath} exists!!!`);
throw err;
}
await fs.rename(srcPath, targetPath);
}
|
javascript
|
async function renameOrDelete(srcPath, targetPath) {
if (srcPath === targetPath) {
return;
}
const srcExists = await fs.exists(srcPath);
if (!srcExists) {
return;
}
const targetExists = await fs.exists(targetPath);
// if target file exists, then throw
// because the target file always be renamed first.
if (targetExists) {
const err = new Error(`targetFile ${targetPath} exists!!!`);
throw err;
}
await fs.rename(srcPath, targetPath);
}
|
[
"async",
"function",
"renameOrDelete",
"(",
"srcPath",
",",
"targetPath",
")",
"{",
"if",
"(",
"srcPath",
"===",
"targetPath",
")",
"{",
"return",
";",
"}",
"const",
"srcExists",
"=",
"await",
"fs",
".",
"exists",
"(",
"srcPath",
")",
";",
"if",
"(",
"!",
"srcExists",
")",
"{",
"return",
";",
"}",
"const",
"targetExists",
"=",
"await",
"fs",
".",
"exists",
"(",
"targetPath",
")",
";",
"// if target file exists, then throw",
"// because the target file always be renamed first.",
"if",
"(",
"targetExists",
")",
"{",
"const",
"err",
"=",
"new",
"Error",
"(",
"`",
"${",
"targetPath",
"}",
"`",
")",
";",
"throw",
"err",
";",
"}",
"await",
"fs",
".",
"rename",
"(",
"srcPath",
",",
"targetPath",
")",
";",
"}"
] |
rename from srcPath to targetPath, for example foo.log.1 > foo.log.2
|
[
"rename",
"from",
"srcPath",
"to",
"targetPath",
"for",
"example",
"foo",
".",
"log",
".",
"1",
">",
"foo",
".",
"log",
".",
"2"
] |
105616a372f563ae77a50ecb62b73c61d4c17fd5
|
https://github.com/eggjs/egg-logrotator/blob/105616a372f563ae77a50ecb62b73c61d4c17fd5/app/lib/rotator.js#L51-L67
|
19,818
|
infusion/Complex.js
|
complex.js
|
function(a, b) {
var z = new Complex(a, b);
// Infinity + Infinity = NaN
if (this['isInfinite']() && z['isInfinite']()) {
return Complex['NAN'];
}
// Infinity + z = Infinity { where z != Infinity }
if (this['isInfinite']() || z['isInfinite']()) {
return Complex['INFINITY'];
}
return new Complex(
this['re'] + z['re'],
this['im'] + z['im']);
}
|
javascript
|
function(a, b) {
var z = new Complex(a, b);
// Infinity + Infinity = NaN
if (this['isInfinite']() && z['isInfinite']()) {
return Complex['NAN'];
}
// Infinity + z = Infinity { where z != Infinity }
if (this['isInfinite']() || z['isInfinite']()) {
return Complex['INFINITY'];
}
return new Complex(
this['re'] + z['re'],
this['im'] + z['im']);
}
|
[
"function",
"(",
"a",
",",
"b",
")",
"{",
"var",
"z",
"=",
"new",
"Complex",
"(",
"a",
",",
"b",
")",
";",
"// Infinity + Infinity = NaN",
"if",
"(",
"this",
"[",
"'isInfinite'",
"]",
"(",
")",
"&&",
"z",
"[",
"'isInfinite'",
"]",
"(",
")",
")",
"{",
"return",
"Complex",
"[",
"'NAN'",
"]",
";",
"}",
"// Infinity + z = Infinity { where z != Infinity }",
"if",
"(",
"this",
"[",
"'isInfinite'",
"]",
"(",
")",
"||",
"z",
"[",
"'isInfinite'",
"]",
"(",
")",
")",
"{",
"return",
"Complex",
"[",
"'INFINITY'",
"]",
";",
"}",
"return",
"new",
"Complex",
"(",
"this",
"[",
"'re'",
"]",
"+",
"z",
"[",
"'re'",
"]",
",",
"this",
"[",
"'im'",
"]",
"+",
"z",
"[",
"'im'",
"]",
")",
";",
"}"
] |
Adds two complex numbers
@returns {Complex}
|
[
"Adds",
"two",
"complex",
"numbers"
] |
7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1
|
https://github.com/infusion/Complex.js/blob/7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1/complex.js#L315-L332
|
|
19,819
|
infusion/Complex.js
|
complex.js
|
function(a, b) {
var z = new Complex(a, b);
// Infinity * 0 = NaN
if ((this['isInfinite']() && z['isZero']()) || (this['isZero']() && z['isInfinite']())) {
return Complex['NAN'];
}
// Infinity * z = Infinity { where z != 0 }
if (this['isInfinite']() || z['isInfinite']()) {
return Complex['INFINITY'];
}
// Short circuit for real values
if (z['im'] === 0 && this['im'] === 0) {
return new Complex(this['re'] * z['re'], 0);
}
return new Complex(
this['re'] * z['re'] - this['im'] * z['im'],
this['re'] * z['im'] + this['im'] * z['re']);
}
|
javascript
|
function(a, b) {
var z = new Complex(a, b);
// Infinity * 0 = NaN
if ((this['isInfinite']() && z['isZero']()) || (this['isZero']() && z['isInfinite']())) {
return Complex['NAN'];
}
// Infinity * z = Infinity { where z != 0 }
if (this['isInfinite']() || z['isInfinite']()) {
return Complex['INFINITY'];
}
// Short circuit for real values
if (z['im'] === 0 && this['im'] === 0) {
return new Complex(this['re'] * z['re'], 0);
}
return new Complex(
this['re'] * z['re'] - this['im'] * z['im'],
this['re'] * z['im'] + this['im'] * z['re']);
}
|
[
"function",
"(",
"a",
",",
"b",
")",
"{",
"var",
"z",
"=",
"new",
"Complex",
"(",
"a",
",",
"b",
")",
";",
"// Infinity * 0 = NaN",
"if",
"(",
"(",
"this",
"[",
"'isInfinite'",
"]",
"(",
")",
"&&",
"z",
"[",
"'isZero'",
"]",
"(",
")",
")",
"||",
"(",
"this",
"[",
"'isZero'",
"]",
"(",
")",
"&&",
"z",
"[",
"'isInfinite'",
"]",
"(",
")",
")",
")",
"{",
"return",
"Complex",
"[",
"'NAN'",
"]",
";",
"}",
"// Infinity * z = Infinity { where z != 0 }",
"if",
"(",
"this",
"[",
"'isInfinite'",
"]",
"(",
")",
"||",
"z",
"[",
"'isInfinite'",
"]",
"(",
")",
")",
"{",
"return",
"Complex",
"[",
"'INFINITY'",
"]",
";",
"}",
"// Short circuit for real values",
"if",
"(",
"z",
"[",
"'im'",
"]",
"===",
"0",
"&&",
"this",
"[",
"'im'",
"]",
"===",
"0",
")",
"{",
"return",
"new",
"Complex",
"(",
"this",
"[",
"'re'",
"]",
"*",
"z",
"[",
"'re'",
"]",
",",
"0",
")",
";",
"}",
"return",
"new",
"Complex",
"(",
"this",
"[",
"'re'",
"]",
"*",
"z",
"[",
"'re'",
"]",
"-",
"this",
"[",
"'im'",
"]",
"*",
"z",
"[",
"'im'",
"]",
",",
"this",
"[",
"'re'",
"]",
"*",
"z",
"[",
"'im'",
"]",
"+",
"this",
"[",
"'im'",
"]",
"*",
"z",
"[",
"'re'",
"]",
")",
";",
"}"
] |
Multiplies two complex numbers
@returns {Complex}
|
[
"Multiplies",
"two",
"complex",
"numbers"
] |
7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1
|
https://github.com/infusion/Complex.js/blob/7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1/complex.js#L363-L385
|
|
19,820
|
infusion/Complex.js
|
complex.js
|
function(a, b) {
var z = new Complex(a, b);
// 0 / 0 = NaN and Infinity / Infinity = NaN
if ((this['isZero']() && z['isZero']()) || (this['isInfinite']() && z['isInfinite']())) {
return Complex['NAN'];
}
// Infinity / 0 = Infinity
if (this['isInfinite']() || z['isZero']()) {
return Complex['INFINITY'];
}
// 0 / Infinity = 0
if (this['isZero']() || z['isInfinite']()) {
return Complex['ZERO'];
}
a = this['re'];
b = this['im'];
var c = z['re'];
var d = z['im'];
var t, x;
if (0 === d) {
// Divisor is real
return new Complex(a / c, b / c);
}
if (Math.abs(c) < Math.abs(d)) {
x = c / d;
t = c * x + d;
return new Complex(
(a * x + b) / t,
(b * x - a) / t);
} else {
x = d / c;
t = d * x + c;
return new Complex(
(a + b * x) / t,
(b - a * x) / t);
}
}
|
javascript
|
function(a, b) {
var z = new Complex(a, b);
// 0 / 0 = NaN and Infinity / Infinity = NaN
if ((this['isZero']() && z['isZero']()) || (this['isInfinite']() && z['isInfinite']())) {
return Complex['NAN'];
}
// Infinity / 0 = Infinity
if (this['isInfinite']() || z['isZero']()) {
return Complex['INFINITY'];
}
// 0 / Infinity = 0
if (this['isZero']() || z['isInfinite']()) {
return Complex['ZERO'];
}
a = this['re'];
b = this['im'];
var c = z['re'];
var d = z['im'];
var t, x;
if (0 === d) {
// Divisor is real
return new Complex(a / c, b / c);
}
if (Math.abs(c) < Math.abs(d)) {
x = c / d;
t = c * x + d;
return new Complex(
(a * x + b) / t,
(b * x - a) / t);
} else {
x = d / c;
t = d * x + c;
return new Complex(
(a + b * x) / t,
(b - a * x) / t);
}
}
|
[
"function",
"(",
"a",
",",
"b",
")",
"{",
"var",
"z",
"=",
"new",
"Complex",
"(",
"a",
",",
"b",
")",
";",
"// 0 / 0 = NaN and Infinity / Infinity = NaN",
"if",
"(",
"(",
"this",
"[",
"'isZero'",
"]",
"(",
")",
"&&",
"z",
"[",
"'isZero'",
"]",
"(",
")",
")",
"||",
"(",
"this",
"[",
"'isInfinite'",
"]",
"(",
")",
"&&",
"z",
"[",
"'isInfinite'",
"]",
"(",
")",
")",
")",
"{",
"return",
"Complex",
"[",
"'NAN'",
"]",
";",
"}",
"// Infinity / 0 = Infinity",
"if",
"(",
"this",
"[",
"'isInfinite'",
"]",
"(",
")",
"||",
"z",
"[",
"'isZero'",
"]",
"(",
")",
")",
"{",
"return",
"Complex",
"[",
"'INFINITY'",
"]",
";",
"}",
"// 0 / Infinity = 0",
"if",
"(",
"this",
"[",
"'isZero'",
"]",
"(",
")",
"||",
"z",
"[",
"'isInfinite'",
"]",
"(",
")",
")",
"{",
"return",
"Complex",
"[",
"'ZERO'",
"]",
";",
"}",
"a",
"=",
"this",
"[",
"'re'",
"]",
";",
"b",
"=",
"this",
"[",
"'im'",
"]",
";",
"var",
"c",
"=",
"z",
"[",
"'re'",
"]",
";",
"var",
"d",
"=",
"z",
"[",
"'im'",
"]",
";",
"var",
"t",
",",
"x",
";",
"if",
"(",
"0",
"===",
"d",
")",
"{",
"// Divisor is real",
"return",
"new",
"Complex",
"(",
"a",
"/",
"c",
",",
"b",
"/",
"c",
")",
";",
"}",
"if",
"(",
"Math",
".",
"abs",
"(",
"c",
")",
"<",
"Math",
".",
"abs",
"(",
"d",
")",
")",
"{",
"x",
"=",
"c",
"/",
"d",
";",
"t",
"=",
"c",
"*",
"x",
"+",
"d",
";",
"return",
"new",
"Complex",
"(",
"(",
"a",
"*",
"x",
"+",
"b",
")",
"/",
"t",
",",
"(",
"b",
"*",
"x",
"-",
"a",
")",
"/",
"t",
")",
";",
"}",
"else",
"{",
"x",
"=",
"d",
"/",
"c",
";",
"t",
"=",
"d",
"*",
"x",
"+",
"c",
";",
"return",
"new",
"Complex",
"(",
"(",
"a",
"+",
"b",
"*",
"x",
")",
"/",
"t",
",",
"(",
"b",
"-",
"a",
"*",
"x",
")",
"/",
"t",
")",
";",
"}",
"}"
] |
Divides two complex numbers
@returns {Complex}
|
[
"Divides",
"two",
"complex",
"numbers"
] |
7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1
|
https://github.com/infusion/Complex.js/blob/7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1/complex.js#L392-L441
|
|
19,821
|
infusion/Complex.js
|
complex.js
|
function(a, b) {
var z = new Complex(a, b);
a = this['re'];
b = this['im'];
if (z['isZero']()) {
return Complex['ONE'];
}
// If the exponent is real
if (z['im'] === 0) {
if (b === 0 && a >= 0) {
return new Complex(Math.pow(a, z['re']), 0);
} else if (a === 0) { // If base is fully imaginary
switch ((z['re'] % 4 + 4) % 4) {
case 0:
return new Complex(Math.pow(b, z['re']), 0);
case 1:
return new Complex(0, Math.pow(b, z['re']));
case 2:
return new Complex(-Math.pow(b, z['re']), 0);
case 3:
return new Complex(0, -Math.pow(b, z['re']));
}
}
}
/* I couldn't find a good formula, so here is a derivation and optimization
*
* z_1^z_2 = (a + bi)^(c + di)
* = exp((c + di) * log(a + bi)
* = pow(a^2 + b^2, (c + di) / 2) * exp(i(c + di)atan2(b, a))
* =>...
* Re = (pow(a^2 + b^2, c / 2) * exp(-d * atan2(b, a))) * cos(d * log(a^2 + b^2) / 2 + c * atan2(b, a))
* Im = (pow(a^2 + b^2, c / 2) * exp(-d * atan2(b, a))) * sin(d * log(a^2 + b^2) / 2 + c * atan2(b, a))
*
* =>...
* Re = exp(c * log(sqrt(a^2 + b^2)) - d * atan2(b, a)) * cos(d * log(sqrt(a^2 + b^2)) + c * atan2(b, a))
* Im = exp(c * log(sqrt(a^2 + b^2)) - d * atan2(b, a)) * sin(d * log(sqrt(a^2 + b^2)) + c * atan2(b, a))
*
* =>
* Re = exp(c * logsq2 - d * arg(z_1)) * cos(d * logsq2 + c * arg(z_1))
* Im = exp(c * logsq2 - d * arg(z_1)) * sin(d * logsq2 + c * arg(z_1))
*
*/
if (a === 0 && b === 0 && z['re'] > 0 && z['im'] >= 0) {
return Complex['ZERO'];
}
var arg = Math.atan2(b, a);
var loh = logHypot(a, b);
a = Math.exp(z['re'] * loh - z['im'] * arg);
b = z['im'] * loh + z['re'] * arg;
return new Complex(
a * Math.cos(b),
a * Math.sin(b));
}
|
javascript
|
function(a, b) {
var z = new Complex(a, b);
a = this['re'];
b = this['im'];
if (z['isZero']()) {
return Complex['ONE'];
}
// If the exponent is real
if (z['im'] === 0) {
if (b === 0 && a >= 0) {
return new Complex(Math.pow(a, z['re']), 0);
} else if (a === 0) { // If base is fully imaginary
switch ((z['re'] % 4 + 4) % 4) {
case 0:
return new Complex(Math.pow(b, z['re']), 0);
case 1:
return new Complex(0, Math.pow(b, z['re']));
case 2:
return new Complex(-Math.pow(b, z['re']), 0);
case 3:
return new Complex(0, -Math.pow(b, z['re']));
}
}
}
/* I couldn't find a good formula, so here is a derivation and optimization
*
* z_1^z_2 = (a + bi)^(c + di)
* = exp((c + di) * log(a + bi)
* = pow(a^2 + b^2, (c + di) / 2) * exp(i(c + di)atan2(b, a))
* =>...
* Re = (pow(a^2 + b^2, c / 2) * exp(-d * atan2(b, a))) * cos(d * log(a^2 + b^2) / 2 + c * atan2(b, a))
* Im = (pow(a^2 + b^2, c / 2) * exp(-d * atan2(b, a))) * sin(d * log(a^2 + b^2) / 2 + c * atan2(b, a))
*
* =>...
* Re = exp(c * log(sqrt(a^2 + b^2)) - d * atan2(b, a)) * cos(d * log(sqrt(a^2 + b^2)) + c * atan2(b, a))
* Im = exp(c * log(sqrt(a^2 + b^2)) - d * atan2(b, a)) * sin(d * log(sqrt(a^2 + b^2)) + c * atan2(b, a))
*
* =>
* Re = exp(c * logsq2 - d * arg(z_1)) * cos(d * logsq2 + c * arg(z_1))
* Im = exp(c * logsq2 - d * arg(z_1)) * sin(d * logsq2 + c * arg(z_1))
*
*/
if (a === 0 && b === 0 && z['re'] > 0 && z['im'] >= 0) {
return Complex['ZERO'];
}
var arg = Math.atan2(b, a);
var loh = logHypot(a, b);
a = Math.exp(z['re'] * loh - z['im'] * arg);
b = z['im'] * loh + z['re'] * arg;
return new Complex(
a * Math.cos(b),
a * Math.sin(b));
}
|
[
"function",
"(",
"a",
",",
"b",
")",
"{",
"var",
"z",
"=",
"new",
"Complex",
"(",
"a",
",",
"b",
")",
";",
"a",
"=",
"this",
"[",
"'re'",
"]",
";",
"b",
"=",
"this",
"[",
"'im'",
"]",
";",
"if",
"(",
"z",
"[",
"'isZero'",
"]",
"(",
")",
")",
"{",
"return",
"Complex",
"[",
"'ONE'",
"]",
";",
"}",
"// If the exponent is real",
"if",
"(",
"z",
"[",
"'im'",
"]",
"===",
"0",
")",
"{",
"if",
"(",
"b",
"===",
"0",
"&&",
"a",
">=",
"0",
")",
"{",
"return",
"new",
"Complex",
"(",
"Math",
".",
"pow",
"(",
"a",
",",
"z",
"[",
"'re'",
"]",
")",
",",
"0",
")",
";",
"}",
"else",
"if",
"(",
"a",
"===",
"0",
")",
"{",
"// If base is fully imaginary",
"switch",
"(",
"(",
"z",
"[",
"'re'",
"]",
"%",
"4",
"+",
"4",
")",
"%",
"4",
")",
"{",
"case",
"0",
":",
"return",
"new",
"Complex",
"(",
"Math",
".",
"pow",
"(",
"b",
",",
"z",
"[",
"'re'",
"]",
")",
",",
"0",
")",
";",
"case",
"1",
":",
"return",
"new",
"Complex",
"(",
"0",
",",
"Math",
".",
"pow",
"(",
"b",
",",
"z",
"[",
"'re'",
"]",
")",
")",
";",
"case",
"2",
":",
"return",
"new",
"Complex",
"(",
"-",
"Math",
".",
"pow",
"(",
"b",
",",
"z",
"[",
"'re'",
"]",
")",
",",
"0",
")",
";",
"case",
"3",
":",
"return",
"new",
"Complex",
"(",
"0",
",",
"-",
"Math",
".",
"pow",
"(",
"b",
",",
"z",
"[",
"'re'",
"]",
")",
")",
";",
"}",
"}",
"}",
"/* I couldn't find a good formula, so here is a derivation and optimization\n *\n * z_1^z_2 = (a + bi)^(c + di)\n * = exp((c + di) * log(a + bi)\n * = pow(a^2 + b^2, (c + di) / 2) * exp(i(c + di)atan2(b, a))\n * =>...\n * Re = (pow(a^2 + b^2, c / 2) * exp(-d * atan2(b, a))) * cos(d * log(a^2 + b^2) / 2 + c * atan2(b, a))\n * Im = (pow(a^2 + b^2, c / 2) * exp(-d * atan2(b, a))) * sin(d * log(a^2 + b^2) / 2 + c * atan2(b, a))\n *\n * =>...\n * Re = exp(c * log(sqrt(a^2 + b^2)) - d * atan2(b, a)) * cos(d * log(sqrt(a^2 + b^2)) + c * atan2(b, a))\n * Im = exp(c * log(sqrt(a^2 + b^2)) - d * atan2(b, a)) * sin(d * log(sqrt(a^2 + b^2)) + c * atan2(b, a))\n *\n * =>\n * Re = exp(c * logsq2 - d * arg(z_1)) * cos(d * logsq2 + c * arg(z_1))\n * Im = exp(c * logsq2 - d * arg(z_1)) * sin(d * logsq2 + c * arg(z_1))\n *\n */",
"if",
"(",
"a",
"===",
"0",
"&&",
"b",
"===",
"0",
"&&",
"z",
"[",
"'re'",
"]",
">",
"0",
"&&",
"z",
"[",
"'im'",
"]",
">=",
"0",
")",
"{",
"return",
"Complex",
"[",
"'ZERO'",
"]",
";",
"}",
"var",
"arg",
"=",
"Math",
".",
"atan2",
"(",
"b",
",",
"a",
")",
";",
"var",
"loh",
"=",
"logHypot",
"(",
"a",
",",
"b",
")",
";",
"a",
"=",
"Math",
".",
"exp",
"(",
"z",
"[",
"'re'",
"]",
"*",
"loh",
"-",
"z",
"[",
"'im'",
"]",
"*",
"arg",
")",
";",
"b",
"=",
"z",
"[",
"'im'",
"]",
"*",
"loh",
"+",
"z",
"[",
"'re'",
"]",
"*",
"arg",
";",
"return",
"new",
"Complex",
"(",
"a",
"*",
"Math",
".",
"cos",
"(",
"b",
")",
",",
"a",
"*",
"Math",
".",
"sin",
"(",
"b",
")",
")",
";",
"}"
] |
Calculate the power of two complex numbers
@returns {Complex}
|
[
"Calculate",
"the",
"power",
"of",
"two",
"complex",
"numbers"
] |
7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1
|
https://github.com/infusion/Complex.js/blob/7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1/complex.js#L448-L512
|
|
19,822
|
infusion/Complex.js
|
complex.js
|
function() {
var a = this['re'];
var b = this['im'];
var r = this['abs']();
var re, im;
if (a >= 0) {
if (b === 0) {
return new Complex(Math.sqrt(a), 0);
}
re = 0.5 * Math.sqrt(2.0 * (r + a));
} else {
re = Math.abs(b) / Math.sqrt(2 * (r - a));
}
if (a <= 0) {
im = 0.5 * Math.sqrt(2.0 * (r - a));
} else {
im = Math.abs(b) / Math.sqrt(2 * (r + a));
}
return new Complex(re, b < 0 ? -im : im);
}
|
javascript
|
function() {
var a = this['re'];
var b = this['im'];
var r = this['abs']();
var re, im;
if (a >= 0) {
if (b === 0) {
return new Complex(Math.sqrt(a), 0);
}
re = 0.5 * Math.sqrt(2.0 * (r + a));
} else {
re = Math.abs(b) / Math.sqrt(2 * (r - a));
}
if (a <= 0) {
im = 0.5 * Math.sqrt(2.0 * (r - a));
} else {
im = Math.abs(b) / Math.sqrt(2 * (r + a));
}
return new Complex(re, b < 0 ? -im : im);
}
|
[
"function",
"(",
")",
"{",
"var",
"a",
"=",
"this",
"[",
"'re'",
"]",
";",
"var",
"b",
"=",
"this",
"[",
"'im'",
"]",
";",
"var",
"r",
"=",
"this",
"[",
"'abs'",
"]",
"(",
")",
";",
"var",
"re",
",",
"im",
";",
"if",
"(",
"a",
">=",
"0",
")",
"{",
"if",
"(",
"b",
"===",
"0",
")",
"{",
"return",
"new",
"Complex",
"(",
"Math",
".",
"sqrt",
"(",
"a",
")",
",",
"0",
")",
";",
"}",
"re",
"=",
"0.5",
"*",
"Math",
".",
"sqrt",
"(",
"2.0",
"*",
"(",
"r",
"+",
"a",
")",
")",
";",
"}",
"else",
"{",
"re",
"=",
"Math",
".",
"abs",
"(",
"b",
")",
"/",
"Math",
".",
"sqrt",
"(",
"2",
"*",
"(",
"r",
"-",
"a",
")",
")",
";",
"}",
"if",
"(",
"a",
"<=",
"0",
")",
"{",
"im",
"=",
"0.5",
"*",
"Math",
".",
"sqrt",
"(",
"2.0",
"*",
"(",
"r",
"-",
"a",
")",
")",
";",
"}",
"else",
"{",
"im",
"=",
"Math",
".",
"abs",
"(",
"b",
")",
"/",
"Math",
".",
"sqrt",
"(",
"2",
"*",
"(",
"r",
"+",
"a",
")",
")",
";",
"}",
"return",
"new",
"Complex",
"(",
"re",
",",
"b",
"<",
"0",
"?",
"-",
"im",
":",
"im",
")",
";",
"}"
] |
Calculate the complex square root
@returns {Complex}
|
[
"Calculate",
"the",
"complex",
"square",
"root"
] |
7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1
|
https://github.com/infusion/Complex.js/blob/7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1/complex.js#L519-L545
|
|
19,823
|
infusion/Complex.js
|
complex.js
|
function() {
var tmp = Math.exp(this['re']);
if (this['im'] === 0) {
//return new Complex(tmp, 0);
}
return new Complex(
tmp * Math.cos(this['im']),
tmp * Math.sin(this['im']));
}
|
javascript
|
function() {
var tmp = Math.exp(this['re']);
if (this['im'] === 0) {
//return new Complex(tmp, 0);
}
return new Complex(
tmp * Math.cos(this['im']),
tmp * Math.sin(this['im']));
}
|
[
"function",
"(",
")",
"{",
"var",
"tmp",
"=",
"Math",
".",
"exp",
"(",
"this",
"[",
"'re'",
"]",
")",
";",
"if",
"(",
"this",
"[",
"'im'",
"]",
"===",
"0",
")",
"{",
"//return new Complex(tmp, 0);",
"}",
"return",
"new",
"Complex",
"(",
"tmp",
"*",
"Math",
".",
"cos",
"(",
"this",
"[",
"'im'",
"]",
")",
",",
"tmp",
"*",
"Math",
".",
"sin",
"(",
"this",
"[",
"'im'",
"]",
")",
")",
";",
"}"
] |
Calculate the complex exponent
@returns {Complex}
|
[
"Calculate",
"the",
"complex",
"exponent"
] |
7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1
|
https://github.com/infusion/Complex.js/blob/7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1/complex.js#L552-L562
|
|
19,824
|
infusion/Complex.js
|
complex.js
|
function() {
/**
* exp(a + i*b) - 1
= exp(a) * (cos(b) + j*sin(b)) - 1
= expm1(a)*cos(b) + cosm1(b) + j*exp(a)*sin(b)
*/
var a = this['re'];
var b = this['im'];
return new Complex(
Math.expm1(a) * Math.cos(b) + cosm1(b),
Math.exp(a) * Math.sin(b));
}
|
javascript
|
function() {
/**
* exp(a + i*b) - 1
= exp(a) * (cos(b) + j*sin(b)) - 1
= expm1(a)*cos(b) + cosm1(b) + j*exp(a)*sin(b)
*/
var a = this['re'];
var b = this['im'];
return new Complex(
Math.expm1(a) * Math.cos(b) + cosm1(b),
Math.exp(a) * Math.sin(b));
}
|
[
"function",
"(",
")",
"{",
"/**\n * exp(a + i*b) - 1\n = exp(a) * (cos(b) + j*sin(b)) - 1\n = expm1(a)*cos(b) + cosm1(b) + j*exp(a)*sin(b)\n */",
"var",
"a",
"=",
"this",
"[",
"'re'",
"]",
";",
"var",
"b",
"=",
"this",
"[",
"'im'",
"]",
";",
"return",
"new",
"Complex",
"(",
"Math",
".",
"expm1",
"(",
"a",
")",
"*",
"Math",
".",
"cos",
"(",
"b",
")",
"+",
"cosm1",
"(",
"b",
")",
",",
"Math",
".",
"exp",
"(",
"a",
")",
"*",
"Math",
".",
"sin",
"(",
"b",
")",
")",
";",
"}"
] |
Calculate the complex exponent and subtracts one.
This may be more accurate than `Complex(x).exp().sub(1)` if
`x` is small.
@returns {Complex}
|
[
"Calculate",
"the",
"complex",
"exponent",
"and",
"subtracts",
"one",
"."
] |
7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1
|
https://github.com/infusion/Complex.js/blob/7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1/complex.js#L572-L586
|
|
19,825
|
infusion/Complex.js
|
complex.js
|
function() {
var a = this['re'];
var b = this['im'];
if (b === 0 && a > 0) {
//return new Complex(Math.log(a), 0);
}
return new Complex(
logHypot(a, b),
Math.atan2(b, a));
}
|
javascript
|
function() {
var a = this['re'];
var b = this['im'];
if (b === 0 && a > 0) {
//return new Complex(Math.log(a), 0);
}
return new Complex(
logHypot(a, b),
Math.atan2(b, a));
}
|
[
"function",
"(",
")",
"{",
"var",
"a",
"=",
"this",
"[",
"'re'",
"]",
";",
"var",
"b",
"=",
"this",
"[",
"'im'",
"]",
";",
"if",
"(",
"b",
"===",
"0",
"&&",
"a",
">",
"0",
")",
"{",
"//return new Complex(Math.log(a), 0);",
"}",
"return",
"new",
"Complex",
"(",
"logHypot",
"(",
"a",
",",
"b",
")",
",",
"Math",
".",
"atan2",
"(",
"b",
",",
"a",
")",
")",
";",
"}"
] |
Calculate the natural log
@returns {Complex}
|
[
"Calculate",
"the",
"natural",
"log"
] |
7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1
|
https://github.com/infusion/Complex.js/blob/7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1/complex.js#L593-L605
|
|
19,826
|
infusion/Complex.js
|
complex.js
|
function() {
// sin(c) = (e^b - e^(-b)) / (2i)
var a = this['re'];
var b = this['im'];
return new Complex(
Math.sin(a) * cosh(b),
Math.cos(a) * sinh(b));
}
|
javascript
|
function() {
// sin(c) = (e^b - e^(-b)) / (2i)
var a = this['re'];
var b = this['im'];
return new Complex(
Math.sin(a) * cosh(b),
Math.cos(a) * sinh(b));
}
|
[
"function",
"(",
")",
"{",
"// sin(c) = (e^b - e^(-b)) / (2i)",
"var",
"a",
"=",
"this",
"[",
"'re'",
"]",
";",
"var",
"b",
"=",
"this",
"[",
"'im'",
"]",
";",
"return",
"new",
"Complex",
"(",
"Math",
".",
"sin",
"(",
"a",
")",
"*",
"cosh",
"(",
"b",
")",
",",
"Math",
".",
"cos",
"(",
"a",
")",
"*",
"sinh",
"(",
"b",
")",
")",
";",
"}"
] |
Calculate the sine of the complex number
@returns {Complex}
|
[
"Calculate",
"the",
"sine",
"of",
"the",
"complex",
"number"
] |
7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1
|
https://github.com/infusion/Complex.js/blob/7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1/complex.js#L632-L642
|
|
19,827
|
infusion/Complex.js
|
complex.js
|
function() {
// asin(c) = -i * log(ci + sqrt(1 - c^2))
var a = this['re'];
var b = this['im'];
var t1 = new Complex(
b * b - a * a + 1,
-2 * a * b)['sqrt']();
var t2 = new Complex(
t1['re'] - b,
t1['im'] + a)['log']();
return new Complex(t2['im'], -t2['re']);
}
|
javascript
|
function() {
// asin(c) = -i * log(ci + sqrt(1 - c^2))
var a = this['re'];
var b = this['im'];
var t1 = new Complex(
b * b - a * a + 1,
-2 * a * b)['sqrt']();
var t2 = new Complex(
t1['re'] - b,
t1['im'] + a)['log']();
return new Complex(t2['im'], -t2['re']);
}
|
[
"function",
"(",
")",
"{",
"// asin(c) = -i * log(ci + sqrt(1 - c^2))",
"var",
"a",
"=",
"this",
"[",
"'re'",
"]",
";",
"var",
"b",
"=",
"this",
"[",
"'im'",
"]",
";",
"var",
"t1",
"=",
"new",
"Complex",
"(",
"b",
"*",
"b",
"-",
"a",
"*",
"a",
"+",
"1",
",",
"-",
"2",
"*",
"a",
"*",
"b",
")",
"[",
"'sqrt'",
"]",
"(",
")",
";",
"var",
"t2",
"=",
"new",
"Complex",
"(",
"t1",
"[",
"'re'",
"]",
"-",
"b",
",",
"t1",
"[",
"'im'",
"]",
"+",
"a",
")",
"[",
"'log'",
"]",
"(",
")",
";",
"return",
"new",
"Complex",
"(",
"t2",
"[",
"'im'",
"]",
",",
"-",
"t2",
"[",
"'re'",
"]",
")",
";",
"}"
] |
Calculate the complex arcus sinus
@returns {Complex}
|
[
"Calculate",
"the",
"complex",
"arcus",
"sinus"
] |
7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1
|
https://github.com/infusion/Complex.js/blob/7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1/complex.js#L738-L754
|
|
19,828
|
infusion/Complex.js
|
complex.js
|
function() {
// acos(c) = i * log(c - i * sqrt(1 - c^2))
var a = this['re'];
var b = this['im'];
var t1 = new Complex(
b * b - a * a + 1,
-2 * a * b)['sqrt']();
var t2 = new Complex(
t1['re'] - b,
t1['im'] + a)['log']();
return new Complex(Math.PI / 2 - t2['im'], t2['re']);
}
|
javascript
|
function() {
// acos(c) = i * log(c - i * sqrt(1 - c^2))
var a = this['re'];
var b = this['im'];
var t1 = new Complex(
b * b - a * a + 1,
-2 * a * b)['sqrt']();
var t2 = new Complex(
t1['re'] - b,
t1['im'] + a)['log']();
return new Complex(Math.PI / 2 - t2['im'], t2['re']);
}
|
[
"function",
"(",
")",
"{",
"// acos(c) = i * log(c - i * sqrt(1 - c^2))",
"var",
"a",
"=",
"this",
"[",
"'re'",
"]",
";",
"var",
"b",
"=",
"this",
"[",
"'im'",
"]",
";",
"var",
"t1",
"=",
"new",
"Complex",
"(",
"b",
"*",
"b",
"-",
"a",
"*",
"a",
"+",
"1",
",",
"-",
"2",
"*",
"a",
"*",
"b",
")",
"[",
"'sqrt'",
"]",
"(",
")",
";",
"var",
"t2",
"=",
"new",
"Complex",
"(",
"t1",
"[",
"'re'",
"]",
"-",
"b",
",",
"t1",
"[",
"'im'",
"]",
"+",
"a",
")",
"[",
"'log'",
"]",
"(",
")",
";",
"return",
"new",
"Complex",
"(",
"Math",
".",
"PI",
"/",
"2",
"-",
"t2",
"[",
"'im'",
"]",
",",
"t2",
"[",
"'re'",
"]",
")",
";",
"}"
] |
Calculate the complex arcus cosinus
@returns {Complex}
|
[
"Calculate",
"the",
"complex",
"arcus",
"cosinus"
] |
7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1
|
https://github.com/infusion/Complex.js/blob/7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1/complex.js#L761-L777
|
|
19,829
|
infusion/Complex.js
|
complex.js
|
function() {
// atan(c) = i / 2 log((i + x) / (i - x))
var a = this['re'];
var b = this['im'];
if (a === 0) {
if (b === 1) {
return new Complex(0, Infinity);
}
if (b === -1) {
return new Complex(0, -Infinity);
}
}
var d = a * a + (1.0 - b) * (1.0 - b);
var t1 = new Complex(
(1 - b * b - a * a) / d,
-2 * a / d).log();
return new Complex(-0.5 * t1['im'], 0.5 * t1['re']);
}
|
javascript
|
function() {
// atan(c) = i / 2 log((i + x) / (i - x))
var a = this['re'];
var b = this['im'];
if (a === 0) {
if (b === 1) {
return new Complex(0, Infinity);
}
if (b === -1) {
return new Complex(0, -Infinity);
}
}
var d = a * a + (1.0 - b) * (1.0 - b);
var t1 = new Complex(
(1 - b * b - a * a) / d,
-2 * a / d).log();
return new Complex(-0.5 * t1['im'], 0.5 * t1['re']);
}
|
[
"function",
"(",
")",
"{",
"// atan(c) = i / 2 log((i + x) / (i - x))",
"var",
"a",
"=",
"this",
"[",
"'re'",
"]",
";",
"var",
"b",
"=",
"this",
"[",
"'im'",
"]",
";",
"if",
"(",
"a",
"===",
"0",
")",
"{",
"if",
"(",
"b",
"===",
"1",
")",
"{",
"return",
"new",
"Complex",
"(",
"0",
",",
"Infinity",
")",
";",
"}",
"if",
"(",
"b",
"===",
"-",
"1",
")",
"{",
"return",
"new",
"Complex",
"(",
"0",
",",
"-",
"Infinity",
")",
";",
"}",
"}",
"var",
"d",
"=",
"a",
"*",
"a",
"+",
"(",
"1.0",
"-",
"b",
")",
"*",
"(",
"1.0",
"-",
"b",
")",
";",
"var",
"t1",
"=",
"new",
"Complex",
"(",
"(",
"1",
"-",
"b",
"*",
"b",
"-",
"a",
"*",
"a",
")",
"/",
"d",
",",
"-",
"2",
"*",
"a",
"/",
"d",
")",
".",
"log",
"(",
")",
";",
"return",
"new",
"Complex",
"(",
"-",
"0.5",
"*",
"t1",
"[",
"'im'",
"]",
",",
"0.5",
"*",
"t1",
"[",
"'re'",
"]",
")",
";",
"}"
] |
Calculate the complex arcus tangent
@returns {Complex}
|
[
"Calculate",
"the",
"complex",
"arcus",
"tangent"
] |
7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1
|
https://github.com/infusion/Complex.js/blob/7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1/complex.js#L784-L809
|
|
19,830
|
infusion/Complex.js
|
complex.js
|
function() {
// acot(c) = i / 2 log((c - i) / (c + i))
var a = this['re'];
var b = this['im'];
if (b === 0) {
return new Complex(Math.atan2(1, a), 0);
}
var d = a * a + b * b;
return (d !== 0)
? new Complex(
a / d,
-b / d).atan()
: new Complex(
(a !== 0) ? a / 0 : 0,
(b !== 0) ? -b / 0 : 0).atan();
}
|
javascript
|
function() {
// acot(c) = i / 2 log((c - i) / (c + i))
var a = this['re'];
var b = this['im'];
if (b === 0) {
return new Complex(Math.atan2(1, a), 0);
}
var d = a * a + b * b;
return (d !== 0)
? new Complex(
a / d,
-b / d).atan()
: new Complex(
(a !== 0) ? a / 0 : 0,
(b !== 0) ? -b / 0 : 0).atan();
}
|
[
"function",
"(",
")",
"{",
"// acot(c) = i / 2 log((c - i) / (c + i))",
"var",
"a",
"=",
"this",
"[",
"'re'",
"]",
";",
"var",
"b",
"=",
"this",
"[",
"'im'",
"]",
";",
"if",
"(",
"b",
"===",
"0",
")",
"{",
"return",
"new",
"Complex",
"(",
"Math",
".",
"atan2",
"(",
"1",
",",
"a",
")",
",",
"0",
")",
";",
"}",
"var",
"d",
"=",
"a",
"*",
"a",
"+",
"b",
"*",
"b",
";",
"return",
"(",
"d",
"!==",
"0",
")",
"?",
"new",
"Complex",
"(",
"a",
"/",
"d",
",",
"-",
"b",
"/",
"d",
")",
".",
"atan",
"(",
")",
":",
"new",
"Complex",
"(",
"(",
"a",
"!==",
"0",
")",
"?",
"a",
"/",
"0",
":",
"0",
",",
"(",
"b",
"!==",
"0",
")",
"?",
"-",
"b",
"/",
"0",
":",
"0",
")",
".",
"atan",
"(",
")",
";",
"}"
] |
Calculate the complex arcus cotangent
@returns {Complex}
|
[
"Calculate",
"the",
"complex",
"arcus",
"cotangent"
] |
7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1
|
https://github.com/infusion/Complex.js/blob/7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1/complex.js#L816-L835
|
|
19,831
|
infusion/Complex.js
|
complex.js
|
function() {
// asec(c) = -i * log(1 / c + sqrt(1 - i / c^2))
var a = this['re'];
var b = this['im'];
if (a === 0 && b === 0) {
return new Complex(0, Infinity);
}
var d = a * a + b * b;
return (d !== 0)
? new Complex(
a / d,
-b / d).acos()
: new Complex(
(a !== 0) ? a / 0 : 0,
(b !== 0) ? -b / 0 : 0).acos();
}
|
javascript
|
function() {
// asec(c) = -i * log(1 / c + sqrt(1 - i / c^2))
var a = this['re'];
var b = this['im'];
if (a === 0 && b === 0) {
return new Complex(0, Infinity);
}
var d = a * a + b * b;
return (d !== 0)
? new Complex(
a / d,
-b / d).acos()
: new Complex(
(a !== 0) ? a / 0 : 0,
(b !== 0) ? -b / 0 : 0).acos();
}
|
[
"function",
"(",
")",
"{",
"// asec(c) = -i * log(1 / c + sqrt(1 - i / c^2))",
"var",
"a",
"=",
"this",
"[",
"'re'",
"]",
";",
"var",
"b",
"=",
"this",
"[",
"'im'",
"]",
";",
"if",
"(",
"a",
"===",
"0",
"&&",
"b",
"===",
"0",
")",
"{",
"return",
"new",
"Complex",
"(",
"0",
",",
"Infinity",
")",
";",
"}",
"var",
"d",
"=",
"a",
"*",
"a",
"+",
"b",
"*",
"b",
";",
"return",
"(",
"d",
"!==",
"0",
")",
"?",
"new",
"Complex",
"(",
"a",
"/",
"d",
",",
"-",
"b",
"/",
"d",
")",
".",
"acos",
"(",
")",
":",
"new",
"Complex",
"(",
"(",
"a",
"!==",
"0",
")",
"?",
"a",
"/",
"0",
":",
"0",
",",
"(",
"b",
"!==",
"0",
")",
"?",
"-",
"b",
"/",
"0",
":",
"0",
")",
".",
"acos",
"(",
")",
";",
"}"
] |
Calculate the complex arcus secant
@returns {Complex}
|
[
"Calculate",
"the",
"complex",
"arcus",
"secant"
] |
7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1
|
https://github.com/infusion/Complex.js/blob/7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1/complex.js#L842-L861
|
|
19,832
|
infusion/Complex.js
|
complex.js
|
function() {
// acsc(c) = -i * log(i / c + sqrt(1 - 1 / c^2))
var a = this['re'];
var b = this['im'];
if (a === 0 && b === 0) {
return new Complex(Math.PI / 2, Infinity);
}
var d = a * a + b * b;
return (d !== 0)
? new Complex(
a / d,
-b / d).asin()
: new Complex(
(a !== 0) ? a / 0 : 0,
(b !== 0) ? -b / 0 : 0).asin();
}
|
javascript
|
function() {
// acsc(c) = -i * log(i / c + sqrt(1 - 1 / c^2))
var a = this['re'];
var b = this['im'];
if (a === 0 && b === 0) {
return new Complex(Math.PI / 2, Infinity);
}
var d = a * a + b * b;
return (d !== 0)
? new Complex(
a / d,
-b / d).asin()
: new Complex(
(a !== 0) ? a / 0 : 0,
(b !== 0) ? -b / 0 : 0).asin();
}
|
[
"function",
"(",
")",
"{",
"// acsc(c) = -i * log(i / c + sqrt(1 - 1 / c^2))",
"var",
"a",
"=",
"this",
"[",
"'re'",
"]",
";",
"var",
"b",
"=",
"this",
"[",
"'im'",
"]",
";",
"if",
"(",
"a",
"===",
"0",
"&&",
"b",
"===",
"0",
")",
"{",
"return",
"new",
"Complex",
"(",
"Math",
".",
"PI",
"/",
"2",
",",
"Infinity",
")",
";",
"}",
"var",
"d",
"=",
"a",
"*",
"a",
"+",
"b",
"*",
"b",
";",
"return",
"(",
"d",
"!==",
"0",
")",
"?",
"new",
"Complex",
"(",
"a",
"/",
"d",
",",
"-",
"b",
"/",
"d",
")",
".",
"asin",
"(",
")",
":",
"new",
"Complex",
"(",
"(",
"a",
"!==",
"0",
")",
"?",
"a",
"/",
"0",
":",
"0",
",",
"(",
"b",
"!==",
"0",
")",
"?",
"-",
"b",
"/",
"0",
":",
"0",
")",
".",
"asin",
"(",
")",
";",
"}"
] |
Calculate the complex arcus cosecans
@returns {Complex}
|
[
"Calculate",
"the",
"complex",
"arcus",
"cosecans"
] |
7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1
|
https://github.com/infusion/Complex.js/blob/7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1/complex.js#L868-L887
|
|
19,833
|
infusion/Complex.js
|
complex.js
|
function() {
// atanh(c) = log((1+c) / (1-c)) / 2
var a = this['re'];
var b = this['im'];
var noIM = a > 1 && b === 0;
var oneMinus = 1 - a;
var onePlus = 1 + a;
var d = oneMinus * oneMinus + b * b;
var x = (d !== 0)
? new Complex(
(onePlus * oneMinus - b * b) / d,
(b * oneMinus + onePlus * b) / d)
: new Complex(
(a !== -1) ? (a / 0) : 0,
(b !== 0) ? (b / 0) : 0);
var temp = x['re'];
x['re'] = logHypot(x['re'], x['im']) / 2;
x['im'] = Math.atan2(x['im'], temp) / 2;
if (noIM) {
x['im'] = -x['im'];
}
return x;
}
|
javascript
|
function() {
// atanh(c) = log((1+c) / (1-c)) / 2
var a = this['re'];
var b = this['im'];
var noIM = a > 1 && b === 0;
var oneMinus = 1 - a;
var onePlus = 1 + a;
var d = oneMinus * oneMinus + b * b;
var x = (d !== 0)
? new Complex(
(onePlus * oneMinus - b * b) / d,
(b * oneMinus + onePlus * b) / d)
: new Complex(
(a !== -1) ? (a / 0) : 0,
(b !== 0) ? (b / 0) : 0);
var temp = x['re'];
x['re'] = logHypot(x['re'], x['im']) / 2;
x['im'] = Math.atan2(x['im'], temp) / 2;
if (noIM) {
x['im'] = -x['im'];
}
return x;
}
|
[
"function",
"(",
")",
"{",
"// atanh(c) = log((1+c) / (1-c)) / 2",
"var",
"a",
"=",
"this",
"[",
"'re'",
"]",
";",
"var",
"b",
"=",
"this",
"[",
"'im'",
"]",
";",
"var",
"noIM",
"=",
"a",
">",
"1",
"&&",
"b",
"===",
"0",
";",
"var",
"oneMinus",
"=",
"1",
"-",
"a",
";",
"var",
"onePlus",
"=",
"1",
"+",
"a",
";",
"var",
"d",
"=",
"oneMinus",
"*",
"oneMinus",
"+",
"b",
"*",
"b",
";",
"var",
"x",
"=",
"(",
"d",
"!==",
"0",
")",
"?",
"new",
"Complex",
"(",
"(",
"onePlus",
"*",
"oneMinus",
"-",
"b",
"*",
"b",
")",
"/",
"d",
",",
"(",
"b",
"*",
"oneMinus",
"+",
"onePlus",
"*",
"b",
")",
"/",
"d",
")",
":",
"new",
"Complex",
"(",
"(",
"a",
"!==",
"-",
"1",
")",
"?",
"(",
"a",
"/",
"0",
")",
":",
"0",
",",
"(",
"b",
"!==",
"0",
")",
"?",
"(",
"b",
"/",
"0",
")",
":",
"0",
")",
";",
"var",
"temp",
"=",
"x",
"[",
"'re'",
"]",
";",
"x",
"[",
"'re'",
"]",
"=",
"logHypot",
"(",
"x",
"[",
"'re'",
"]",
",",
"x",
"[",
"'im'",
"]",
")",
"/",
"2",
";",
"x",
"[",
"'im'",
"]",
"=",
"Math",
".",
"atan2",
"(",
"x",
"[",
"'im'",
"]",
",",
"temp",
")",
"/",
"2",
";",
"if",
"(",
"noIM",
")",
"{",
"x",
"[",
"'im'",
"]",
"=",
"-",
"x",
"[",
"'im'",
"]",
";",
"}",
"return",
"x",
";",
"}"
] |
Calculate the complex atanh
@returns {Complex}
|
[
"Calculate",
"the",
"complex",
"atanh"
] |
7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1
|
https://github.com/infusion/Complex.js/blob/7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1/complex.js#L1045-L1072
|
|
19,834
|
infusion/Complex.js
|
complex.js
|
function() {
// acoth(c) = log((c+1) / (c-1)) / 2
var a = this['re'];
var b = this['im'];
if (a === 0 && b === 0) {
return new Complex(0, Math.PI / 2);
}
var d = a * a + b * b;
return (d !== 0)
? new Complex(
a / d,
-b / d).atanh()
: new Complex(
(a !== 0) ? a / 0 : 0,
(b !== 0) ? -b / 0 : 0).atanh();
}
|
javascript
|
function() {
// acoth(c) = log((c+1) / (c-1)) / 2
var a = this['re'];
var b = this['im'];
if (a === 0 && b === 0) {
return new Complex(0, Math.PI / 2);
}
var d = a * a + b * b;
return (d !== 0)
? new Complex(
a / d,
-b / d).atanh()
: new Complex(
(a !== 0) ? a / 0 : 0,
(b !== 0) ? -b / 0 : 0).atanh();
}
|
[
"function",
"(",
")",
"{",
"// acoth(c) = log((c+1) / (c-1)) / 2",
"var",
"a",
"=",
"this",
"[",
"'re'",
"]",
";",
"var",
"b",
"=",
"this",
"[",
"'im'",
"]",
";",
"if",
"(",
"a",
"===",
"0",
"&&",
"b",
"===",
"0",
")",
"{",
"return",
"new",
"Complex",
"(",
"0",
",",
"Math",
".",
"PI",
"/",
"2",
")",
";",
"}",
"var",
"d",
"=",
"a",
"*",
"a",
"+",
"b",
"*",
"b",
";",
"return",
"(",
"d",
"!==",
"0",
")",
"?",
"new",
"Complex",
"(",
"a",
"/",
"d",
",",
"-",
"b",
"/",
"d",
")",
".",
"atanh",
"(",
")",
":",
"new",
"Complex",
"(",
"(",
"a",
"!==",
"0",
")",
"?",
"a",
"/",
"0",
":",
"0",
",",
"(",
"b",
"!==",
"0",
")",
"?",
"-",
"b",
"/",
"0",
":",
"0",
")",
".",
"atanh",
"(",
")",
";",
"}"
] |
Calculate the complex acoth
@returns {Complex}
|
[
"Calculate",
"the",
"complex",
"acoth"
] |
7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1
|
https://github.com/infusion/Complex.js/blob/7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1/complex.js#L1079-L1098
|
|
19,835
|
infusion/Complex.js
|
complex.js
|
function() {
// acsch(c) = log((1+sqrt(1+c^2))/c)
var a = this['re'];
var b = this['im'];
if (b === 0) {
return new Complex(
(a !== 0)
? Math.log(a + Math.sqrt(a * a + 1))
: Infinity, 0);
}
var d = a * a + b * b;
return (d !== 0)
? new Complex(
a / d,
-b / d).asinh()
: new Complex(
(a !== 0) ? a / 0 : 0,
(b !== 0) ? -b / 0 : 0).asinh();
}
|
javascript
|
function() {
// acsch(c) = log((1+sqrt(1+c^2))/c)
var a = this['re'];
var b = this['im'];
if (b === 0) {
return new Complex(
(a !== 0)
? Math.log(a + Math.sqrt(a * a + 1))
: Infinity, 0);
}
var d = a * a + b * b;
return (d !== 0)
? new Complex(
a / d,
-b / d).asinh()
: new Complex(
(a !== 0) ? a / 0 : 0,
(b !== 0) ? -b / 0 : 0).asinh();
}
|
[
"function",
"(",
")",
"{",
"// acsch(c) = log((1+sqrt(1+c^2))/c)",
"var",
"a",
"=",
"this",
"[",
"'re'",
"]",
";",
"var",
"b",
"=",
"this",
"[",
"'im'",
"]",
";",
"if",
"(",
"b",
"===",
"0",
")",
"{",
"return",
"new",
"Complex",
"(",
"(",
"a",
"!==",
"0",
")",
"?",
"Math",
".",
"log",
"(",
"a",
"+",
"Math",
".",
"sqrt",
"(",
"a",
"*",
"a",
"+",
"1",
")",
")",
":",
"Infinity",
",",
"0",
")",
";",
"}",
"var",
"d",
"=",
"a",
"*",
"a",
"+",
"b",
"*",
"b",
";",
"return",
"(",
"d",
"!==",
"0",
")",
"?",
"new",
"Complex",
"(",
"a",
"/",
"d",
",",
"-",
"b",
"/",
"d",
")",
".",
"asinh",
"(",
")",
":",
"new",
"Complex",
"(",
"(",
"a",
"!==",
"0",
")",
"?",
"a",
"/",
"0",
":",
"0",
",",
"(",
"b",
"!==",
"0",
")",
"?",
"-",
"b",
"/",
"0",
":",
"0",
")",
".",
"asinh",
"(",
")",
";",
"}"
] |
Calculate the complex acsch
@returns {Complex}
|
[
"Calculate",
"the",
"complex",
"acsch"
] |
7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1
|
https://github.com/infusion/Complex.js/blob/7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1/complex.js#L1105-L1128
|
|
19,836
|
infusion/Complex.js
|
complex.js
|
function() {
// asech(c) = log((1+sqrt(1-c^2))/c)
var a = this['re'];
var b = this['im'];
if (this['isZero']()) {
return Complex['INFINITY'];
}
var d = a * a + b * b;
return (d !== 0)
? new Complex(
a / d,
-b / d).acosh()
: new Complex(
(a !== 0) ? a / 0 : 0,
(b !== 0) ? -b / 0 : 0).acosh();
}
|
javascript
|
function() {
// asech(c) = log((1+sqrt(1-c^2))/c)
var a = this['re'];
var b = this['im'];
if (this['isZero']()) {
return Complex['INFINITY'];
}
var d = a * a + b * b;
return (d !== 0)
? new Complex(
a / d,
-b / d).acosh()
: new Complex(
(a !== 0) ? a / 0 : 0,
(b !== 0) ? -b / 0 : 0).acosh();
}
|
[
"function",
"(",
")",
"{",
"// asech(c) = log((1+sqrt(1-c^2))/c)",
"var",
"a",
"=",
"this",
"[",
"'re'",
"]",
";",
"var",
"b",
"=",
"this",
"[",
"'im'",
"]",
";",
"if",
"(",
"this",
"[",
"'isZero'",
"]",
"(",
")",
")",
"{",
"return",
"Complex",
"[",
"'INFINITY'",
"]",
";",
"}",
"var",
"d",
"=",
"a",
"*",
"a",
"+",
"b",
"*",
"b",
";",
"return",
"(",
"d",
"!==",
"0",
")",
"?",
"new",
"Complex",
"(",
"a",
"/",
"d",
",",
"-",
"b",
"/",
"d",
")",
".",
"acosh",
"(",
")",
":",
"new",
"Complex",
"(",
"(",
"a",
"!==",
"0",
")",
"?",
"a",
"/",
"0",
":",
"0",
",",
"(",
"b",
"!==",
"0",
")",
"?",
"-",
"b",
"/",
"0",
":",
"0",
")",
".",
"acosh",
"(",
")",
";",
"}"
] |
Calculate the complex asech
@returns {Complex}
|
[
"Calculate",
"the",
"complex",
"asech"
] |
7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1
|
https://github.com/infusion/Complex.js/blob/7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1/complex.js#L1135-L1154
|
|
19,837
|
infusion/Complex.js
|
complex.js
|
function(places) {
places = Math.pow(10, places || 0);
return new Complex(
Math.floor(this['re'] * places) / places,
Math.floor(this['im'] * places) / places);
}
|
javascript
|
function(places) {
places = Math.pow(10, places || 0);
return new Complex(
Math.floor(this['re'] * places) / places,
Math.floor(this['im'] * places) / places);
}
|
[
"function",
"(",
"places",
")",
"{",
"places",
"=",
"Math",
".",
"pow",
"(",
"10",
",",
"places",
"||",
"0",
")",
";",
"return",
"new",
"Complex",
"(",
"Math",
".",
"floor",
"(",
"this",
"[",
"'re'",
"]",
"*",
"places",
")",
"/",
"places",
",",
"Math",
".",
"floor",
"(",
"this",
"[",
"'im'",
"]",
"*",
"places",
")",
"/",
"places",
")",
";",
"}"
] |
Floors the actual complex number
@returns {Complex}
|
[
"Floors",
"the",
"actual",
"complex",
"number"
] |
7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1
|
https://github.com/infusion/Complex.js/blob/7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1/complex.js#L1219-L1226
|
|
19,838
|
infusion/Complex.js
|
complex.js
|
function(a, b) {
var z = new Complex(a, b);
return Math.abs(z['re'] - this['re']) <= Complex['EPSILON'] &&
Math.abs(z['im'] - this['im']) <= Complex['EPSILON'];
}
|
javascript
|
function(a, b) {
var z = new Complex(a, b);
return Math.abs(z['re'] - this['re']) <= Complex['EPSILON'] &&
Math.abs(z['im'] - this['im']) <= Complex['EPSILON'];
}
|
[
"function",
"(",
"a",
",",
"b",
")",
"{",
"var",
"z",
"=",
"new",
"Complex",
"(",
"a",
",",
"b",
")",
";",
"return",
"Math",
".",
"abs",
"(",
"z",
"[",
"'re'",
"]",
"-",
"this",
"[",
"'re'",
"]",
")",
"<=",
"Complex",
"[",
"'EPSILON'",
"]",
"&&",
"Math",
".",
"abs",
"(",
"z",
"[",
"'im'",
"]",
"-",
"this",
"[",
"'im'",
"]",
")",
"<=",
"Complex",
"[",
"'EPSILON'",
"]",
";",
"}"
] |
Compares two complex numbers
**Note:** new Complex(Infinity).equals(Infinity) === false
@returns {boolean}
|
[
"Compares",
"two",
"complex",
"numbers"
] |
7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1
|
https://github.com/infusion/Complex.js/blob/7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1/complex.js#L1249-L1255
|
|
19,839
|
infusion/Complex.js
|
complex.js
|
function() {
var a = this['re'];
var b = this['im'];
var ret = '';
if (this['isNaN']()) {
return 'NaN';
}
if (this['isZero']()) {
return '0';
}
if (this['isInfinite']()) {
return 'Infinity';
}
if (a !== 0) {
ret += a;
}
if (b !== 0) {
if (a !== 0) {
ret += b < 0 ? ' - ' : ' + ';
} else if (b < 0) {
ret += '-';
}
b = Math.abs(b);
if (1 !== b) {
ret += b;
}
ret += 'i';
}
if (!ret)
return '0';
return ret;
}
|
javascript
|
function() {
var a = this['re'];
var b = this['im'];
var ret = '';
if (this['isNaN']()) {
return 'NaN';
}
if (this['isZero']()) {
return '0';
}
if (this['isInfinite']()) {
return 'Infinity';
}
if (a !== 0) {
ret += a;
}
if (b !== 0) {
if (a !== 0) {
ret += b < 0 ? ' - ' : ' + ';
} else if (b < 0) {
ret += '-';
}
b = Math.abs(b);
if (1 !== b) {
ret += b;
}
ret += 'i';
}
if (!ret)
return '0';
return ret;
}
|
[
"function",
"(",
")",
"{",
"var",
"a",
"=",
"this",
"[",
"'re'",
"]",
";",
"var",
"b",
"=",
"this",
"[",
"'im'",
"]",
";",
"var",
"ret",
"=",
"''",
";",
"if",
"(",
"this",
"[",
"'isNaN'",
"]",
"(",
")",
")",
"{",
"return",
"'NaN'",
";",
"}",
"if",
"(",
"this",
"[",
"'isZero'",
"]",
"(",
")",
")",
"{",
"return",
"'0'",
";",
"}",
"if",
"(",
"this",
"[",
"'isInfinite'",
"]",
"(",
")",
")",
"{",
"return",
"'Infinity'",
";",
"}",
"if",
"(",
"a",
"!==",
"0",
")",
"{",
"ret",
"+=",
"a",
";",
"}",
"if",
"(",
"b",
"!==",
"0",
")",
"{",
"if",
"(",
"a",
"!==",
"0",
")",
"{",
"ret",
"+=",
"b",
"<",
"0",
"?",
"' - '",
":",
"' + '",
";",
"}",
"else",
"if",
"(",
"b",
"<",
"0",
")",
"{",
"ret",
"+=",
"'-'",
";",
"}",
"b",
"=",
"Math",
".",
"abs",
"(",
"b",
")",
";",
"if",
"(",
"1",
"!==",
"b",
")",
"{",
"ret",
"+=",
"b",
";",
"}",
"ret",
"+=",
"'i'",
";",
"}",
"if",
"(",
"!",
"ret",
")",
"return",
"'0'",
";",
"return",
"ret",
";",
"}"
] |
Gets a string of the actual complex number
@returns {string}
|
[
"Gets",
"a",
"string",
"of",
"the",
"actual",
"complex",
"number"
] |
7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1
|
https://github.com/infusion/Complex.js/blob/7477f7b125dcd3a645b8ae4c818a14c1ed1c65b1/complex.js#L1272-L1314
|
|
19,840
|
jshttp/accepts
|
index.js
|
Accepts
|
function Accepts (req) {
if (!(this instanceof Accepts)) {
return new Accepts(req)
}
this.headers = req.headers
this.negotiator = new Negotiator(req)
}
|
javascript
|
function Accepts (req) {
if (!(this instanceof Accepts)) {
return new Accepts(req)
}
this.headers = req.headers
this.negotiator = new Negotiator(req)
}
|
[
"function",
"Accepts",
"(",
"req",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Accepts",
")",
")",
"{",
"return",
"new",
"Accepts",
"(",
"req",
")",
"}",
"this",
".",
"headers",
"=",
"req",
".",
"headers",
"this",
".",
"negotiator",
"=",
"new",
"Negotiator",
"(",
"req",
")",
"}"
] |
Create a new Accepts object for the given req.
@param {object} req
@public
|
[
"Create",
"a",
"new",
"Accepts",
"object",
"for",
"the",
"given",
"req",
"."
] |
2a6e060aebb52813fdb074e9e7f66da1cfa61902
|
https://github.com/jshttp/accepts/blob/2a6e060aebb52813fdb074e9e7f66da1cfa61902/index.js#L32-L39
|
19,841
|
ybogdanov/node-sync
|
examples/fiber.js
|
someAsyncFunction
|
function someAsyncFunction(file, callback) {
// Here we just wrap the function body to make it synchronous inside
// Sync will execute first argument 'fn' in synchronous way
// and call second argument 'callback' when function returns
// it also calls callback if exception will be thrown inside of 'fn'
Sync(function(){
var source = require('fs').readFile.sync(null, __filename);
return source;
}, callback)
}
|
javascript
|
function someAsyncFunction(file, callback) {
// Here we just wrap the function body to make it synchronous inside
// Sync will execute first argument 'fn' in synchronous way
// and call second argument 'callback' when function returns
// it also calls callback if exception will be thrown inside of 'fn'
Sync(function(){
var source = require('fs').readFile.sync(null, __filename);
return source;
}, callback)
}
|
[
"function",
"someAsyncFunction",
"(",
"file",
",",
"callback",
")",
"{",
"// Here we just wrap the function body to make it synchronous inside",
"// Sync will execute first argument 'fn' in synchronous way",
"// and call second argument 'callback' when function returns",
"// it also calls callback if exception will be thrown inside of 'fn'",
"Sync",
"(",
"function",
"(",
")",
"{",
"var",
"source",
"=",
"require",
"(",
"'fs'",
")",
".",
"readFile",
".",
"sync",
"(",
"null",
",",
"__filename",
")",
";",
"return",
"source",
";",
"}",
",",
"callback",
")",
"}"
] |
Simple asynchronous function with fiber inside example
|
[
"Simple",
"asynchronous",
"function",
"with",
"fiber",
"inside",
"example"
] |
e977d68cf34eb207fce162e6a288eef2fb3f22d3
|
https://github.com/ybogdanov/node-sync/blob/e977d68cf34eb207fce162e6a288eef2fb3f22d3/examples/fiber.js#L12-L21
|
19,842
|
ybogdanov/node-sync
|
examples/async.js
|
asyncFunction
|
function asyncFunction(a, b, callback) {
process.nextTick(function(){
callback(null, a + b);
})
}
|
javascript
|
function asyncFunction(a, b, callback) {
process.nextTick(function(){
callback(null, a + b);
})
}
|
[
"function",
"asyncFunction",
"(",
"a",
",",
"b",
",",
"callback",
")",
"{",
"process",
".",
"nextTick",
"(",
"function",
"(",
")",
"{",
"callback",
"(",
"null",
",",
"a",
"+",
"b",
")",
";",
"}",
")",
"}"
] |
Simple asynchronous function
|
[
"Simple",
"asynchronous",
"function"
] |
e977d68cf34eb207fce162e6a288eef2fb3f22d3
|
https://github.com/ybogdanov/node-sync/blob/e977d68cf34eb207fce162e6a288eef2fb3f22d3/examples/async.js#L10-L14
|
19,843
|
ybogdanov/node-sync
|
lib/sync.js
|
function (callbackError, callbackResult, otherArgs) {
// forbid to call twice
if (syncCallback.called) return;
syncCallback.called = true;
if (callbackError) {
err = callbackError;
}
else if (otherArgs) {
// Support multiple callback result values
result = [];
for (var i = 1, l = arguments.length; i < l; i++) {
result.push(arguments[i]);
}
}
else {
result = callbackResult;
}
// Resume fiber if yielding
if (yielded) fiber.run();
}
|
javascript
|
function (callbackError, callbackResult, otherArgs) {
// forbid to call twice
if (syncCallback.called) return;
syncCallback.called = true;
if (callbackError) {
err = callbackError;
}
else if (otherArgs) {
// Support multiple callback result values
result = [];
for (var i = 1, l = arguments.length; i < l; i++) {
result.push(arguments[i]);
}
}
else {
result = callbackResult;
}
// Resume fiber if yielding
if (yielded) fiber.run();
}
|
[
"function",
"(",
"callbackError",
",",
"callbackResult",
",",
"otherArgs",
")",
"{",
"// forbid to call twice",
"if",
"(",
"syncCallback",
".",
"called",
")",
"return",
";",
"syncCallback",
".",
"called",
"=",
"true",
";",
"if",
"(",
"callbackError",
")",
"{",
"err",
"=",
"callbackError",
";",
"}",
"else",
"if",
"(",
"otherArgs",
")",
"{",
"// Support multiple callback result values",
"result",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"1",
",",
"l",
"=",
"arguments",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"result",
".",
"push",
"(",
"arguments",
"[",
"i",
"]",
")",
";",
"}",
"}",
"else",
"{",
"result",
"=",
"callbackResult",
";",
"}",
"// Resume fiber if yielding",
"if",
"(",
"yielded",
")",
"fiber",
".",
"run",
"(",
")",
";",
"}"
] |
Create virtual callback
|
[
"Create",
"virtual",
"callback"
] |
e977d68cf34eb207fce162e6a288eef2fb3f22d3
|
https://github.com/ybogdanov/node-sync/blob/e977d68cf34eb207fce162e6a288eef2fb3f22d3/lib/sync.js#L38-L59
|
|
19,844
|
ybogdanov/node-sync
|
lib/sync.js
|
SyncFuture
|
function SyncFuture(timeout)
{
var self = this;
this.resolved = false;
this.fiber = Fiber.current;
this.yielding = false;
this.timeout = timeout;
this.time = null;
this._timeoutId = null;
this._result = undefined;
this._error = null;
this._start = +new Date;
Sync.stat.totalFutures++;
Sync.stat.activeFutures++;
// Create timeout error to capture stack trace correctly
self.timeoutError = new Error();
Error.captureStackTrace(self.timeoutError, arguments.callee);
this.ticket = function Future()
{
// clear timeout if present
if (self._timeoutId) clearTimeout(self._timeoutId);
// measure time
self.time = new Date - self._start;
// forbid to call twice
if (self.resolved) return;
self.resolved = true;
// err returned as first argument
var err = arguments[0];
if (err) {
self._error = err;
}
else {
self._result = arguments[1];
}
// remove self from current fiber
self.fiber.removeFuture(self.ticket);
Sync.stat.activeFutures--;
if (self.yielding && Fiber.current !== self.fiber) {
self.yielding = false;
self.fiber.run();
}
else if (self._error) {
throw self._error;
}
}
this.ticket.__proto__ = this;
this.ticket.yield = function() {
while (!self.resolved) {
self.yielding = true;
if (self.timeout) {
self._timeoutId = setTimeout(function(){
self.timeoutError.message = 'Future function timed out at ' + self.timeout + ' ms';
self.ticket(self.timeoutError);
}, self.timeout)
}
Fiber.yield();
}
if (self._error) throw self._error;
return self._result;
}
this.ticket.__defineGetter__('result', function(){
return this.yield();
});
this.ticket.__defineGetter__('error', function(){
if (self._error) {
return self._error;
}
try {
this.result;
}
catch (e) {
return e;
}
return null;
});
this.ticket.__defineGetter__('timeout', function(){
return self.timeout;
});
this.ticket.__defineSetter__('timeout', function(value){
self.timeout = value;
});
// append self to current fiber
this.fiber.addFuture(this.ticket);
return this.ticket;
}
|
javascript
|
function SyncFuture(timeout)
{
var self = this;
this.resolved = false;
this.fiber = Fiber.current;
this.yielding = false;
this.timeout = timeout;
this.time = null;
this._timeoutId = null;
this._result = undefined;
this._error = null;
this._start = +new Date;
Sync.stat.totalFutures++;
Sync.stat.activeFutures++;
// Create timeout error to capture stack trace correctly
self.timeoutError = new Error();
Error.captureStackTrace(self.timeoutError, arguments.callee);
this.ticket = function Future()
{
// clear timeout if present
if (self._timeoutId) clearTimeout(self._timeoutId);
// measure time
self.time = new Date - self._start;
// forbid to call twice
if (self.resolved) return;
self.resolved = true;
// err returned as first argument
var err = arguments[0];
if (err) {
self._error = err;
}
else {
self._result = arguments[1];
}
// remove self from current fiber
self.fiber.removeFuture(self.ticket);
Sync.stat.activeFutures--;
if (self.yielding && Fiber.current !== self.fiber) {
self.yielding = false;
self.fiber.run();
}
else if (self._error) {
throw self._error;
}
}
this.ticket.__proto__ = this;
this.ticket.yield = function() {
while (!self.resolved) {
self.yielding = true;
if (self.timeout) {
self._timeoutId = setTimeout(function(){
self.timeoutError.message = 'Future function timed out at ' + self.timeout + ' ms';
self.ticket(self.timeoutError);
}, self.timeout)
}
Fiber.yield();
}
if (self._error) throw self._error;
return self._result;
}
this.ticket.__defineGetter__('result', function(){
return this.yield();
});
this.ticket.__defineGetter__('error', function(){
if (self._error) {
return self._error;
}
try {
this.result;
}
catch (e) {
return e;
}
return null;
});
this.ticket.__defineGetter__('timeout', function(){
return self.timeout;
});
this.ticket.__defineSetter__('timeout', function(value){
self.timeout = value;
});
// append self to current fiber
this.fiber.addFuture(this.ticket);
return this.ticket;
}
|
[
"function",
"SyncFuture",
"(",
"timeout",
")",
"{",
"var",
"self",
"=",
"this",
";",
"this",
".",
"resolved",
"=",
"false",
";",
"this",
".",
"fiber",
"=",
"Fiber",
".",
"current",
";",
"this",
".",
"yielding",
"=",
"false",
";",
"this",
".",
"timeout",
"=",
"timeout",
";",
"this",
".",
"time",
"=",
"null",
";",
"this",
".",
"_timeoutId",
"=",
"null",
";",
"this",
".",
"_result",
"=",
"undefined",
";",
"this",
".",
"_error",
"=",
"null",
";",
"this",
".",
"_start",
"=",
"+",
"new",
"Date",
";",
"Sync",
".",
"stat",
".",
"totalFutures",
"++",
";",
"Sync",
".",
"stat",
".",
"activeFutures",
"++",
";",
"// Create timeout error to capture stack trace correctly",
"self",
".",
"timeoutError",
"=",
"new",
"Error",
"(",
")",
";",
"Error",
".",
"captureStackTrace",
"(",
"self",
".",
"timeoutError",
",",
"arguments",
".",
"callee",
")",
";",
"this",
".",
"ticket",
"=",
"function",
"Future",
"(",
")",
"{",
"// clear timeout if present",
"if",
"(",
"self",
".",
"_timeoutId",
")",
"clearTimeout",
"(",
"self",
".",
"_timeoutId",
")",
";",
"// measure time",
"self",
".",
"time",
"=",
"new",
"Date",
"-",
"self",
".",
"_start",
";",
"// forbid to call twice",
"if",
"(",
"self",
".",
"resolved",
")",
"return",
";",
"self",
".",
"resolved",
"=",
"true",
";",
"// err returned as first argument",
"var",
"err",
"=",
"arguments",
"[",
"0",
"]",
";",
"if",
"(",
"err",
")",
"{",
"self",
".",
"_error",
"=",
"err",
";",
"}",
"else",
"{",
"self",
".",
"_result",
"=",
"arguments",
"[",
"1",
"]",
";",
"}",
"// remove self from current fiber",
"self",
".",
"fiber",
".",
"removeFuture",
"(",
"self",
".",
"ticket",
")",
";",
"Sync",
".",
"stat",
".",
"activeFutures",
"--",
";",
"if",
"(",
"self",
".",
"yielding",
"&&",
"Fiber",
".",
"current",
"!==",
"self",
".",
"fiber",
")",
"{",
"self",
".",
"yielding",
"=",
"false",
";",
"self",
".",
"fiber",
".",
"run",
"(",
")",
";",
"}",
"else",
"if",
"(",
"self",
".",
"_error",
")",
"{",
"throw",
"self",
".",
"_error",
";",
"}",
"}",
"this",
".",
"ticket",
".",
"__proto__",
"=",
"this",
";",
"this",
".",
"ticket",
".",
"yield",
"=",
"function",
"(",
")",
"{",
"while",
"(",
"!",
"self",
".",
"resolved",
")",
"{",
"self",
".",
"yielding",
"=",
"true",
";",
"if",
"(",
"self",
".",
"timeout",
")",
"{",
"self",
".",
"_timeoutId",
"=",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"self",
".",
"timeoutError",
".",
"message",
"=",
"'Future function timed out at '",
"+",
"self",
".",
"timeout",
"+",
"' ms'",
";",
"self",
".",
"ticket",
"(",
"self",
".",
"timeoutError",
")",
";",
"}",
",",
"self",
".",
"timeout",
")",
"}",
"Fiber",
".",
"yield",
"(",
")",
";",
"}",
"if",
"(",
"self",
".",
"_error",
")",
"throw",
"self",
".",
"_error",
";",
"return",
"self",
".",
"_result",
";",
"}",
"this",
".",
"ticket",
".",
"__defineGetter__",
"(",
"'result'",
",",
"function",
"(",
")",
"{",
"return",
"this",
".",
"yield",
"(",
")",
";",
"}",
")",
";",
"this",
".",
"ticket",
".",
"__defineGetter__",
"(",
"'error'",
",",
"function",
"(",
")",
"{",
"if",
"(",
"self",
".",
"_error",
")",
"{",
"return",
"self",
".",
"_error",
";",
"}",
"try",
"{",
"this",
".",
"result",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"return",
"e",
";",
"}",
"return",
"null",
";",
"}",
")",
";",
"this",
".",
"ticket",
".",
"__defineGetter__",
"(",
"'timeout'",
",",
"function",
"(",
")",
"{",
"return",
"self",
".",
"timeout",
";",
"}",
")",
";",
"this",
".",
"ticket",
".",
"__defineSetter__",
"(",
"'timeout'",
",",
"function",
"(",
"value",
")",
"{",
"self",
".",
"timeout",
"=",
"value",
";",
"}",
")",
";",
"// append self to current fiber",
"this",
".",
"fiber",
".",
"addFuture",
"(",
"this",
".",
"ticket",
")",
";",
"return",
"this",
".",
"ticket",
";",
"}"
] |
Future object itself
|
[
"Future",
"object",
"itself"
] |
e977d68cf34eb207fce162e6a288eef2fb3f22d3
|
https://github.com/ybogdanov/node-sync/blob/e977d68cf34eb207fce162e6a288eef2fb3f22d3/lib/sync.js#L208-L309
|
19,845
|
icon-project/icon-sdk-js
|
lib/module/scryptsy/index.js
|
smix
|
function smix (B, Bi, r, N, V, XY) {
var Xi = 0
var Yi = 128 * r
var i
B.copy(XY, Xi, Bi, Bi + Yi)
for (i = 0; i < N; i++) {
XY.copy(V, i * Yi, Xi, Xi + Yi)
blockmix_salsa8(XY, Xi, Yi, r)
if (tickCallback) tickCallback()
}
for (i = 0; i < N; i++) {
var offset = Xi + (2 * r - 1) * 64
var j = XY.readUInt32LE(offset) & (N - 1)
blockxor(V, j * Yi, XY, Xi, Yi)
blockmix_salsa8(XY, Xi, Yi, r)
if (tickCallback) tickCallback()
}
XY.copy(B, Bi, Xi, Xi + Yi)
}
|
javascript
|
function smix (B, Bi, r, N, V, XY) {
var Xi = 0
var Yi = 128 * r
var i
B.copy(XY, Xi, Bi, Bi + Yi)
for (i = 0; i < N; i++) {
XY.copy(V, i * Yi, Xi, Xi + Yi)
blockmix_salsa8(XY, Xi, Yi, r)
if (tickCallback) tickCallback()
}
for (i = 0; i < N; i++) {
var offset = Xi + (2 * r - 1) * 64
var j = XY.readUInt32LE(offset) & (N - 1)
blockxor(V, j * Yi, XY, Xi, Yi)
blockmix_salsa8(XY, Xi, Yi, r)
if (tickCallback) tickCallback()
}
XY.copy(B, Bi, Xi, Xi + Yi)
}
|
[
"function",
"smix",
"(",
"B",
",",
"Bi",
",",
"r",
",",
"N",
",",
"V",
",",
"XY",
")",
"{",
"var",
"Xi",
"=",
"0",
"var",
"Yi",
"=",
"128",
"*",
"r",
"var",
"i",
"B",
".",
"copy",
"(",
"XY",
",",
"Xi",
",",
"Bi",
",",
"Bi",
"+",
"Yi",
")",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"N",
";",
"i",
"++",
")",
"{",
"XY",
".",
"copy",
"(",
"V",
",",
"i",
"*",
"Yi",
",",
"Xi",
",",
"Xi",
"+",
"Yi",
")",
"blockmix_salsa8",
"(",
"XY",
",",
"Xi",
",",
"Yi",
",",
"r",
")",
"if",
"(",
"tickCallback",
")",
"tickCallback",
"(",
")",
"}",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"N",
";",
"i",
"++",
")",
"{",
"var",
"offset",
"=",
"Xi",
"+",
"(",
"2",
"*",
"r",
"-",
"1",
")",
"*",
"64",
"var",
"j",
"=",
"XY",
".",
"readUInt32LE",
"(",
"offset",
")",
"&",
"(",
"N",
"-",
"1",
")",
"blockxor",
"(",
"V",
",",
"j",
"*",
"Yi",
",",
"XY",
",",
"Xi",
",",
"Yi",
")",
"blockmix_salsa8",
"(",
"XY",
",",
"Xi",
",",
"Yi",
",",
"r",
")",
"if",
"(",
"tickCallback",
")",
"tickCallback",
"(",
")",
"}",
"XY",
".",
"copy",
"(",
"B",
",",
"Bi",
",",
"Xi",
",",
"Xi",
"+",
"Yi",
")",
"}"
] |
all of these functions are actually moved to the top due to function hoisting
|
[
"all",
"of",
"these",
"functions",
"are",
"actually",
"moved",
"to",
"the",
"top",
"due",
"to",
"function",
"hoisting"
] |
65411d8f6240369dd2a5c23be87fdb22cebc82de
|
https://github.com/icon-project/icon-sdk-js/blob/65411d8f6240369dd2a5c23be87fdb22cebc82de/lib/module/scryptsy/index.js#L52-L76
|
19,846
|
nemtsov/json-mask
|
lib/filter.js
|
_arrayProperties
|
function _arrayProperties (arr, mask) {
var obj = _properties({_: arr}, {_: {
type: 'array',
properties: mask
}})
return obj && obj._
}
|
javascript
|
function _arrayProperties (arr, mask) {
var obj = _properties({_: arr}, {_: {
type: 'array',
properties: mask
}})
return obj && obj._
}
|
[
"function",
"_arrayProperties",
"(",
"arr",
",",
"mask",
")",
"{",
"var",
"obj",
"=",
"_properties",
"(",
"{",
"_",
":",
"arr",
"}",
",",
"{",
"_",
":",
"{",
"type",
":",
"'array'",
",",
"properties",
":",
"mask",
"}",
"}",
")",
"return",
"obj",
"&&",
"obj",
".",
"_",
"}"
] |
wrap array & mask in a temp object; extract results from temp at the end
|
[
"wrap",
"array",
"&",
"mask",
"in",
"a",
"temp",
"object",
";",
"extract",
"results",
"from",
"temp",
"at",
"the",
"end"
] |
9430f0b97d58d43ef33be23e1c7d4dd81e831834
|
https://github.com/nemtsov/json-mask/blob/9430f0b97d58d43ef33be23e1c7d4dd81e831834/lib/filter.js#L13-L19
|
19,847
|
keenwon/elint
|
src/utils/pad-end.js
|
padEnd
|
function padEnd (string, targetLength) {
if (typeof string !== 'string' ||
typeof targetLength !== 'number') {
return string
}
/* istanbul ignore next */
const fn = typeof String.prototype.padEnd === 'function'
? String.prototype.padEnd
: polyfill
return fn.call(string, targetLength)
}
|
javascript
|
function padEnd (string, targetLength) {
if (typeof string !== 'string' ||
typeof targetLength !== 'number') {
return string
}
/* istanbul ignore next */
const fn = typeof String.prototype.padEnd === 'function'
? String.prototype.padEnd
: polyfill
return fn.call(string, targetLength)
}
|
[
"function",
"padEnd",
"(",
"string",
",",
"targetLength",
")",
"{",
"if",
"(",
"typeof",
"string",
"!==",
"'string'",
"||",
"typeof",
"targetLength",
"!==",
"'number'",
")",
"{",
"return",
"string",
"}",
"/* istanbul ignore next */",
"const",
"fn",
"=",
"typeof",
"String",
".",
"prototype",
".",
"padEnd",
"===",
"'function'",
"?",
"String",
".",
"prototype",
".",
"padEnd",
":",
"polyfill",
"return",
"fn",
".",
"call",
"(",
"string",
",",
"targetLength",
")",
"}"
] |
String.prototype.padEnd
@param {string} string string
@param {number} targetLength padding length
@returns {string} string
|
[
"String",
".",
"prototype",
".",
"padEnd"
] |
7bdb0c1a023dcbf305b2752e21f5cadec1fdd64d
|
https://github.com/keenwon/elint/blob/7bdb0c1a023dcbf305b2752e21f5cadec1fdd64d/src/utils/pad-end.js#L27-L39
|
19,848
|
keenwon/elint
|
src/preset/install-scripts.js
|
install
|
function install (presetName) {
debug('run install from scripts, arguments: %o', arguments)
const name = presetName || tryRequire(/elint-preset-/)[0]
if (!name) {
debug('can not fount preset, return')
return
}
const nodeModulesDir = getNodeModulesDir()
const keep = process.env.npm_config_keep || ''
const presetModulePath = path.join(nodeModulesDir, name)
link(presetModulePath, keep)
}
|
javascript
|
function install (presetName) {
debug('run install from scripts, arguments: %o', arguments)
const name = presetName || tryRequire(/elint-preset-/)[0]
if (!name) {
debug('can not fount preset, return')
return
}
const nodeModulesDir = getNodeModulesDir()
const keep = process.env.npm_config_keep || ''
const presetModulePath = path.join(nodeModulesDir, name)
link(presetModulePath, keep)
}
|
[
"function",
"install",
"(",
"presetName",
")",
"{",
"debug",
"(",
"'run install from scripts, arguments: %o'",
",",
"arguments",
")",
"const",
"name",
"=",
"presetName",
"||",
"tryRequire",
"(",
"/",
"elint-preset-",
"/",
")",
"[",
"0",
"]",
"if",
"(",
"!",
"name",
")",
"{",
"debug",
"(",
"'can not fount preset, return'",
")",
"return",
"}",
"const",
"nodeModulesDir",
"=",
"getNodeModulesDir",
"(",
")",
"const",
"keep",
"=",
"process",
".",
"env",
".",
"npm_config_keep",
"||",
"''",
"const",
"presetModulePath",
"=",
"path",
".",
"join",
"(",
"nodeModulesDir",
",",
"name",
")",
"link",
"(",
"presetModulePath",
",",
"keep",
")",
"}"
] |
install preset from npm scripts
@param {string} [presetName] preset name
@returns {void}
|
[
"install",
"preset",
"from",
"npm",
"scripts"
] |
7bdb0c1a023dcbf305b2752e21f5cadec1fdd64d
|
https://github.com/keenwon/elint/blob/7bdb0c1a023dcbf305b2752e21f5cadec1fdd64d/src/preset/install-scripts.js#L15-L30
|
19,849
|
sonnyp/JSON8
|
packages/patch/lib/buildRevertPatch.js
|
reverse
|
function reverse(patch, previous, idx) {
const op = patch.op;
const path = patch.path;
if (op === "copy" || (op === "add" && previous === undefined)) {
if (idx === undefined) return { op: "remove", path: path };
// for item pushed to array with -
const tokens = decode(path);
tokens[tokens.length - 1] = idx.toString();
return { op: "remove", path: encode(tokens) };
}
if (op === "replace") return { op: "replace", path: path, value: previous };
if (op === "move") return { op: "move", path: patch.from, from: path };
if (op === "add" || op === "remove")
return { op: "add", path: path, value: previous };
if (op === "test") return { op: "test", path: path, value: patch.value };
}
|
javascript
|
function reverse(patch, previous, idx) {
const op = patch.op;
const path = patch.path;
if (op === "copy" || (op === "add" && previous === undefined)) {
if (idx === undefined) return { op: "remove", path: path };
// for item pushed to array with -
const tokens = decode(path);
tokens[tokens.length - 1] = idx.toString();
return { op: "remove", path: encode(tokens) };
}
if (op === "replace") return { op: "replace", path: path, value: previous };
if (op === "move") return { op: "move", path: patch.from, from: path };
if (op === "add" || op === "remove")
return { op: "add", path: path, value: previous };
if (op === "test") return { op: "test", path: path, value: patch.value };
}
|
[
"function",
"reverse",
"(",
"patch",
",",
"previous",
",",
"idx",
")",
"{",
"const",
"op",
"=",
"patch",
".",
"op",
";",
"const",
"path",
"=",
"patch",
".",
"path",
";",
"if",
"(",
"op",
"===",
"\"copy\"",
"||",
"(",
"op",
"===",
"\"add\"",
"&&",
"previous",
"===",
"undefined",
")",
")",
"{",
"if",
"(",
"idx",
"===",
"undefined",
")",
"return",
"{",
"op",
":",
"\"remove\"",
",",
"path",
":",
"path",
"}",
";",
"// for item pushed to array with -",
"const",
"tokens",
"=",
"decode",
"(",
"path",
")",
";",
"tokens",
"[",
"tokens",
".",
"length",
"-",
"1",
"]",
"=",
"idx",
".",
"toString",
"(",
")",
";",
"return",
"{",
"op",
":",
"\"remove\"",
",",
"path",
":",
"encode",
"(",
"tokens",
")",
"}",
";",
"}",
"if",
"(",
"op",
"===",
"\"replace\"",
")",
"return",
"{",
"op",
":",
"\"replace\"",
",",
"path",
":",
"path",
",",
"value",
":",
"previous",
"}",
";",
"if",
"(",
"op",
"===",
"\"move\"",
")",
"return",
"{",
"op",
":",
"\"move\"",
",",
"path",
":",
"patch",
".",
"from",
",",
"from",
":",
"path",
"}",
";",
"if",
"(",
"op",
"===",
"\"add\"",
"||",
"op",
"===",
"\"remove\"",
")",
"return",
"{",
"op",
":",
"\"add\"",
",",
"path",
":",
"path",
",",
"value",
":",
"previous",
"}",
";",
"if",
"(",
"op",
"===",
"\"test\"",
")",
"return",
"{",
"op",
":",
"\"test\"",
",",
"path",
":",
"path",
",",
"value",
":",
"patch",
".",
"value",
"}",
";",
"}"
] |
Return the reverse operation to a JSON Patch operation
@param {Object} patch - JSON Patch operation object
@param {Any} previous - previous value for add and replace operations
@param {Number} idx - index of the item for array
@return {Object}
|
[
"Return",
"the",
"reverse",
"operation",
"to",
"a",
"JSON",
"Patch",
"operation"
] |
4bbb0fe612a780a9834c79f2525d4a2267049ebe
|
https://github.com/sonnyp/JSON8/blob/4bbb0fe612a780a9834c79f2525d4a2267049ebe/packages/patch/lib/buildRevertPatch.js#L14-L31
|
19,850
|
sonnyp/JSON8
|
packages/patch/lib/apply.js
|
apply
|
function apply(doc, patch, options) {
if (!Array.isArray(patch))
throw new Error("Invalid argument, patch must be an array");
const done = [];
for (let i = 0, len = patch.length; i < len; i++) {
const p = patch[i];
let r;
try {
r = run(doc, p);
} catch (err) {
// restore document
// does not use ./revert.js because it is a circular dependency
const revertPatch = buildRevertPatch(done);
apply(doc, revertPatch);
throw err;
}
doc = r.doc;
done.push([p, r.previous, r.idx]);
}
const result = { doc: doc };
if (options && typeof options === "object" && options.reversible === true)
result.revert = done;
return result;
}
|
javascript
|
function apply(doc, patch, options) {
if (!Array.isArray(patch))
throw new Error("Invalid argument, patch must be an array");
const done = [];
for (let i = 0, len = patch.length; i < len; i++) {
const p = patch[i];
let r;
try {
r = run(doc, p);
} catch (err) {
// restore document
// does not use ./revert.js because it is a circular dependency
const revertPatch = buildRevertPatch(done);
apply(doc, revertPatch);
throw err;
}
doc = r.doc;
done.push([p, r.previous, r.idx]);
}
const result = { doc: doc };
if (options && typeof options === "object" && options.reversible === true)
result.revert = done;
return result;
}
|
[
"function",
"apply",
"(",
"doc",
",",
"patch",
",",
"options",
")",
"{",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"patch",
")",
")",
"throw",
"new",
"Error",
"(",
"\"Invalid argument, patch must be an array\"",
")",
";",
"const",
"done",
"=",
"[",
"]",
";",
"for",
"(",
"let",
"i",
"=",
"0",
",",
"len",
"=",
"patch",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"const",
"p",
"=",
"patch",
"[",
"i",
"]",
";",
"let",
"r",
";",
"try",
"{",
"r",
"=",
"run",
"(",
"doc",
",",
"p",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"// restore document",
"// does not use ./revert.js because it is a circular dependency",
"const",
"revertPatch",
"=",
"buildRevertPatch",
"(",
"done",
")",
";",
"apply",
"(",
"doc",
",",
"revertPatch",
")",
";",
"throw",
"err",
";",
"}",
"doc",
"=",
"r",
".",
"doc",
";",
"done",
".",
"push",
"(",
"[",
"p",
",",
"r",
".",
"previous",
",",
"r",
".",
"idx",
"]",
")",
";",
"}",
"const",
"result",
"=",
"{",
"doc",
":",
"doc",
"}",
";",
"if",
"(",
"options",
"&&",
"typeof",
"options",
"===",
"\"object\"",
"&&",
"options",
".",
"reversible",
"===",
"true",
")",
"result",
".",
"revert",
"=",
"done",
";",
"return",
"result",
";",
"}"
] |
Apply a JSON Patch to a JSON document
@param {Any} doc - JSON document to apply the patch to
@param {Array} patch - JSON Patch array
@param {Object} options - options
@param {Boolean} options.reversible - return an array to revert
@return {PatchResult}
|
[
"Apply",
"a",
"JSON",
"Patch",
"to",
"a",
"JSON",
"document"
] |
4bbb0fe612a780a9834c79f2525d4a2267049ebe
|
https://github.com/sonnyp/JSON8/blob/4bbb0fe612a780a9834c79f2525d4a2267049ebe/packages/patch/lib/apply.js#L57-L87
|
19,851
|
marook/osm-read
|
lib/proto/index.js
|
Blob
|
function Blob(properties) {
if (properties)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
|
javascript
|
function Blob(properties) {
if (properties)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
|
[
"function",
"Blob",
"(",
"properties",
")",
"{",
"if",
"(",
"properties",
")",
"for",
"(",
"var",
"keys",
"=",
"Object",
".",
"keys",
"(",
"properties",
")",
",",
"i",
"=",
"0",
";",
"i",
"<",
"keys",
".",
"length",
";",
"++",
"i",
")",
"if",
"(",
"properties",
"[",
"keys",
"[",
"i",
"]",
"]",
"!=",
"null",
")",
"this",
"[",
"keys",
"[",
"i",
"]",
"]",
"=",
"properties",
"[",
"keys",
"[",
"i",
"]",
"]",
";",
"}"
] |
Properties of a Blob.
@memberof OSMPBF
@interface IBlob
@property {Uint8Array|null} [raw] Blob raw
@property {number|null} [rawSize] Blob rawSize
@property {Uint8Array|null} [zlibData] Blob zlibData
@property {Uint8Array|null} [lzmaData] Blob lzmaData
@property {Uint8Array|null} [OBSOLETEBzip2Data] Blob OBSOLETEBzip2Data
Constructs a new Blob.
@memberof OSMPBF
@classdesc Represents a Blob.
@implements IBlob
@constructor
@param {OSMPBF.IBlob=} [properties] Properties to set
|
[
"Properties",
"of",
"a",
"Blob",
"."
] |
a1530bfe40bb247af9648c7c86e8e96af6fd0882
|
https://github.com/marook/osm-read/blob/a1530bfe40bb247af9648c7c86e8e96af6fd0882/lib/proto/index.js#L42-L47
|
19,852
|
marook/osm-read
|
lib/proto/index.js
|
BlobHeader
|
function BlobHeader(properties) {
if (properties)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
|
javascript
|
function BlobHeader(properties) {
if (properties)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
|
[
"function",
"BlobHeader",
"(",
"properties",
")",
"{",
"if",
"(",
"properties",
")",
"for",
"(",
"var",
"keys",
"=",
"Object",
".",
"keys",
"(",
"properties",
")",
",",
"i",
"=",
"0",
";",
"i",
"<",
"keys",
".",
"length",
";",
"++",
"i",
")",
"if",
"(",
"properties",
"[",
"keys",
"[",
"i",
"]",
"]",
"!=",
"null",
")",
"this",
"[",
"keys",
"[",
"i",
"]",
"]",
"=",
"properties",
"[",
"keys",
"[",
"i",
"]",
"]",
";",
"}"
] |
Properties of a BlobHeader.
@memberof OSMPBF
@interface IBlobHeader
@property {string} type BlobHeader type
@property {Uint8Array|null} [indexdata] BlobHeader indexdata
@property {number} datasize BlobHeader datasize
Constructs a new BlobHeader.
@memberof OSMPBF
@classdesc Represents a BlobHeader.
@implements IBlobHeader
@constructor
@param {OSMPBF.IBlobHeader=} [properties] Properties to set
|
[
"Properties",
"of",
"a",
"BlobHeader",
"."
] |
a1530bfe40bb247af9648c7c86e8e96af6fd0882
|
https://github.com/marook/osm-read/blob/a1530bfe40bb247af9648c7c86e8e96af6fd0882/lib/proto/index.js#L352-L357
|
19,853
|
marook/osm-read
|
lib/proto/index.js
|
HeaderBlock
|
function HeaderBlock(properties) {
this.requiredFeatures = [];
this.optionalFeatures = [];
if (properties)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
|
javascript
|
function HeaderBlock(properties) {
this.requiredFeatures = [];
this.optionalFeatures = [];
if (properties)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
|
[
"function",
"HeaderBlock",
"(",
"properties",
")",
"{",
"this",
".",
"requiredFeatures",
"=",
"[",
"]",
";",
"this",
".",
"optionalFeatures",
"=",
"[",
"]",
";",
"if",
"(",
"properties",
")",
"for",
"(",
"var",
"keys",
"=",
"Object",
".",
"keys",
"(",
"properties",
")",
",",
"i",
"=",
"0",
";",
"i",
"<",
"keys",
".",
"length",
";",
"++",
"i",
")",
"if",
"(",
"properties",
"[",
"keys",
"[",
"i",
"]",
"]",
"!=",
"null",
")",
"this",
"[",
"keys",
"[",
"i",
"]",
"]",
"=",
"properties",
"[",
"keys",
"[",
"i",
"]",
"]",
";",
"}"
] |
Properties of a HeaderBlock.
@memberof OSMPBF
@interface IHeaderBlock
@property {OSMPBF.IHeaderBBox|null} [bbox] HeaderBlock bbox
@property {Array.<string>|null} [requiredFeatures] HeaderBlock requiredFeatures
@property {Array.<string>|null} [optionalFeatures] HeaderBlock optionalFeatures
@property {string|null} [writingprogram] HeaderBlock writingprogram
@property {string|null} [source] HeaderBlock source
@property {number|Long|null} [osmosisReplicationTimestamp] HeaderBlock osmosisReplicationTimestamp
@property {number|Long|null} [osmosisReplicationSequenceNumber] HeaderBlock osmosisReplicationSequenceNumber
@property {string|null} [osmosisReplicationBaseUrl] HeaderBlock osmosisReplicationBaseUrl
Constructs a new HeaderBlock.
@memberof OSMPBF
@classdesc Represents a HeaderBlock.
@implements IHeaderBlock
@constructor
@param {OSMPBF.IHeaderBlock=} [properties] Properties to set
|
[
"Properties",
"of",
"a",
"HeaderBlock",
"."
] |
a1530bfe40bb247af9648c7c86e8e96af6fd0882
|
https://github.com/marook/osm-read/blob/a1530bfe40bb247af9648c7c86e8e96af6fd0882/lib/proto/index.js#L598-L605
|
19,854
|
marook/osm-read
|
lib/proto/index.js
|
HeaderBBox
|
function HeaderBBox(properties) {
if (properties)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
|
javascript
|
function HeaderBBox(properties) {
if (properties)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
|
[
"function",
"HeaderBBox",
"(",
"properties",
")",
"{",
"if",
"(",
"properties",
")",
"for",
"(",
"var",
"keys",
"=",
"Object",
".",
"keys",
"(",
"properties",
")",
",",
"i",
"=",
"0",
";",
"i",
"<",
"keys",
".",
"length",
";",
"++",
"i",
")",
"if",
"(",
"properties",
"[",
"keys",
"[",
"i",
"]",
"]",
"!=",
"null",
")",
"this",
"[",
"keys",
"[",
"i",
"]",
"]",
"=",
"properties",
"[",
"keys",
"[",
"i",
"]",
"]",
";",
"}"
] |
Properties of a HeaderBBox.
@memberof OSMPBF
@interface IHeaderBBox
@property {number|Long} left HeaderBBox left
@property {number|Long} right HeaderBBox right
@property {number|Long} top HeaderBBox top
@property {number|Long} bottom HeaderBBox bottom
Constructs a new HeaderBBox.
@memberof OSMPBF
@classdesc Represents a HeaderBBox.
@implements IHeaderBBox
@constructor
@param {OSMPBF.IHeaderBBox=} [properties] Properties to set
|
[
"Properties",
"of",
"a",
"HeaderBBox",
"."
] |
a1530bfe40bb247af9648c7c86e8e96af6fd0882
|
https://github.com/marook/osm-read/blob/a1530bfe40bb247af9648c7c86e8e96af6fd0882/lib/proto/index.js#L1003-L1008
|
19,855
|
marook/osm-read
|
lib/proto/index.js
|
PrimitiveBlock
|
function PrimitiveBlock(properties) {
this.primitivegroup = [];
if (properties)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
|
javascript
|
function PrimitiveBlock(properties) {
this.primitivegroup = [];
if (properties)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
|
[
"function",
"PrimitiveBlock",
"(",
"properties",
")",
"{",
"this",
".",
"primitivegroup",
"=",
"[",
"]",
";",
"if",
"(",
"properties",
")",
"for",
"(",
"var",
"keys",
"=",
"Object",
".",
"keys",
"(",
"properties",
")",
",",
"i",
"=",
"0",
";",
"i",
"<",
"keys",
".",
"length",
";",
"++",
"i",
")",
"if",
"(",
"properties",
"[",
"keys",
"[",
"i",
"]",
"]",
"!=",
"null",
")",
"this",
"[",
"keys",
"[",
"i",
"]",
"]",
"=",
"properties",
"[",
"keys",
"[",
"i",
"]",
"]",
";",
"}"
] |
Properties of a PrimitiveBlock.
@memberof OSMPBF
@interface IPrimitiveBlock
@property {OSMPBF.IStringTable} stringtable PrimitiveBlock stringtable
@property {Array.<OSMPBF.IPrimitiveGroup>|null} [primitivegroup] PrimitiveBlock primitivegroup
@property {number|null} [granularity] PrimitiveBlock granularity
@property {number|Long|null} [latOffset] PrimitiveBlock latOffset
@property {number|Long|null} [lonOffset] PrimitiveBlock lonOffset
@property {number|null} [dateGranularity] PrimitiveBlock dateGranularity
Constructs a new PrimitiveBlock.
@memberof OSMPBF
@classdesc Represents a PrimitiveBlock.
@implements IPrimitiveBlock
@constructor
@param {OSMPBF.IPrimitiveBlock=} [properties] Properties to set
|
[
"Properties",
"of",
"a",
"PrimitiveBlock",
"."
] |
a1530bfe40bb247af9648c7c86e8e96af6fd0882
|
https://github.com/marook/osm-read/blob/a1530bfe40bb247af9648c7c86e8e96af6fd0882/lib/proto/index.js#L1315-L1321
|
19,856
|
marook/osm-read
|
lib/proto/index.js
|
PrimitiveGroup
|
function PrimitiveGroup(properties) {
this.nodes = [];
this.ways = [];
this.relations = [];
this.changesets = [];
if (properties)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
|
javascript
|
function PrimitiveGroup(properties) {
this.nodes = [];
this.ways = [];
this.relations = [];
this.changesets = [];
if (properties)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
|
[
"function",
"PrimitiveGroup",
"(",
"properties",
")",
"{",
"this",
".",
"nodes",
"=",
"[",
"]",
";",
"this",
".",
"ways",
"=",
"[",
"]",
";",
"this",
".",
"relations",
"=",
"[",
"]",
";",
"this",
".",
"changesets",
"=",
"[",
"]",
";",
"if",
"(",
"properties",
")",
"for",
"(",
"var",
"keys",
"=",
"Object",
".",
"keys",
"(",
"properties",
")",
",",
"i",
"=",
"0",
";",
"i",
"<",
"keys",
".",
"length",
";",
"++",
"i",
")",
"if",
"(",
"properties",
"[",
"keys",
"[",
"i",
"]",
"]",
"!=",
"null",
")",
"this",
"[",
"keys",
"[",
"i",
"]",
"]",
"=",
"properties",
"[",
"keys",
"[",
"i",
"]",
"]",
";",
"}"
] |
Properties of a PrimitiveGroup.
@memberof OSMPBF
@interface IPrimitiveGroup
@property {Array.<OSMPBF.INode>|null} [nodes] PrimitiveGroup nodes
@property {OSMPBF.IDenseNodes|null} [dense] PrimitiveGroup dense
@property {Array.<OSMPBF.IWay>|null} [ways] PrimitiveGroup ways
@property {Array.<OSMPBF.IRelation>|null} [relations] PrimitiveGroup relations
@property {Array.<OSMPBF.IChangeSet>|null} [changesets] PrimitiveGroup changesets
Constructs a new PrimitiveGroup.
@memberof OSMPBF
@classdesc Represents a PrimitiveGroup.
@implements IPrimitiveGroup
@constructor
@param {OSMPBF.IPrimitiveGroup=} [properties] Properties to set
|
[
"Properties",
"of",
"a",
"PrimitiveGroup",
"."
] |
a1530bfe40bb247af9648c7c86e8e96af6fd0882
|
https://github.com/marook/osm-read/blob/a1530bfe40bb247af9648c7c86e8e96af6fd0882/lib/proto/index.js#L1668-L1677
|
19,857
|
marook/osm-read
|
lib/proto/index.js
|
DenseInfo
|
function DenseInfo(properties) {
this.version = [];
this.timestamp = [];
this.changeset = [];
this.uid = [];
this.userSid = [];
this.visible = [];
if (properties)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
|
javascript
|
function DenseInfo(properties) {
this.version = [];
this.timestamp = [];
this.changeset = [];
this.uid = [];
this.userSid = [];
this.visible = [];
if (properties)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
|
[
"function",
"DenseInfo",
"(",
"properties",
")",
"{",
"this",
".",
"version",
"=",
"[",
"]",
";",
"this",
".",
"timestamp",
"=",
"[",
"]",
";",
"this",
".",
"changeset",
"=",
"[",
"]",
";",
"this",
".",
"uid",
"=",
"[",
"]",
";",
"this",
".",
"userSid",
"=",
"[",
"]",
";",
"this",
".",
"visible",
"=",
"[",
"]",
";",
"if",
"(",
"properties",
")",
"for",
"(",
"var",
"keys",
"=",
"Object",
".",
"keys",
"(",
"properties",
")",
",",
"i",
"=",
"0",
";",
"i",
"<",
"keys",
".",
"length",
";",
"++",
"i",
")",
"if",
"(",
"properties",
"[",
"keys",
"[",
"i",
"]",
"]",
"!=",
"null",
")",
"this",
"[",
"keys",
"[",
"i",
"]",
"]",
"=",
"properties",
"[",
"keys",
"[",
"i",
"]",
"]",
";",
"}"
] |
Properties of a DenseInfo.
@memberof OSMPBF
@interface IDenseInfo
@property {Array.<number>|null} [version] DenseInfo version
@property {Array.<number|Long>|null} [timestamp] DenseInfo timestamp
@property {Array.<number|Long>|null} [changeset] DenseInfo changeset
@property {Array.<number>|null} [uid] DenseInfo uid
@property {Array.<number>|null} [userSid] DenseInfo userSid
@property {Array.<boolean>|null} [visible] DenseInfo visible
Constructs a new DenseInfo.
@memberof OSMPBF
@classdesc Optional metadata that may be included into each primitive. Special dense format used in DenseNodes.
@implements IDenseInfo
@constructor
@param {OSMPBF.IDenseInfo=} [properties] Properties to set
|
[
"Properties",
"of",
"a",
"DenseInfo",
"."
] |
a1530bfe40bb247af9648c7c86e8e96af6fd0882
|
https://github.com/marook/osm-read/blob/a1530bfe40bb247af9648c7c86e8e96af6fd0882/lib/proto/index.js#L2570-L2581
|
19,858
|
marook/osm-read
|
lib/proto/index.js
|
ChangeSet
|
function ChangeSet(properties) {
if (properties)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
|
javascript
|
function ChangeSet(properties) {
if (properties)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
|
[
"function",
"ChangeSet",
"(",
"properties",
")",
"{",
"if",
"(",
"properties",
")",
"for",
"(",
"var",
"keys",
"=",
"Object",
".",
"keys",
"(",
"properties",
")",
",",
"i",
"=",
"0",
";",
"i",
"<",
"keys",
".",
"length",
";",
"++",
"i",
")",
"if",
"(",
"properties",
"[",
"keys",
"[",
"i",
"]",
"]",
"!=",
"null",
")",
"this",
"[",
"keys",
"[",
"i",
"]",
"]",
"=",
"properties",
"[",
"keys",
"[",
"i",
"]",
"]",
";",
"}"
] |
Properties of a ChangeSet.
@memberof OSMPBF
@interface IChangeSet
@property {number|Long} id ChangeSet id
Constructs a new ChangeSet.
@memberof OSMPBF
@classdesc Represents a ChangeSet.
@implements IChangeSet
@constructor
@param {OSMPBF.IChangeSet=} [properties] Properties to set
|
[
"Properties",
"of",
"a",
"ChangeSet",
"."
] |
a1530bfe40bb247af9648c7c86e8e96af6fd0882
|
https://github.com/marook/osm-read/blob/a1530bfe40bb247af9648c7c86e8e96af6fd0882/lib/proto/index.js#L3027-L3032
|
19,859
|
marook/osm-read
|
lib/proto/index.js
|
Node
|
function Node(properties) {
this.keys = [];
this.vals = [];
if (properties)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
|
javascript
|
function Node(properties) {
this.keys = [];
this.vals = [];
if (properties)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
|
[
"function",
"Node",
"(",
"properties",
")",
"{",
"this",
".",
"keys",
"=",
"[",
"]",
";",
"this",
".",
"vals",
"=",
"[",
"]",
";",
"if",
"(",
"properties",
")",
"for",
"(",
"var",
"keys",
"=",
"Object",
".",
"keys",
"(",
"properties",
")",
",",
"i",
"=",
"0",
";",
"i",
"<",
"keys",
".",
"length",
";",
"++",
"i",
")",
"if",
"(",
"properties",
"[",
"keys",
"[",
"i",
"]",
"]",
"!=",
"null",
")",
"this",
"[",
"keys",
"[",
"i",
"]",
"]",
"=",
"properties",
"[",
"keys",
"[",
"i",
"]",
"]",
";",
"}"
] |
Properties of a Node.
@memberof OSMPBF
@interface INode
@property {number|Long} id Node id
@property {Array.<number>|null} [keys] Node keys
@property {Array.<number>|null} [vals] Node vals
@property {OSMPBF.IInfo|null} [info] Node info
@property {number|Long} lat Node lat
@property {number|Long} lon Node lon
Constructs a new Node.
@memberof OSMPBF
@classdesc Represents a Node.
@implements INode
@constructor
@param {OSMPBF.INode=} [properties] Properties to set
|
[
"Properties",
"of",
"a",
"Node",
"."
] |
a1530bfe40bb247af9648c7c86e8e96af6fd0882
|
https://github.com/marook/osm-read/blob/a1530bfe40bb247af9648c7c86e8e96af6fd0882/lib/proto/index.js#L3233-L3240
|
19,860
|
marook/osm-read
|
lib/proto/index.js
|
DenseNodes
|
function DenseNodes(properties) {
this.id = [];
this.lat = [];
this.lon = [];
this.keysVals = [];
if (properties)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
|
javascript
|
function DenseNodes(properties) {
this.id = [];
this.lat = [];
this.lon = [];
this.keysVals = [];
if (properties)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
|
[
"function",
"DenseNodes",
"(",
"properties",
")",
"{",
"this",
".",
"id",
"=",
"[",
"]",
";",
"this",
".",
"lat",
"=",
"[",
"]",
";",
"this",
".",
"lon",
"=",
"[",
"]",
";",
"this",
".",
"keysVals",
"=",
"[",
"]",
";",
"if",
"(",
"properties",
")",
"for",
"(",
"var",
"keys",
"=",
"Object",
".",
"keys",
"(",
"properties",
")",
",",
"i",
"=",
"0",
";",
"i",
"<",
"keys",
".",
"length",
";",
"++",
"i",
")",
"if",
"(",
"properties",
"[",
"keys",
"[",
"i",
"]",
"]",
"!=",
"null",
")",
"this",
"[",
"keys",
"[",
"i",
"]",
"]",
"=",
"properties",
"[",
"keys",
"[",
"i",
"]",
"]",
";",
"}"
] |
Properties of a DenseNodes.
@memberof OSMPBF
@interface IDenseNodes
@property {Array.<number|Long>|null} [id] DenseNodes id
@property {OSMPBF.IDenseInfo|null} [denseinfo] DenseNodes denseinfo
@property {Array.<number|Long>|null} [lat] DenseNodes lat
@property {Array.<number|Long>|null} [lon] DenseNodes lon
@property {Array.<number>|null} [keysVals] DenseNodes keysVals
Constructs a new DenseNodes.
@memberof OSMPBF
@classdesc Represents a DenseNodes.
@implements IDenseNodes
@constructor
@param {OSMPBF.IDenseNodes=} [properties] Properties to set
|
[
"Properties",
"of",
"a",
"DenseNodes",
"."
] |
a1530bfe40bb247af9648c7c86e8e96af6fd0882
|
https://github.com/marook/osm-read/blob/a1530bfe40bb247af9648c7c86e8e96af6fd0882/lib/proto/index.js#L3627-L3636
|
19,861
|
marook/osm-read
|
lib/proto/index.js
|
Way
|
function Way(properties) {
this.keys = [];
this.vals = [];
this.refs = [];
if (properties)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
|
javascript
|
function Way(properties) {
this.keys = [];
this.vals = [];
this.refs = [];
if (properties)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
|
[
"function",
"Way",
"(",
"properties",
")",
"{",
"this",
".",
"keys",
"=",
"[",
"]",
";",
"this",
".",
"vals",
"=",
"[",
"]",
";",
"this",
".",
"refs",
"=",
"[",
"]",
";",
"if",
"(",
"properties",
")",
"for",
"(",
"var",
"keys",
"=",
"Object",
".",
"keys",
"(",
"properties",
")",
",",
"i",
"=",
"0",
";",
"i",
"<",
"keys",
".",
"length",
";",
"++",
"i",
")",
"if",
"(",
"properties",
"[",
"keys",
"[",
"i",
"]",
"]",
"!=",
"null",
")",
"this",
"[",
"keys",
"[",
"i",
"]",
"]",
"=",
"properties",
"[",
"keys",
"[",
"i",
"]",
"]",
";",
"}"
] |
Properties of a Way.
@memberof OSMPBF
@interface IWay
@property {number|Long} id Way id
@property {Array.<number>|null} [keys] Way keys
@property {Array.<number>|null} [vals] Way vals
@property {OSMPBF.IInfo|null} [info] Way info
@property {Array.<number|Long>|null} [refs] Way refs
Constructs a new Way.
@memberof OSMPBF
@classdesc Represents a Way.
@implements IWay
@constructor
@param {OSMPBF.IWay=} [properties] Properties to set
|
[
"Properties",
"of",
"a",
"Way",
"."
] |
a1530bfe40bb247af9648c7c86e8e96af6fd0882
|
https://github.com/marook/osm-read/blob/a1530bfe40bb247af9648c7c86e8e96af6fd0882/lib/proto/index.js#L4035-L4043
|
19,862
|
marook/osm-read
|
lib/proto/index.js
|
Relation
|
function Relation(properties) {
this.keys = [];
this.vals = [];
this.rolesSid = [];
this.memids = [];
this.types = [];
if (properties)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
|
javascript
|
function Relation(properties) {
this.keys = [];
this.vals = [];
this.rolesSid = [];
this.memids = [];
this.types = [];
if (properties)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
|
[
"function",
"Relation",
"(",
"properties",
")",
"{",
"this",
".",
"keys",
"=",
"[",
"]",
";",
"this",
".",
"vals",
"=",
"[",
"]",
";",
"this",
".",
"rolesSid",
"=",
"[",
"]",
";",
"this",
".",
"memids",
"=",
"[",
"]",
";",
"this",
".",
"types",
"=",
"[",
"]",
";",
"if",
"(",
"properties",
")",
"for",
"(",
"var",
"keys",
"=",
"Object",
".",
"keys",
"(",
"properties",
")",
",",
"i",
"=",
"0",
";",
"i",
"<",
"keys",
".",
"length",
";",
"++",
"i",
")",
"if",
"(",
"properties",
"[",
"keys",
"[",
"i",
"]",
"]",
"!=",
"null",
")",
"this",
"[",
"keys",
"[",
"i",
"]",
"]",
"=",
"properties",
"[",
"keys",
"[",
"i",
"]",
"]",
";",
"}"
] |
Properties of a Relation.
@memberof OSMPBF
@interface IRelation
@property {number|Long} id Relation id
@property {Array.<number>|null} [keys] Relation keys
@property {Array.<number>|null} [vals] Relation vals
@property {OSMPBF.IInfo|null} [info] Relation info
@property {Array.<number>|null} [rolesSid] Relation rolesSid
@property {Array.<number|Long>|null} [memids] Relation memids
@property {Array.<OSMPBF.Relation.MemberType>|null} [types] Relation types
Constructs a new Relation.
@memberof OSMPBF
@classdesc Represents a Relation.
@implements IRelation
@constructor
@param {OSMPBF.IRelation=} [properties] Properties to set
|
[
"Properties",
"of",
"a",
"Relation",
"."
] |
a1530bfe40bb247af9648c7c86e8e96af6fd0882
|
https://github.com/marook/osm-read/blob/a1530bfe40bb247af9648c7c86e8e96af6fd0882/lib/proto/index.js#L4416-L4426
|
19,863
|
marook/osm-read
|
osm-read-pbf.js
|
inquire
|
function inquire(moduleName) {
try {
var mod = eval("quire".replace(/^/,"re"))(moduleName); // eslint-disable-line no-eval
if (mod && (mod.length || Object.keys(mod).length))
return mod;
} catch (e) {} // eslint-disable-line no-empty
return null;
}
|
javascript
|
function inquire(moduleName) {
try {
var mod = eval("quire".replace(/^/,"re"))(moduleName); // eslint-disable-line no-eval
if (mod && (mod.length || Object.keys(mod).length))
return mod;
} catch (e) {} // eslint-disable-line no-empty
return null;
}
|
[
"function",
"inquire",
"(",
"moduleName",
")",
"{",
"try",
"{",
"var",
"mod",
"=",
"eval",
"(",
"\"quire\"",
".",
"replace",
"(",
"/",
"^",
"/",
",",
"\"re\"",
")",
")",
"(",
"moduleName",
")",
";",
"// eslint-disable-line no-eval\r",
"if",
"(",
"mod",
"&&",
"(",
"mod",
".",
"length",
"||",
"Object",
".",
"keys",
"(",
"mod",
")",
".",
"length",
")",
")",
"return",
"mod",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"}",
"// eslint-disable-line no-empty\r",
"return",
"null",
";",
"}"
] |
Requires a module only if available.
@memberof util
@param {string} moduleName Module to require
@returns {?Object} Required module if available and not empty, otherwise `null`
|
[
"Requires",
"a",
"module",
"only",
"if",
"available",
"."
] |
a1530bfe40bb247af9648c7c86e8e96af6fd0882
|
https://github.com/marook/osm-read/blob/a1530bfe40bb247af9648c7c86e8e96af6fd0882/osm-read-pbf.js#L6387-L6394
|
19,864
|
marook/osm-read
|
osm-read-pbf.js
|
merge
|
function merge(dst, src, ifNotSet) { // used by converters
for (var keys = Object.keys(src), i = 0; i < keys.length; ++i)
if (dst[keys[i]] === undefined || !ifNotSet)
dst[keys[i]] = src[keys[i]];
return dst;
}
|
javascript
|
function merge(dst, src, ifNotSet) { // used by converters
for (var keys = Object.keys(src), i = 0; i < keys.length; ++i)
if (dst[keys[i]] === undefined || !ifNotSet)
dst[keys[i]] = src[keys[i]];
return dst;
}
|
[
"function",
"merge",
"(",
"dst",
",",
"src",
",",
"ifNotSet",
")",
"{",
"// used by converters\r",
"for",
"(",
"var",
"keys",
"=",
"Object",
".",
"keys",
"(",
"src",
")",
",",
"i",
"=",
"0",
";",
"i",
"<",
"keys",
".",
"length",
";",
"++",
"i",
")",
"if",
"(",
"dst",
"[",
"keys",
"[",
"i",
"]",
"]",
"===",
"undefined",
"||",
"!",
"ifNotSet",
")",
"dst",
"[",
"keys",
"[",
"i",
"]",
"]",
"=",
"src",
"[",
"keys",
"[",
"i",
"]",
"]",
";",
"return",
"dst",
";",
"}"
] |
Merges the properties of the source object into the destination object.
@memberof util
@param {Object.<string,*>} dst Destination object
@param {Object.<string,*>} src Source object
@param {boolean} [ifNotSet=false] Merges only if the key is not already set
@returns {Object.<string,*>} Destination object
|
[
"Merges",
"the",
"properties",
"of",
"the",
"source",
"object",
"into",
"the",
"destination",
"object",
"."
] |
a1530bfe40bb247af9648c7c86e8e96af6fd0882
|
https://github.com/marook/osm-read/blob/a1530bfe40bb247af9648c7c86e8e96af6fd0882/osm-read-pbf.js#L7684-L7689
|
19,865
|
ipfs/js-ipfs-merkle-dag
|
src/dag-node.js
|
toProtoBuf
|
function toProtoBuf (node) {
const pbn = {}
if (node.data && node.data.length > 0) {
pbn.Data = node.data
} else {
pbn.Data = null // new Buffer(0)
}
if (node.links.length > 0) {
pbn.Links = node.links.map((link) => {
return {
Hash: link.hash,
Name: link.name,
Tsize: link.size
}
})
} else {
pbn.Links = null
}
return pbn
}
|
javascript
|
function toProtoBuf (node) {
const pbn = {}
if (node.data && node.data.length > 0) {
pbn.Data = node.data
} else {
pbn.Data = null // new Buffer(0)
}
if (node.links.length > 0) {
pbn.Links = node.links.map((link) => {
return {
Hash: link.hash,
Name: link.name,
Tsize: link.size
}
})
} else {
pbn.Links = null
}
return pbn
}
|
[
"function",
"toProtoBuf",
"(",
"node",
")",
"{",
"const",
"pbn",
"=",
"{",
"}",
"if",
"(",
"node",
".",
"data",
"&&",
"node",
".",
"data",
".",
"length",
">",
"0",
")",
"{",
"pbn",
".",
"Data",
"=",
"node",
".",
"data",
"}",
"else",
"{",
"pbn",
".",
"Data",
"=",
"null",
"// new Buffer(0)",
"}",
"if",
"(",
"node",
".",
"links",
".",
"length",
">",
"0",
")",
"{",
"pbn",
".",
"Links",
"=",
"node",
".",
"links",
".",
"map",
"(",
"(",
"link",
")",
"=>",
"{",
"return",
"{",
"Hash",
":",
"link",
".",
"hash",
",",
"Name",
":",
"link",
".",
"name",
",",
"Tsize",
":",
"link",
".",
"size",
"}",
"}",
")",
"}",
"else",
"{",
"pbn",
".",
"Links",
"=",
"null",
"}",
"return",
"pbn",
"}"
] |
Helper method to get a protobuf object equivalent
|
[
"Helper",
"method",
"to",
"get",
"a",
"protobuf",
"object",
"equivalent"
] |
d510f2eae1d4817feb2d9aecb02918b4e06313a9
|
https://github.com/ipfs/js-ipfs-merkle-dag/blob/d510f2eae1d4817feb2d9aecb02918b4e06313a9/src/dag-node.js#L19-L41
|
19,866
|
JerryC8080/Memeye
|
src/dashboard/index.js
|
bindIndicators
|
function bindIndicators(indicator) {
// Parent process will send three type of data
const collectorHandler = {
'process': function (value) {
indicator.rss = value.rss;
indicator.heapTotal = value.heapTotal;
indicator.heapUsed = value.heapUsed;
},
'os': function (value) {
indicator.totalMem = value.totalMem;
indicator.freeMem = value.freeMem;
indicator.cpus = value.cpus;
},
'v8': function (value) {
indicator.newSpace = value.heapSpace[0];
indicator.oldSpace = value.heapSpace[1];
indicator.codeSpace = value.heapSpace[2];
indicator.mapSpace = value.heapSpace[3];
indicator.largeObjectSpace = value.heapSpace[4];
}
}
process.on('message', (msg) => {
if (Array.isArray(msg)) {
msg.forEach((data) => {
let handler = collectorHandler[data.type];
if (typeof handler === 'function') collectorHandler[data.type](data.value);
});
}
});
}
|
javascript
|
function bindIndicators(indicator) {
// Parent process will send three type of data
const collectorHandler = {
'process': function (value) {
indicator.rss = value.rss;
indicator.heapTotal = value.heapTotal;
indicator.heapUsed = value.heapUsed;
},
'os': function (value) {
indicator.totalMem = value.totalMem;
indicator.freeMem = value.freeMem;
indicator.cpus = value.cpus;
},
'v8': function (value) {
indicator.newSpace = value.heapSpace[0];
indicator.oldSpace = value.heapSpace[1];
indicator.codeSpace = value.heapSpace[2];
indicator.mapSpace = value.heapSpace[3];
indicator.largeObjectSpace = value.heapSpace[4];
}
}
process.on('message', (msg) => {
if (Array.isArray(msg)) {
msg.forEach((data) => {
let handler = collectorHandler[data.type];
if (typeof handler === 'function') collectorHandler[data.type](data.value);
});
}
});
}
|
[
"function",
"bindIndicators",
"(",
"indicator",
")",
"{",
"// Parent process will send three type of data",
"const",
"collectorHandler",
"=",
"{",
"'process'",
":",
"function",
"(",
"value",
")",
"{",
"indicator",
".",
"rss",
"=",
"value",
".",
"rss",
";",
"indicator",
".",
"heapTotal",
"=",
"value",
".",
"heapTotal",
";",
"indicator",
".",
"heapUsed",
"=",
"value",
".",
"heapUsed",
";",
"}",
",",
"'os'",
":",
"function",
"(",
"value",
")",
"{",
"indicator",
".",
"totalMem",
"=",
"value",
".",
"totalMem",
";",
"indicator",
".",
"freeMem",
"=",
"value",
".",
"freeMem",
";",
"indicator",
".",
"cpus",
"=",
"value",
".",
"cpus",
";",
"}",
",",
"'v8'",
":",
"function",
"(",
"value",
")",
"{",
"indicator",
".",
"newSpace",
"=",
"value",
".",
"heapSpace",
"[",
"0",
"]",
";",
"indicator",
".",
"oldSpace",
"=",
"value",
".",
"heapSpace",
"[",
"1",
"]",
";",
"indicator",
".",
"codeSpace",
"=",
"value",
".",
"heapSpace",
"[",
"2",
"]",
";",
"indicator",
".",
"mapSpace",
"=",
"value",
".",
"heapSpace",
"[",
"3",
"]",
";",
"indicator",
".",
"largeObjectSpace",
"=",
"value",
".",
"heapSpace",
"[",
"4",
"]",
";",
"}",
"}",
"process",
".",
"on",
"(",
"'message'",
",",
"(",
"msg",
")",
"=>",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"msg",
")",
")",
"{",
"msg",
".",
"forEach",
"(",
"(",
"data",
")",
"=>",
"{",
"let",
"handler",
"=",
"collectorHandler",
"[",
"data",
".",
"type",
"]",
";",
"if",
"(",
"typeof",
"handler",
"===",
"'function'",
")",
"collectorHandler",
"[",
"data",
".",
"type",
"]",
"(",
"data",
".",
"value",
")",
";",
"}",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Bind process IPC channel to indicator
|
[
"Bind",
"process",
"IPC",
"channel",
"to",
"indicator"
] |
139f6d46ef74929a48fa6a00b01219b8aefa0fe6
|
https://github.com/JerryC8080/Memeye/blob/139f6d46ef74929a48fa6a00b01219b8aefa0fe6/src/dashboard/index.js#L35-L65
|
19,867
|
JerryC8080/Memeye
|
src/dashboard/index.js
|
bindSocket
|
function bindSocket(io, indicator) {
Object.keys(indicator.watch).forEach((key) => {
let eventName = indicator.watch[key];
indicator.on(eventName, (msg) => io.emit(eventName, msg));
});
}
|
javascript
|
function bindSocket(io, indicator) {
Object.keys(indicator.watch).forEach((key) => {
let eventName = indicator.watch[key];
indicator.on(eventName, (msg) => io.emit(eventName, msg));
});
}
|
[
"function",
"bindSocket",
"(",
"io",
",",
"indicator",
")",
"{",
"Object",
".",
"keys",
"(",
"indicator",
".",
"watch",
")",
".",
"forEach",
"(",
"(",
"key",
")",
"=>",
"{",
"let",
"eventName",
"=",
"indicator",
".",
"watch",
"[",
"key",
"]",
";",
"indicator",
".",
"on",
"(",
"eventName",
",",
"(",
"msg",
")",
"=>",
"io",
".",
"emit",
"(",
"eventName",
",",
"msg",
")",
")",
";",
"}",
")",
";",
"}"
] |
Bind indicators to socket
|
[
"Bind",
"indicators",
"to",
"socket"
] |
139f6d46ef74929a48fa6a00b01219b8aefa0fe6
|
https://github.com/JerryC8080/Memeye/blob/139f6d46ef74929a48fa6a00b01219b8aefa0fe6/src/dashboard/index.js#L68-L73
|
19,868
|
fzaninotto/DependencyWheel
|
js/d3.dependencyWheel.js
|
function(opacity) {
return function(g, i) {
gEnter.selectAll(".chord")
.filter(function(d) {
return d.source.index != i && d.target.index != i;
})
.transition()
.style("opacity", opacity);
var groups = [];
gEnter.selectAll(".chord")
.filter(function(d) {
if (d.source.index == i) {
groups.push(d.target.index);
}
if (d.target.index == i) {
groups.push(d.source.index);
}
});
groups.push(i);
var length = groups.length;
gEnter.selectAll('.group')
.filter(function(d) {
for (var i = 0; i < length; i++) {
if(groups[i] == d.index) return false;
}
return true;
})
.transition()
.style("opacity", opacity);
};
}
|
javascript
|
function(opacity) {
return function(g, i) {
gEnter.selectAll(".chord")
.filter(function(d) {
return d.source.index != i && d.target.index != i;
})
.transition()
.style("opacity", opacity);
var groups = [];
gEnter.selectAll(".chord")
.filter(function(d) {
if (d.source.index == i) {
groups.push(d.target.index);
}
if (d.target.index == i) {
groups.push(d.source.index);
}
});
groups.push(i);
var length = groups.length;
gEnter.selectAll('.group')
.filter(function(d) {
for (var i = 0; i < length; i++) {
if(groups[i] == d.index) return false;
}
return true;
})
.transition()
.style("opacity", opacity);
};
}
|
[
"function",
"(",
"opacity",
")",
"{",
"return",
"function",
"(",
"g",
",",
"i",
")",
"{",
"gEnter",
".",
"selectAll",
"(",
"\".chord\"",
")",
".",
"filter",
"(",
"function",
"(",
"d",
")",
"{",
"return",
"d",
".",
"source",
".",
"index",
"!=",
"i",
"&&",
"d",
".",
"target",
".",
"index",
"!=",
"i",
";",
"}",
")",
".",
"transition",
"(",
")",
".",
"style",
"(",
"\"opacity\"",
",",
"opacity",
")",
";",
"var",
"groups",
"=",
"[",
"]",
";",
"gEnter",
".",
"selectAll",
"(",
"\".chord\"",
")",
".",
"filter",
"(",
"function",
"(",
"d",
")",
"{",
"if",
"(",
"d",
".",
"source",
".",
"index",
"==",
"i",
")",
"{",
"groups",
".",
"push",
"(",
"d",
".",
"target",
".",
"index",
")",
";",
"}",
"if",
"(",
"d",
".",
"target",
".",
"index",
"==",
"i",
")",
"{",
"groups",
".",
"push",
"(",
"d",
".",
"source",
".",
"index",
")",
";",
"}",
"}",
")",
";",
"groups",
".",
"push",
"(",
"i",
")",
";",
"var",
"length",
"=",
"groups",
".",
"length",
";",
"gEnter",
".",
"selectAll",
"(",
"'.group'",
")",
".",
"filter",
"(",
"function",
"(",
"d",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"groups",
"[",
"i",
"]",
"==",
"d",
".",
"index",
")",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}",
")",
".",
"transition",
"(",
")",
".",
"style",
"(",
"\"opacity\"",
",",
"opacity",
")",
";",
"}",
";",
"}"
] |
Returns an event handler for fading a given chord group.
|
[
"Returns",
"an",
"event",
"handler",
"for",
"fading",
"a",
"given",
"chord",
"group",
"."
] |
c7a1f4a1672dd903337d3c3d8c260a09fd8ee910
|
https://github.com/fzaninotto/DependencyWheel/blob/c7a1f4a1672dd903337d3c3d8c260a09fd8ee910/js/d3.dependencyWheel.js#L73-L103
|
|
19,869
|
choojs/wayfarer
|
index.js
|
Wayfarer
|
function Wayfarer (dft) {
if (!(this instanceof Wayfarer)) return new Wayfarer(dft)
var _default = (dft || '').replace(/^\//, '')
var _trie = trie()
emit._trie = _trie
emit.on = on
emit.emit = emit
emit.match = match
emit._wayfarer = true
return emit
// define a route
// (str, fn) -> obj
function on (route, fn) {
assert.equal(typeof route, 'string')
assert.equal(typeof fn, 'function')
var cb = fn._wayfarer && fn._trie ? fn : proxy
route = route || '/'
cb.route = route
if (cb._wayfarer && cb._trie) {
_trie.mount(route, cb._trie.trie)
} else {
var node = _trie.create(route)
node.cb = cb
}
return emit
function proxy () {
return fn.apply(this, Array.prototype.slice.call(arguments))
}
}
// match and call a route
// (str, obj?) -> null
function emit (route) {
var matched = match(route)
var args = new Array(arguments.length)
args[0] = matched.params
for (var i = 1; i < args.length; i++) {
args[i] = arguments[i]
}
return matched.cb.apply(matched.cb, args)
}
function match (route) {
assert.notEqual(route, undefined, "'route' must be defined")
var matched = _trie.match(route)
if (matched && matched.cb) return new Route(matched)
var dft = _trie.match(_default)
if (dft && dft.cb) return new Route(dft)
throw new Error("route '" + route + "' did not match")
}
function Route (matched) {
this.cb = matched.cb
this.route = matched.cb.route
this.params = matched.params
}
}
|
javascript
|
function Wayfarer (dft) {
if (!(this instanceof Wayfarer)) return new Wayfarer(dft)
var _default = (dft || '').replace(/^\//, '')
var _trie = trie()
emit._trie = _trie
emit.on = on
emit.emit = emit
emit.match = match
emit._wayfarer = true
return emit
// define a route
// (str, fn) -> obj
function on (route, fn) {
assert.equal(typeof route, 'string')
assert.equal(typeof fn, 'function')
var cb = fn._wayfarer && fn._trie ? fn : proxy
route = route || '/'
cb.route = route
if (cb._wayfarer && cb._trie) {
_trie.mount(route, cb._trie.trie)
} else {
var node = _trie.create(route)
node.cb = cb
}
return emit
function proxy () {
return fn.apply(this, Array.prototype.slice.call(arguments))
}
}
// match and call a route
// (str, obj?) -> null
function emit (route) {
var matched = match(route)
var args = new Array(arguments.length)
args[0] = matched.params
for (var i = 1; i < args.length; i++) {
args[i] = arguments[i]
}
return matched.cb.apply(matched.cb, args)
}
function match (route) {
assert.notEqual(route, undefined, "'route' must be defined")
var matched = _trie.match(route)
if (matched && matched.cb) return new Route(matched)
var dft = _trie.match(_default)
if (dft && dft.cb) return new Route(dft)
throw new Error("route '" + route + "' did not match")
}
function Route (matched) {
this.cb = matched.cb
this.route = matched.cb.route
this.params = matched.params
}
}
|
[
"function",
"Wayfarer",
"(",
"dft",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Wayfarer",
")",
")",
"return",
"new",
"Wayfarer",
"(",
"dft",
")",
"var",
"_default",
"=",
"(",
"dft",
"||",
"''",
")",
".",
"replace",
"(",
"/",
"^\\/",
"/",
",",
"''",
")",
"var",
"_trie",
"=",
"trie",
"(",
")",
"emit",
".",
"_trie",
"=",
"_trie",
"emit",
".",
"on",
"=",
"on",
"emit",
".",
"emit",
"=",
"emit",
"emit",
".",
"match",
"=",
"match",
"emit",
".",
"_wayfarer",
"=",
"true",
"return",
"emit",
"// define a route",
"// (str, fn) -> obj",
"function",
"on",
"(",
"route",
",",
"fn",
")",
"{",
"assert",
".",
"equal",
"(",
"typeof",
"route",
",",
"'string'",
")",
"assert",
".",
"equal",
"(",
"typeof",
"fn",
",",
"'function'",
")",
"var",
"cb",
"=",
"fn",
".",
"_wayfarer",
"&&",
"fn",
".",
"_trie",
"?",
"fn",
":",
"proxy",
"route",
"=",
"route",
"||",
"'/'",
"cb",
".",
"route",
"=",
"route",
"if",
"(",
"cb",
".",
"_wayfarer",
"&&",
"cb",
".",
"_trie",
")",
"{",
"_trie",
".",
"mount",
"(",
"route",
",",
"cb",
".",
"_trie",
".",
"trie",
")",
"}",
"else",
"{",
"var",
"node",
"=",
"_trie",
".",
"create",
"(",
"route",
")",
"node",
".",
"cb",
"=",
"cb",
"}",
"return",
"emit",
"function",
"proxy",
"(",
")",
"{",
"return",
"fn",
".",
"apply",
"(",
"this",
",",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
")",
")",
"}",
"}",
"// match and call a route",
"// (str, obj?) -> null",
"function",
"emit",
"(",
"route",
")",
"{",
"var",
"matched",
"=",
"match",
"(",
"route",
")",
"var",
"args",
"=",
"new",
"Array",
"(",
"arguments",
".",
"length",
")",
"args",
"[",
"0",
"]",
"=",
"matched",
".",
"params",
"for",
"(",
"var",
"i",
"=",
"1",
";",
"i",
"<",
"args",
".",
"length",
";",
"i",
"++",
")",
"{",
"args",
"[",
"i",
"]",
"=",
"arguments",
"[",
"i",
"]",
"}",
"return",
"matched",
".",
"cb",
".",
"apply",
"(",
"matched",
".",
"cb",
",",
"args",
")",
"}",
"function",
"match",
"(",
"route",
")",
"{",
"assert",
".",
"notEqual",
"(",
"route",
",",
"undefined",
",",
"\"'route' must be defined\"",
")",
"var",
"matched",
"=",
"_trie",
".",
"match",
"(",
"route",
")",
"if",
"(",
"matched",
"&&",
"matched",
".",
"cb",
")",
"return",
"new",
"Route",
"(",
"matched",
")",
"var",
"dft",
"=",
"_trie",
".",
"match",
"(",
"_default",
")",
"if",
"(",
"dft",
"&&",
"dft",
".",
"cb",
")",
"return",
"new",
"Route",
"(",
"dft",
")",
"throw",
"new",
"Error",
"(",
"\"route '\"",
"+",
"route",
"+",
"\"' did not match\"",
")",
"}",
"function",
"Route",
"(",
"matched",
")",
"{",
"this",
".",
"cb",
"=",
"matched",
".",
"cb",
"this",
".",
"route",
"=",
"matched",
".",
"cb",
".",
"route",
"this",
".",
"params",
"=",
"matched",
".",
"params",
"}",
"}"
] |
create a router str -> obj
|
[
"create",
"a",
"router",
"str",
"-",
">",
"obj"
] |
7f23ccdf2094443403902cde3ebc05828fa9b26b
|
https://github.com/choojs/wayfarer/blob/7f23ccdf2094443403902cde3ebc05828fa9b26b/index.js#L8-L77
|
19,870
|
kimmobrunfeldt/react-progressbar.js
|
tools/release.js
|
bumpVersion
|
function bumpVersion(files, bumpType) {
status('Bump', bumpType, 'version to files:', files.join(' '));
if (config.dryRun) return '[not available in dry run]';
var newVersion;
var originalVersion;
files.forEach(function(fileName) {
var filePath = path.join(projectRoot, fileName);
var data = JSON.parse(fs.readFileSync(filePath));
originalVersion = data.version;
var currentVersion = data.version;
if (!semver.valid(currentVersion)) {
var msg = 'Invalid version ' + currentVersion +
' in file ' + fileName;;
var err = new Error(msg);
throw err;
}
if (S(currentVersion).endsWith(config.devSuffix)) {
currentVersion = S(currentVersion).chompRight(config.devSuffix).s;
}
if (bumpType === 'dev') {
newVersion = currentVersion + config.devSuffix;
} else {
newVersion = semver.inc(currentVersion, bumpType);
}
data.version = newVersion;
var content = JSON.stringify(data, null, config.indentation);
fs.writeFileSync(filePath, content);
status('Bump', originalVersion, '->', newVersion, 'in',
fileName);
});
return newVersion;
}
|
javascript
|
function bumpVersion(files, bumpType) {
status('Bump', bumpType, 'version to files:', files.join(' '));
if (config.dryRun) return '[not available in dry run]';
var newVersion;
var originalVersion;
files.forEach(function(fileName) {
var filePath = path.join(projectRoot, fileName);
var data = JSON.parse(fs.readFileSync(filePath));
originalVersion = data.version;
var currentVersion = data.version;
if (!semver.valid(currentVersion)) {
var msg = 'Invalid version ' + currentVersion +
' in file ' + fileName;;
var err = new Error(msg);
throw err;
}
if (S(currentVersion).endsWith(config.devSuffix)) {
currentVersion = S(currentVersion).chompRight(config.devSuffix).s;
}
if (bumpType === 'dev') {
newVersion = currentVersion + config.devSuffix;
} else {
newVersion = semver.inc(currentVersion, bumpType);
}
data.version = newVersion;
var content = JSON.stringify(data, null, config.indentation);
fs.writeFileSync(filePath, content);
status('Bump', originalVersion, '->', newVersion, 'in',
fileName);
});
return newVersion;
}
|
[
"function",
"bumpVersion",
"(",
"files",
",",
"bumpType",
")",
"{",
"status",
"(",
"'Bump'",
",",
"bumpType",
",",
"'version to files:'",
",",
"files",
".",
"join",
"(",
"' '",
")",
")",
";",
"if",
"(",
"config",
".",
"dryRun",
")",
"return",
"'[not available in dry run]'",
";",
"var",
"newVersion",
";",
"var",
"originalVersion",
";",
"files",
".",
"forEach",
"(",
"function",
"(",
"fileName",
")",
"{",
"var",
"filePath",
"=",
"path",
".",
"join",
"(",
"projectRoot",
",",
"fileName",
")",
";",
"var",
"data",
"=",
"JSON",
".",
"parse",
"(",
"fs",
".",
"readFileSync",
"(",
"filePath",
")",
")",
";",
"originalVersion",
"=",
"data",
".",
"version",
";",
"var",
"currentVersion",
"=",
"data",
".",
"version",
";",
"if",
"(",
"!",
"semver",
".",
"valid",
"(",
"currentVersion",
")",
")",
"{",
"var",
"msg",
"=",
"'Invalid version '",
"+",
"currentVersion",
"+",
"' in file '",
"+",
"fileName",
";",
";",
"var",
"err",
"=",
"new",
"Error",
"(",
"msg",
")",
";",
"throw",
"err",
";",
"}",
"if",
"(",
"S",
"(",
"currentVersion",
")",
".",
"endsWith",
"(",
"config",
".",
"devSuffix",
")",
")",
"{",
"currentVersion",
"=",
"S",
"(",
"currentVersion",
")",
".",
"chompRight",
"(",
"config",
".",
"devSuffix",
")",
".",
"s",
";",
"}",
"if",
"(",
"bumpType",
"===",
"'dev'",
")",
"{",
"newVersion",
"=",
"currentVersion",
"+",
"config",
".",
"devSuffix",
";",
"}",
"else",
"{",
"newVersion",
"=",
"semver",
".",
"inc",
"(",
"currentVersion",
",",
"bumpType",
")",
";",
"}",
"data",
".",
"version",
"=",
"newVersion",
";",
"var",
"content",
"=",
"JSON",
".",
"stringify",
"(",
"data",
",",
"null",
",",
"config",
".",
"indentation",
")",
";",
"fs",
".",
"writeFileSync",
"(",
"filePath",
",",
"content",
")",
";",
"status",
"(",
"'Bump'",
",",
"originalVersion",
",",
"'->'",
",",
"newVersion",
",",
"'in'",
",",
"fileName",
")",
";",
"}",
")",
";",
"return",
"newVersion",
";",
"}"
] |
Bumps version in specified files. Files are assumed to contain JSON data which has "version" key following semantic versioning
|
[
"Bumps",
"version",
"in",
"specified",
"files",
".",
"Files",
"are",
"assumed",
"to",
"contain",
"JSON",
"data",
"which",
"has",
"version",
"key",
"following",
"semantic",
"versioning"
] |
16d5cf0a289ee87111580fedb42c9e58aab32b08
|
https://github.com/kimmobrunfeldt/react-progressbar.js/blob/16d5cf0a289ee87111580fedb42c9e58aab32b08/tools/release.js#L150-L188
|
19,871
|
bastienmichaux/generator-jhipster-db-helper
|
generators/fix-entity/prompts.js
|
askForTableName
|
function askForTableName() {
if (this.force) {
return;
}
const validateTableName = dbh.validateTableName;
const done = this.async();
this.prompt([
{
type: 'input',
name: 'dbhTableName',
validate: ((input) => {
const prodDatabaseType = this.jhipsterAppConfig.prodDatabaseType;
return validateTableName(input, prodDatabaseType);
}),
message: 'What is the table name for this entity ?',
default: this.entityTableName
}
]).then((props) => {
this.tableNameInput = props.dbhTableName;
done();
});
}
|
javascript
|
function askForTableName() {
if (this.force) {
return;
}
const validateTableName = dbh.validateTableName;
const done = this.async();
this.prompt([
{
type: 'input',
name: 'dbhTableName',
validate: ((input) => {
const prodDatabaseType = this.jhipsterAppConfig.prodDatabaseType;
return validateTableName(input, prodDatabaseType);
}),
message: 'What is the table name for this entity ?',
default: this.entityTableName
}
]).then((props) => {
this.tableNameInput = props.dbhTableName;
done();
});
}
|
[
"function",
"askForTableName",
"(",
")",
"{",
"if",
"(",
"this",
".",
"force",
")",
"{",
"return",
";",
"}",
"const",
"validateTableName",
"=",
"dbh",
".",
"validateTableName",
";",
"const",
"done",
"=",
"this",
".",
"async",
"(",
")",
";",
"this",
".",
"prompt",
"(",
"[",
"{",
"type",
":",
"'input'",
",",
"name",
":",
"'dbhTableName'",
",",
"validate",
":",
"(",
"(",
"input",
")",
"=>",
"{",
"const",
"prodDatabaseType",
"=",
"this",
".",
"jhipsterAppConfig",
".",
"prodDatabaseType",
";",
"return",
"validateTableName",
"(",
"input",
",",
"prodDatabaseType",
")",
";",
"}",
")",
",",
"message",
":",
"'What is the table name for this entity ?'",
",",
"default",
":",
"this",
".",
"entityTableName",
"}",
"]",
")",
".",
"then",
"(",
"(",
"props",
")",
"=>",
"{",
"this",
".",
"tableNameInput",
"=",
"props",
".",
"dbhTableName",
";",
"done",
"(",
")",
";",
"}",
")",
";",
"}"
] |
Ask the table name for an entity
|
[
"Ask",
"the",
"table",
"name",
"for",
"an",
"entity"
] |
17912e83f0a36248d8c32bb2aa07c6d077be7d87
|
https://github.com/bastienmichaux/generator-jhipster-db-helper/blob/17912e83f0a36248d8c32bb2aa07c6d077be7d87/generators/fix-entity/prompts.js#L14-L37
|
19,872
|
bastienmichaux/generator-jhipster-db-helper
|
generators/fix-entity/prompts.js
|
askForColumnsName
|
function askForColumnsName() {
// Don't ask columns name if there aren't any field
// Or option --force
if (this.fields === undefined || this.fields.length === 0 || this.force) {
return;
}
this.log(chalk.green(`Asking column names for ${this.fields.length} field(s)`));
const done = this.async();
// work on a copy
this.fieldsPile = this.fields.slice();
// feed the first item for the first question
this.field = this.fieldsPile.shift();
askForColumnName.call(this, done);
}
|
javascript
|
function askForColumnsName() {
// Don't ask columns name if there aren't any field
// Or option --force
if (this.fields === undefined || this.fields.length === 0 || this.force) {
return;
}
this.log(chalk.green(`Asking column names for ${this.fields.length} field(s)`));
const done = this.async();
// work on a copy
this.fieldsPile = this.fields.slice();
// feed the first item for the first question
this.field = this.fieldsPile.shift();
askForColumnName.call(this, done);
}
|
[
"function",
"askForColumnsName",
"(",
")",
"{",
"// Don't ask columns name if there aren't any field",
"// Or option --force",
"if",
"(",
"this",
".",
"fields",
"===",
"undefined",
"||",
"this",
".",
"fields",
".",
"length",
"===",
"0",
"||",
"this",
".",
"force",
")",
"{",
"return",
";",
"}",
"this",
".",
"log",
"(",
"chalk",
".",
"green",
"(",
"`",
"${",
"this",
".",
"fields",
".",
"length",
"}",
"`",
")",
")",
";",
"const",
"done",
"=",
"this",
".",
"async",
"(",
")",
";",
"// work on a copy",
"this",
".",
"fieldsPile",
"=",
"this",
".",
"fields",
".",
"slice",
"(",
")",
";",
"// feed the first item for the first question",
"this",
".",
"field",
"=",
"this",
".",
"fieldsPile",
".",
"shift",
"(",
")",
";",
"askForColumnName",
".",
"call",
"(",
"this",
",",
"done",
")",
";",
"}"
] |
For each field of an entity, ask the actual column name
|
[
"For",
"each",
"field",
"of",
"an",
"entity",
"ask",
"the",
"actual",
"column",
"name"
] |
17912e83f0a36248d8c32bb2aa07c6d077be7d87
|
https://github.com/bastienmichaux/generator-jhipster-db-helper/blob/17912e83f0a36248d8c32bb2aa07c6d077be7d87/generators/fix-entity/prompts.js#L65-L80
|
19,873
|
bastienmichaux/generator-jhipster-db-helper
|
generators/fix-entity/prompts.js
|
askForRelationshipsId
|
function askForRelationshipsId() {
// Don't ask relationship id if there aren't any relationship
// Or option --force
if (this.relationships === undefined || this.relationships.length === 0 || this.force) {
return;
}
// work only on owner relationship
this.relationshipsPile = this.relationships.filter(relationshipItem =>
// We don't need to do anything about relationships which don't add any constraint.
!(relationshipItem.relationshipType === 'one-to-many' ||
(relationshipItem.relationshipType === 'one-to-one' && !relationshipItem.ownerSide) ||
(relationshipItem.relationshipType === 'many-to-many' && !relationshipItem.ownerSide)));
if (this.relationshipsPile.length === 0) {
return;
}
this.log(chalk.green(`Asking column names for ${this.relationshipsPile.length} relationship(s)`));
const done = this.async();
this.relationship = this.relationshipsPile.shift();
askForRelationshipId.call(this, done);
}
|
javascript
|
function askForRelationshipsId() {
// Don't ask relationship id if there aren't any relationship
// Or option --force
if (this.relationships === undefined || this.relationships.length === 0 || this.force) {
return;
}
// work only on owner relationship
this.relationshipsPile = this.relationships.filter(relationshipItem =>
// We don't need to do anything about relationships which don't add any constraint.
!(relationshipItem.relationshipType === 'one-to-many' ||
(relationshipItem.relationshipType === 'one-to-one' && !relationshipItem.ownerSide) ||
(relationshipItem.relationshipType === 'many-to-many' && !relationshipItem.ownerSide)));
if (this.relationshipsPile.length === 0) {
return;
}
this.log(chalk.green(`Asking column names for ${this.relationshipsPile.length} relationship(s)`));
const done = this.async();
this.relationship = this.relationshipsPile.shift();
askForRelationshipId.call(this, done);
}
|
[
"function",
"askForRelationshipsId",
"(",
")",
"{",
"// Don't ask relationship id if there aren't any relationship",
"// Or option --force",
"if",
"(",
"this",
".",
"relationships",
"===",
"undefined",
"||",
"this",
".",
"relationships",
".",
"length",
"===",
"0",
"||",
"this",
".",
"force",
")",
"{",
"return",
";",
"}",
"// work only on owner relationship",
"this",
".",
"relationshipsPile",
"=",
"this",
".",
"relationships",
".",
"filter",
"(",
"relationshipItem",
"=>",
"// We don't need to do anything about relationships which don't add any constraint.",
"!",
"(",
"relationshipItem",
".",
"relationshipType",
"===",
"'one-to-many'",
"||",
"(",
"relationshipItem",
".",
"relationshipType",
"===",
"'one-to-one'",
"&&",
"!",
"relationshipItem",
".",
"ownerSide",
")",
"||",
"(",
"relationshipItem",
".",
"relationshipType",
"===",
"'many-to-many'",
"&&",
"!",
"relationshipItem",
".",
"ownerSide",
")",
")",
")",
";",
"if",
"(",
"this",
".",
"relationshipsPile",
".",
"length",
"===",
"0",
")",
"{",
"return",
";",
"}",
"this",
".",
"log",
"(",
"chalk",
".",
"green",
"(",
"`",
"${",
"this",
".",
"relationshipsPile",
".",
"length",
"}",
"`",
")",
")",
";",
"const",
"done",
"=",
"this",
".",
"async",
"(",
")",
";",
"this",
".",
"relationship",
"=",
"this",
".",
"relationshipsPile",
".",
"shift",
"(",
")",
";",
"askForRelationshipId",
".",
"call",
"(",
"this",
",",
"done",
")",
";",
"}"
] |
For each relationship of entity, ask for actual column name
|
[
"For",
"each",
"relationship",
"of",
"entity",
"ask",
"for",
"actual",
"column",
"name"
] |
17912e83f0a36248d8c32bb2aa07c6d077be7d87
|
https://github.com/bastienmichaux/generator-jhipster-db-helper/blob/17912e83f0a36248d8c32bb2aa07c6d077be7d87/generators/fix-entity/prompts.js#L124-L147
|
19,874
|
joetidee/enzyme-react-intl
|
src/index.js
|
loadTranslation
|
function loadTranslation(localeFilePath) {
if(typeof localeFilePath == "undefined"){
messages = defaultMessages;
return null;
}
let fp = path.join(__dirname, localeFilePath);
messages = require('jsonfile').readFileSync("." + fp);
return messages;
}
|
javascript
|
function loadTranslation(localeFilePath) {
if(typeof localeFilePath == "undefined"){
messages = defaultMessages;
return null;
}
let fp = path.join(__dirname, localeFilePath);
messages = require('jsonfile').readFileSync("." + fp);
return messages;
}
|
[
"function",
"loadTranslation",
"(",
"localeFilePath",
")",
"{",
"if",
"(",
"typeof",
"localeFilePath",
"==",
"\"undefined\"",
")",
"{",
"messages",
"=",
"defaultMessages",
";",
"return",
"null",
";",
"}",
"let",
"fp",
"=",
"path",
".",
"join",
"(",
"__dirname",
",",
"localeFilePath",
")",
";",
"messages",
"=",
"require",
"(",
"'jsonfile'",
")",
".",
"readFileSync",
"(",
"\".\"",
"+",
"fp",
")",
";",
"return",
"messages",
";",
"}"
] |
Loads translation file.
@param {string} localeFilePath
@return {object} messages
|
[
"Loads",
"translation",
"file",
"."
] |
1e96a0eb59239a6ac7dade34d38e71da49fd27b8
|
https://github.com/joetidee/enzyme-react-intl/blob/1e96a0eb59239a6ac7dade34d38e71da49fd27b8/src/index.js#L14-L22
|
19,875
|
joetidee/enzyme-react-intl
|
src/index.js
|
shallowWithIntl
|
function shallowWithIntl(node, options = { context: {}}) {
const intlProvider = new IntlProvider({locale: locale, messages }, {});
const { intl } = intlProvider.getChildContext();
return shallow(React.cloneElement(node, { intl }), { ...options, context: { ...options.context, intl } });
}
|
javascript
|
function shallowWithIntl(node, options = { context: {}}) {
const intlProvider = new IntlProvider({locale: locale, messages }, {});
const { intl } = intlProvider.getChildContext();
return shallow(React.cloneElement(node, { intl }), { ...options, context: { ...options.context, intl } });
}
|
[
"function",
"shallowWithIntl",
"(",
"node",
",",
"options",
"=",
"{",
"context",
":",
"{",
"}",
"}",
")",
"{",
"const",
"intlProvider",
"=",
"new",
"IntlProvider",
"(",
"{",
"locale",
":",
"locale",
",",
"messages",
"}",
",",
"{",
"}",
")",
";",
"const",
"{",
"intl",
"}",
"=",
"intlProvider",
".",
"getChildContext",
"(",
")",
";",
"return",
"shallow",
"(",
"React",
".",
"cloneElement",
"(",
"node",
",",
"{",
"intl",
"}",
")",
",",
"{",
"...",
"options",
",",
"context",
":",
"{",
"...",
"options",
".",
"context",
",",
"intl",
"}",
"}",
")",
";",
"}"
] |
Equivalent to enzyme's 'shallow' method.
@param {string} node React Component that requires react-intl.
@param {object} options enzyme.shallow options
@return {object}
|
[
"Equivalent",
"to",
"enzyme",
"s",
"shallow",
"method",
"."
] |
1e96a0eb59239a6ac7dade34d38e71da49fd27b8
|
https://github.com/joetidee/enzyme-react-intl/blob/1e96a0eb59239a6ac7dade34d38e71da49fd27b8/src/index.js#L45-L49
|
19,876
|
joetidee/enzyme-react-intl
|
src/index.js
|
mountWithIntl
|
function mountWithIntl (node, { context, childContextTypes } = {}) {
const intlProvider = new IntlProvider({locale: locale, messages }, {});
const { intl } = intlProvider.getChildContext();
return mount(React.cloneElement(node, { intl }), {
context: Object.assign({}, context, {intl}),
childContextTypes: Object.assign({}, { intl: intlShape }, childContextTypes)
});
}
|
javascript
|
function mountWithIntl (node, { context, childContextTypes } = {}) {
const intlProvider = new IntlProvider({locale: locale, messages }, {});
const { intl } = intlProvider.getChildContext();
return mount(React.cloneElement(node, { intl }), {
context: Object.assign({}, context, {intl}),
childContextTypes: Object.assign({}, { intl: intlShape }, childContextTypes)
});
}
|
[
"function",
"mountWithIntl",
"(",
"node",
",",
"{",
"context",
",",
"childContextTypes",
"}",
"=",
"{",
"}",
")",
"{",
"const",
"intlProvider",
"=",
"new",
"IntlProvider",
"(",
"{",
"locale",
":",
"locale",
",",
"messages",
"}",
",",
"{",
"}",
")",
";",
"const",
"{",
"intl",
"}",
"=",
"intlProvider",
".",
"getChildContext",
"(",
")",
";",
"return",
"mount",
"(",
"React",
".",
"cloneElement",
"(",
"node",
",",
"{",
"intl",
"}",
")",
",",
"{",
"context",
":",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"context",
",",
"{",
"intl",
"}",
")",
",",
"childContextTypes",
":",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"{",
"intl",
":",
"intlShape",
"}",
",",
"childContextTypes",
")",
"}",
")",
";",
"}"
] |
Equivalent to enzyme's 'mount' method.
@param {string} node React Component that requires react-intl.
@return {object}
|
[
"Equivalent",
"to",
"enzyme",
"s",
"mount",
"method",
"."
] |
1e96a0eb59239a6ac7dade34d38e71da49fd27b8
|
https://github.com/joetidee/enzyme-react-intl/blob/1e96a0eb59239a6ac7dade34d38e71da49fd27b8/src/index.js#L56-L63
|
19,877
|
joetidee/enzyme-react-intl
|
src/index.js
|
renderWithIntl
|
function renderWithIntl (node, { context, childContextTypes } = {}) {
const intlProvider = new IntlProvider({locale: locale, messages }, {});
const { intl } = intlProvider.getChildContext();
return render(React.cloneElement(node, { intl }), {
context: Object.assign({}, context, {intl}),
childContextTypes: Object.assign({}, { intl: intlShape }, childContextTypes)
});
}
|
javascript
|
function renderWithIntl (node, { context, childContextTypes } = {}) {
const intlProvider = new IntlProvider({locale: locale, messages }, {});
const { intl } = intlProvider.getChildContext();
return render(React.cloneElement(node, { intl }), {
context: Object.assign({}, context, {intl}),
childContextTypes: Object.assign({}, { intl: intlShape }, childContextTypes)
});
}
|
[
"function",
"renderWithIntl",
"(",
"node",
",",
"{",
"context",
",",
"childContextTypes",
"}",
"=",
"{",
"}",
")",
"{",
"const",
"intlProvider",
"=",
"new",
"IntlProvider",
"(",
"{",
"locale",
":",
"locale",
",",
"messages",
"}",
",",
"{",
"}",
")",
";",
"const",
"{",
"intl",
"}",
"=",
"intlProvider",
".",
"getChildContext",
"(",
")",
";",
"return",
"render",
"(",
"React",
".",
"cloneElement",
"(",
"node",
",",
"{",
"intl",
"}",
")",
",",
"{",
"context",
":",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"context",
",",
"{",
"intl",
"}",
")",
",",
"childContextTypes",
":",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"{",
"intl",
":",
"intlShape",
"}",
",",
"childContextTypes",
")",
"}",
")",
";",
"}"
] |
Equivalent to enzyme's 'render' method.
@param {string} node React Component that requires react-intl.
@return {object}
|
[
"Equivalent",
"to",
"enzyme",
"s",
"render",
"method",
"."
] |
1e96a0eb59239a6ac7dade34d38e71da49fd27b8
|
https://github.com/joetidee/enzyme-react-intl/blob/1e96a0eb59239a6ac7dade34d38e71da49fd27b8/src/index.js#L70-L77
|
19,878
|
mapbox/makizushi
|
index.js
|
getMarker
|
function getMarker(options, callback) {
// prevent .parsedTint from being attached to options
options = xtend({}, options);
if (options.tint) {
// Expand hex shorthand (3 chars) to 6, e.g. 333 => 333333.
// This is not done upstream in `node-tint` as some such
// shorthand cannot be disambiguated from other tintspec strings,
// e.g. 123 (rgb shorthand) vs. 123 (hue).
if (options.tint.length === 3) {
options.tint =
options.tint[0] + options.tint[0] +
options.tint[1] + options.tint[1] +
options.tint[2] + options.tint[2];
}
options.parsedTint = blend.parseTintString(options.tint);
}
if (!options.symbol ||
(options.symbol && options.symbol.length === 1) ||
(options.symbol.length === 2 && !isNaN(parseInt(options.symbol)))) {
loadCached(options, callback);
} else {
loadMaki(options, callback);
}
}
|
javascript
|
function getMarker(options, callback) {
// prevent .parsedTint from being attached to options
options = xtend({}, options);
if (options.tint) {
// Expand hex shorthand (3 chars) to 6, e.g. 333 => 333333.
// This is not done upstream in `node-tint` as some such
// shorthand cannot be disambiguated from other tintspec strings,
// e.g. 123 (rgb shorthand) vs. 123 (hue).
if (options.tint.length === 3) {
options.tint =
options.tint[0] + options.tint[0] +
options.tint[1] + options.tint[1] +
options.tint[2] + options.tint[2];
}
options.parsedTint = blend.parseTintString(options.tint);
}
if (!options.symbol ||
(options.symbol && options.symbol.length === 1) ||
(options.symbol.length === 2 && !isNaN(parseInt(options.symbol)))) {
loadCached(options, callback);
} else {
loadMaki(options, callback);
}
}
|
[
"function",
"getMarker",
"(",
"options",
",",
"callback",
")",
"{",
"// prevent .parsedTint from being attached to options",
"options",
"=",
"xtend",
"(",
"{",
"}",
",",
"options",
")",
";",
"if",
"(",
"options",
".",
"tint",
")",
"{",
"// Expand hex shorthand (3 chars) to 6, e.g. 333 => 333333.",
"// This is not done upstream in `node-tint` as some such",
"// shorthand cannot be disambiguated from other tintspec strings,",
"// e.g. 123 (rgb shorthand) vs. 123 (hue).",
"if",
"(",
"options",
".",
"tint",
".",
"length",
"===",
"3",
")",
"{",
"options",
".",
"tint",
"=",
"options",
".",
"tint",
"[",
"0",
"]",
"+",
"options",
".",
"tint",
"[",
"0",
"]",
"+",
"options",
".",
"tint",
"[",
"1",
"]",
"+",
"options",
".",
"tint",
"[",
"1",
"]",
"+",
"options",
".",
"tint",
"[",
"2",
"]",
"+",
"options",
".",
"tint",
"[",
"2",
"]",
";",
"}",
"options",
".",
"parsedTint",
"=",
"blend",
".",
"parseTintString",
"(",
"options",
".",
"tint",
")",
";",
"}",
"if",
"(",
"!",
"options",
".",
"symbol",
"||",
"(",
"options",
".",
"symbol",
"&&",
"options",
".",
"symbol",
".",
"length",
"===",
"1",
")",
"||",
"(",
"options",
".",
"symbol",
".",
"length",
"===",
"2",
"&&",
"!",
"isNaN",
"(",
"parseInt",
"(",
"options",
".",
"symbol",
")",
")",
")",
")",
"{",
"loadCached",
"(",
"options",
",",
"callback",
")",
";",
"}",
"else",
"{",
"loadMaki",
"(",
"options",
",",
"callback",
")",
";",
"}",
"}"
] |
Given a marker object like
{ base, tint, symbol, name }
Call callback with buffer.
@param {object} options
@param {function} callback
|
[
"Given",
"a",
"marker",
"object",
"like"
] |
8ffaa0415d78439d79ab3108ae36f845c789d475
|
https://github.com/mapbox/makizushi/blob/8ffaa0415d78439d79ab3108ae36f845c789d475/index.js#L39-L63
|
19,879
|
mapbox/makizushi
|
index.js
|
loadMaki
|
function loadMaki(options, callback) {
var base = options.base + '-' + options.size + (options.retina ? '@2x' : ''),
size = options.size,
symbol = options.symbol + '-' + sizes[size] + (options.retina ? '@2x' : '');
if (!base || !size) {
return callback(errcode('Marker is invalid because it lacks base or size.', 'EINVALID'));
}
if (!makiAvailable[symbol]) {
return callback(errcode('Marker symbol "' + options.symbol + '" is invalid.', 'EINVALID'));
}
fs.readFile(makiRenders + symbol + '.png', function(err, data) {
if (err) return callback(new Error('Marker "' + JSON.stringify(options) + '" is invalid because the symbol is not found.'));
// Base marker gets tint applied.
var parts = [{
buffer: markerCache.base[base],
tint: options.parsedTint
}];
// If symbol is present, find correct offset (varies by marker size).
if (symbol) {
parts.push(xtend({
buffer: data,
tint: blend.parseTintString('0x0;0x0;1.4x0'),
}, offsets[size + (options.retina ? '@2x' : '')]));
}
// Add mask layer.
parts.push({
buffer: markerCache.mask[base]
});
// Extract width and height from the IHDR. The IHDR chunk must appear
// first, so the location is always fixed.
var width = markerCache.base[base].readUInt32BE(16),
height = markerCache.base[base].readUInt32BE(20);
// Combine base, (optional) symbol, to supply the final marker.
blend(parts, {
format: 'png',
quality: 256,
width: width,
height: height
}, function(err, data) {
if (err) return callback(err);
return callback(null, data);
});
});
}
|
javascript
|
function loadMaki(options, callback) {
var base = options.base + '-' + options.size + (options.retina ? '@2x' : ''),
size = options.size,
symbol = options.symbol + '-' + sizes[size] + (options.retina ? '@2x' : '');
if (!base || !size) {
return callback(errcode('Marker is invalid because it lacks base or size.', 'EINVALID'));
}
if (!makiAvailable[symbol]) {
return callback(errcode('Marker symbol "' + options.symbol + '" is invalid.', 'EINVALID'));
}
fs.readFile(makiRenders + symbol + '.png', function(err, data) {
if (err) return callback(new Error('Marker "' + JSON.stringify(options) + '" is invalid because the symbol is not found.'));
// Base marker gets tint applied.
var parts = [{
buffer: markerCache.base[base],
tint: options.parsedTint
}];
// If symbol is present, find correct offset (varies by marker size).
if (symbol) {
parts.push(xtend({
buffer: data,
tint: blend.parseTintString('0x0;0x0;1.4x0'),
}, offsets[size + (options.retina ? '@2x' : '')]));
}
// Add mask layer.
parts.push({
buffer: markerCache.mask[base]
});
// Extract width and height from the IHDR. The IHDR chunk must appear
// first, so the location is always fixed.
var width = markerCache.base[base].readUInt32BE(16),
height = markerCache.base[base].readUInt32BE(20);
// Combine base, (optional) symbol, to supply the final marker.
blend(parts, {
format: 'png',
quality: 256,
width: width,
height: height
}, function(err, data) {
if (err) return callback(err);
return callback(null, data);
});
});
}
|
[
"function",
"loadMaki",
"(",
"options",
",",
"callback",
")",
"{",
"var",
"base",
"=",
"options",
".",
"base",
"+",
"'-'",
"+",
"options",
".",
"size",
"+",
"(",
"options",
".",
"retina",
"?",
"'@2x'",
":",
"''",
")",
",",
"size",
"=",
"options",
".",
"size",
",",
"symbol",
"=",
"options",
".",
"symbol",
"+",
"'-'",
"+",
"sizes",
"[",
"size",
"]",
"+",
"(",
"options",
".",
"retina",
"?",
"'@2x'",
":",
"''",
")",
";",
"if",
"(",
"!",
"base",
"||",
"!",
"size",
")",
"{",
"return",
"callback",
"(",
"errcode",
"(",
"'Marker is invalid because it lacks base or size.'",
",",
"'EINVALID'",
")",
")",
";",
"}",
"if",
"(",
"!",
"makiAvailable",
"[",
"symbol",
"]",
")",
"{",
"return",
"callback",
"(",
"errcode",
"(",
"'Marker symbol \"'",
"+",
"options",
".",
"symbol",
"+",
"'\" is invalid.'",
",",
"'EINVALID'",
")",
")",
";",
"}",
"fs",
".",
"readFile",
"(",
"makiRenders",
"+",
"symbol",
"+",
"'.png'",
",",
"function",
"(",
"err",
",",
"data",
")",
"{",
"if",
"(",
"err",
")",
"return",
"callback",
"(",
"new",
"Error",
"(",
"'Marker \"'",
"+",
"JSON",
".",
"stringify",
"(",
"options",
")",
"+",
"'\" is invalid because the symbol is not found.'",
")",
")",
";",
"// Base marker gets tint applied.",
"var",
"parts",
"=",
"[",
"{",
"buffer",
":",
"markerCache",
".",
"base",
"[",
"base",
"]",
",",
"tint",
":",
"options",
".",
"parsedTint",
"}",
"]",
";",
"// If symbol is present, find correct offset (varies by marker size).",
"if",
"(",
"symbol",
")",
"{",
"parts",
".",
"push",
"(",
"xtend",
"(",
"{",
"buffer",
":",
"data",
",",
"tint",
":",
"blend",
".",
"parseTintString",
"(",
"'0x0;0x0;1.4x0'",
")",
",",
"}",
",",
"offsets",
"[",
"size",
"+",
"(",
"options",
".",
"retina",
"?",
"'@2x'",
":",
"''",
")",
"]",
")",
")",
";",
"}",
"// Add mask layer.",
"parts",
".",
"push",
"(",
"{",
"buffer",
":",
"markerCache",
".",
"mask",
"[",
"base",
"]",
"}",
")",
";",
"// Extract width and height from the IHDR. The IHDR chunk must appear",
"// first, so the location is always fixed.",
"var",
"width",
"=",
"markerCache",
".",
"base",
"[",
"base",
"]",
".",
"readUInt32BE",
"(",
"16",
")",
",",
"height",
"=",
"markerCache",
".",
"base",
"[",
"base",
"]",
".",
"readUInt32BE",
"(",
"20",
")",
";",
"// Combine base, (optional) symbol, to supply the final marker.",
"blend",
"(",
"parts",
",",
"{",
"format",
":",
"'png'",
",",
"quality",
":",
"256",
",",
"width",
":",
"width",
",",
"height",
":",
"height",
"}",
",",
"function",
"(",
"err",
",",
"data",
")",
"{",
"if",
"(",
"err",
")",
"return",
"callback",
"(",
"err",
")",
";",
"return",
"callback",
"(",
"null",
",",
"data",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Load & composite a marker from the maki icon set.
@param {object} options
@param {function} callback
|
[
"Load",
"&",
"composite",
"a",
"marker",
"from",
"the",
"maki",
"icon",
"set",
"."
] |
8ffaa0415d78439d79ab3108ae36f845c789d475
|
https://github.com/mapbox/makizushi/blob/8ffaa0415d78439d79ab3108ae36f845c789d475/index.js#L71-L122
|
19,880
|
CSNW/sql-bricks
|
sql-bricks.js
|
argsToArray
|
function argsToArray(args) {
if (_.isArray(args[0]))
return args[0];
else if (typeof args[0] == 'string' && args[0].indexOf(',') > -1)
return _.invoke(args[0].split(','), 'trim');
else
return _.toArray(args);
}
|
javascript
|
function argsToArray(args) {
if (_.isArray(args[0]))
return args[0];
else if (typeof args[0] == 'string' && args[0].indexOf(',') > -1)
return _.invoke(args[0].split(','), 'trim');
else
return _.toArray(args);
}
|
[
"function",
"argsToArray",
"(",
"args",
")",
"{",
"if",
"(",
"_",
".",
"isArray",
"(",
"args",
"[",
"0",
"]",
")",
")",
"return",
"args",
"[",
"0",
"]",
";",
"else",
"if",
"(",
"typeof",
"args",
"[",
"0",
"]",
"==",
"'string'",
"&&",
"args",
"[",
"0",
"]",
".",
"indexOf",
"(",
"','",
")",
">",
"-",
"1",
")",
"return",
"_",
".",
"invoke",
"(",
"args",
"[",
"0",
"]",
".",
"split",
"(",
"','",
")",
",",
"'trim'",
")",
";",
"else",
"return",
"_",
".",
"toArray",
"(",
"args",
")",
";",
"}"
] |
handle an array, a comma-delimited str or separate args
|
[
"handle",
"an",
"array",
"a",
"comma",
"-",
"delimited",
"str",
"or",
"separate",
"args"
] |
087027d2f3738d769873b0c76ac9090697077b2b
|
https://github.com/CSNW/sql-bricks/blob/087027d2f3738d769873b0c76ac9090697077b2b/sql-bricks.js#L638-L645
|
19,881
|
jonsamwell/angular-auto-validate
|
dist/jcs-auto-validate.js
|
formatString
|
function formatString(string, params) {
return string.replace(/{(\d+)}/g, function (match, number) {
return typeof params[number] !== undefined ? params[number] : match;
});
}
|
javascript
|
function formatString(string, params) {
return string.replace(/{(\d+)}/g, function (match, number) {
return typeof params[number] !== undefined ? params[number] : match;
});
}
|
[
"function",
"formatString",
"(",
"string",
",",
"params",
")",
"{",
"return",
"string",
".",
"replace",
"(",
"/",
"{(\\d+)}",
"/",
"g",
",",
"function",
"(",
"match",
",",
"number",
")",
"{",
"return",
"typeof",
"params",
"[",
"number",
"]",
"!==",
"undefined",
"?",
"params",
"[",
"number",
"]",
":",
"match",
";",
"}",
")",
";",
"}"
] |
Replaces string placeholders with corresponding template string
|
[
"Replaces",
"string",
"placeholders",
"with",
"corresponding",
"template",
"string"
] |
ea8ccf4e312e8fdf1e73fb69e26846f57d5eb3ca
|
https://github.com/jonsamwell/angular-auto-validate/blob/ea8ccf4e312e8fdf1e73fb69e26846f57d5eb3ca/dist/jcs-auto-validate.js#L647-L651
|
19,882
|
jsdoc2md/dmd
|
helpers/helpers.js
|
tableHead
|
function tableHead () {
var args = arrayify(arguments)
var data = args.shift()
if (!data) return
args.pop()
var cols = args
var colHeaders = cols.map(function (col) {
var spl = col.split('|')
return spl[1] || spl[0]
})
cols = cols.map(function (col) {
return col.split('|')[0]
})
var toSplice = []
cols = cols.filter(function (col, index) {
var hasValue = data.some(function (row) {
return typeof row[col] !== 'undefined'
})
if (!hasValue) toSplice.push(index)
return hasValue
})
toSplice.reverse().forEach(function (index) {
colHeaders.splice(index, 1)
})
var table = '| ' + colHeaders.join(' | ') + ' |\n'
table += cols.reduce(function (p) { return p + ' --- |' }, '|') + '\n'
return table
}
|
javascript
|
function tableHead () {
var args = arrayify(arguments)
var data = args.shift()
if (!data) return
args.pop()
var cols = args
var colHeaders = cols.map(function (col) {
var spl = col.split('|')
return spl[1] || spl[0]
})
cols = cols.map(function (col) {
return col.split('|')[0]
})
var toSplice = []
cols = cols.filter(function (col, index) {
var hasValue = data.some(function (row) {
return typeof row[col] !== 'undefined'
})
if (!hasValue) toSplice.push(index)
return hasValue
})
toSplice.reverse().forEach(function (index) {
colHeaders.splice(index, 1)
})
var table = '| ' + colHeaders.join(' | ') + ' |\n'
table += cols.reduce(function (p) { return p + ' --- |' }, '|') + '\n'
return table
}
|
[
"function",
"tableHead",
"(",
")",
"{",
"var",
"args",
"=",
"arrayify",
"(",
"arguments",
")",
"var",
"data",
"=",
"args",
".",
"shift",
"(",
")",
"if",
"(",
"!",
"data",
")",
"return",
"args",
".",
"pop",
"(",
")",
"var",
"cols",
"=",
"args",
"var",
"colHeaders",
"=",
"cols",
".",
"map",
"(",
"function",
"(",
"col",
")",
"{",
"var",
"spl",
"=",
"col",
".",
"split",
"(",
"'|'",
")",
"return",
"spl",
"[",
"1",
"]",
"||",
"spl",
"[",
"0",
"]",
"}",
")",
"cols",
"=",
"cols",
".",
"map",
"(",
"function",
"(",
"col",
")",
"{",
"return",
"col",
".",
"split",
"(",
"'|'",
")",
"[",
"0",
"]",
"}",
")",
"var",
"toSplice",
"=",
"[",
"]",
"cols",
"=",
"cols",
".",
"filter",
"(",
"function",
"(",
"col",
",",
"index",
")",
"{",
"var",
"hasValue",
"=",
"data",
".",
"some",
"(",
"function",
"(",
"row",
")",
"{",
"return",
"typeof",
"row",
"[",
"col",
"]",
"!==",
"'undefined'",
"}",
")",
"if",
"(",
"!",
"hasValue",
")",
"toSplice",
".",
"push",
"(",
"index",
")",
"return",
"hasValue",
"}",
")",
"toSplice",
".",
"reverse",
"(",
")",
".",
"forEach",
"(",
"function",
"(",
"index",
")",
"{",
"colHeaders",
".",
"splice",
"(",
"index",
",",
"1",
")",
"}",
")",
"var",
"table",
"=",
"'| '",
"+",
"colHeaders",
".",
"join",
"(",
"' | '",
")",
"+",
"' |\\n'",
"table",
"+=",
"cols",
".",
"reduce",
"(",
"function",
"(",
"p",
")",
"{",
"return",
"p",
"+",
"' --- |'",
"}",
",",
"'|'",
")",
"+",
"'\\n'",
"return",
"table",
"}"
] |
returns a gfm table header row.. only columns which contain data are included in the output
|
[
"returns",
"a",
"gfm",
"table",
"header",
"row",
"..",
"only",
"columns",
"which",
"contain",
"data",
"are",
"included",
"in",
"the",
"output"
] |
a4b31ec41f3b3a523c354877ac488da33314fc1f
|
https://github.com/jsdoc2md/dmd/blob/a4b31ec41f3b3a523c354877ac488da33314fc1f/helpers/helpers.js#L62-L90
|
19,883
|
jsdoc2md/dmd
|
helpers/helpers.js
|
tableRow
|
function tableRow () {
var args = arrayify(arguments)
var rows = args.shift()
if (!rows) return
var options = args.pop()
var cols = args
var output = ''
if (options.data) {
var data = handlebars.createFrame(options.data)
cols.forEach(function (col, index) {
var colNumber = index + 1
data['col' + colNumber] = containsData(rows, col)
})
}
rows.forEach(function (row) {
output += options.fn(row, { data: data })
})
return output
}
|
javascript
|
function tableRow () {
var args = arrayify(arguments)
var rows = args.shift()
if (!rows) return
var options = args.pop()
var cols = args
var output = ''
if (options.data) {
var data = handlebars.createFrame(options.data)
cols.forEach(function (col, index) {
var colNumber = index + 1
data['col' + colNumber] = containsData(rows, col)
})
}
rows.forEach(function (row) {
output += options.fn(row, { data: data })
})
return output
}
|
[
"function",
"tableRow",
"(",
")",
"{",
"var",
"args",
"=",
"arrayify",
"(",
"arguments",
")",
"var",
"rows",
"=",
"args",
".",
"shift",
"(",
")",
"if",
"(",
"!",
"rows",
")",
"return",
"var",
"options",
"=",
"args",
".",
"pop",
"(",
")",
"var",
"cols",
"=",
"args",
"var",
"output",
"=",
"''",
"if",
"(",
"options",
".",
"data",
")",
"{",
"var",
"data",
"=",
"handlebars",
".",
"createFrame",
"(",
"options",
".",
"data",
")",
"cols",
".",
"forEach",
"(",
"function",
"(",
"col",
",",
"index",
")",
"{",
"var",
"colNumber",
"=",
"index",
"+",
"1",
"data",
"[",
"'col'",
"+",
"colNumber",
"]",
"=",
"containsData",
"(",
"rows",
",",
"col",
")",
"}",
")",
"}",
"rows",
".",
"forEach",
"(",
"function",
"(",
"row",
")",
"{",
"output",
"+=",
"options",
".",
"fn",
"(",
"row",
",",
"{",
"data",
":",
"data",
"}",
")",
"}",
")",
"return",
"output",
"}"
] |
returns a gfm table row.. only columns which contain data are included in the output
|
[
"returns",
"a",
"gfm",
"table",
"row",
"..",
"only",
"columns",
"which",
"contain",
"data",
"are",
"included",
"in",
"the",
"output"
] |
a4b31ec41f3b3a523c354877ac488da33314fc1f
|
https://github.com/jsdoc2md/dmd/blob/a4b31ec41f3b3a523c354877ac488da33314fc1f/helpers/helpers.js#L101-L120
|
19,884
|
jsdoc2md/dmd
|
helpers/helpers.js
|
_groupBy
|
function _groupBy (identifiers, groupByFields) {
/* don't modify the input array */
groupByFields = groupByFields.slice(0)
groupByFields.forEach(function (group) {
var groupValues = identifiers
.filter(function (identifier) {
/* exclude constructors from grouping.. re-implement to work off a `null` group value */
return identifier.kind !== 'constructor'
})
.map(function (i) { return i[group] })
.reduce(unique, [])
if (groupValues.length <= 1) groupByFields = groupByFields.reduce(without(group), [])
})
identifiers = _addGroup(identifiers, groupByFields)
var inserts = []
var prevGroup = []
var level = 0
identifiers.forEach(function (identifier, index) {
if (!deepEqual(identifier._group, prevGroup)) {
var common = commonSequence(identifier._group, prevGroup)
level = common.length
identifier._group.forEach(function (group, i) {
if (group !== common[i] && group !== null) {
inserts.push({
index: index,
_title: group,
level: level++
})
}
})
}
identifier.level = level
prevGroup = identifier._group
delete identifier._group
})
/* insert title items */
inserts.reverse().forEach(function (insert) {
identifiers.splice(insert.index, 0, { _title: insert._title, level: insert.level })
})
return identifiers
}
|
javascript
|
function _groupBy (identifiers, groupByFields) {
/* don't modify the input array */
groupByFields = groupByFields.slice(0)
groupByFields.forEach(function (group) {
var groupValues = identifiers
.filter(function (identifier) {
/* exclude constructors from grouping.. re-implement to work off a `null` group value */
return identifier.kind !== 'constructor'
})
.map(function (i) { return i[group] })
.reduce(unique, [])
if (groupValues.length <= 1) groupByFields = groupByFields.reduce(without(group), [])
})
identifiers = _addGroup(identifiers, groupByFields)
var inserts = []
var prevGroup = []
var level = 0
identifiers.forEach(function (identifier, index) {
if (!deepEqual(identifier._group, prevGroup)) {
var common = commonSequence(identifier._group, prevGroup)
level = common.length
identifier._group.forEach(function (group, i) {
if (group !== common[i] && group !== null) {
inserts.push({
index: index,
_title: group,
level: level++
})
}
})
}
identifier.level = level
prevGroup = identifier._group
delete identifier._group
})
/* insert title items */
inserts.reverse().forEach(function (insert) {
identifiers.splice(insert.index, 0, { _title: insert._title, level: insert.level })
})
return identifiers
}
|
[
"function",
"_groupBy",
"(",
"identifiers",
",",
"groupByFields",
")",
"{",
"/* don't modify the input array */",
"groupByFields",
"=",
"groupByFields",
".",
"slice",
"(",
"0",
")",
"groupByFields",
".",
"forEach",
"(",
"function",
"(",
"group",
")",
"{",
"var",
"groupValues",
"=",
"identifiers",
".",
"filter",
"(",
"function",
"(",
"identifier",
")",
"{",
"/* exclude constructors from grouping.. re-implement to work off a `null` group value */",
"return",
"identifier",
".",
"kind",
"!==",
"'constructor'",
"}",
")",
".",
"map",
"(",
"function",
"(",
"i",
")",
"{",
"return",
"i",
"[",
"group",
"]",
"}",
")",
".",
"reduce",
"(",
"unique",
",",
"[",
"]",
")",
"if",
"(",
"groupValues",
".",
"length",
"<=",
"1",
")",
"groupByFields",
"=",
"groupByFields",
".",
"reduce",
"(",
"without",
"(",
"group",
")",
",",
"[",
"]",
")",
"}",
")",
"identifiers",
"=",
"_addGroup",
"(",
"identifiers",
",",
"groupByFields",
")",
"var",
"inserts",
"=",
"[",
"]",
"var",
"prevGroup",
"=",
"[",
"]",
"var",
"level",
"=",
"0",
"identifiers",
".",
"forEach",
"(",
"function",
"(",
"identifier",
",",
"index",
")",
"{",
"if",
"(",
"!",
"deepEqual",
"(",
"identifier",
".",
"_group",
",",
"prevGroup",
")",
")",
"{",
"var",
"common",
"=",
"commonSequence",
"(",
"identifier",
".",
"_group",
",",
"prevGroup",
")",
"level",
"=",
"common",
".",
"length",
"identifier",
".",
"_group",
".",
"forEach",
"(",
"function",
"(",
"group",
",",
"i",
")",
"{",
"if",
"(",
"group",
"!==",
"common",
"[",
"i",
"]",
"&&",
"group",
"!==",
"null",
")",
"{",
"inserts",
".",
"push",
"(",
"{",
"index",
":",
"index",
",",
"_title",
":",
"group",
",",
"level",
":",
"level",
"++",
"}",
")",
"}",
"}",
")",
"}",
"identifier",
".",
"level",
"=",
"level",
"prevGroup",
"=",
"identifier",
".",
"_group",
"delete",
"identifier",
".",
"_group",
"}",
")",
"/* insert title items */",
"inserts",
".",
"reverse",
"(",
")",
".",
"forEach",
"(",
"function",
"(",
"insert",
")",
"{",
"identifiers",
".",
"splice",
"(",
"insert",
".",
"index",
",",
"0",
",",
"{",
"_title",
":",
"insert",
".",
"_title",
",",
"level",
":",
"insert",
".",
"level",
"}",
")",
"}",
")",
"return",
"identifiers",
"}"
] |
takes the children of this, groups them, inserts group headings..
|
[
"takes",
"the",
"children",
"of",
"this",
"groups",
"them",
"inserts",
"group",
"headings",
".."
] |
a4b31ec41f3b3a523c354877ac488da33314fc1f
|
https://github.com/jsdoc2md/dmd/blob/a4b31ec41f3b3a523c354877ac488da33314fc1f/helpers/helpers.js#L191-L234
|
19,885
|
jsdoc2md/dmd
|
helpers/helpers.js
|
kindInThisContext
|
function kindInThisContext (options) {
if (this.kind === 'function' && this.memberof) {
return 'method'
} else if (this.kind === 'member' && !this.isEnum && this.memberof) {
return 'property'
} else if (this.kind === 'member' && this.isEnum && this.memberof) {
return 'enum property'
} else if (this.kind === 'member' && this.isEnum && !this.memberof) {
return 'enum'
} else if (this.kind === 'member' && this.scope === 'global') {
return 'variable'
} else {
return this.kind
}
}
|
javascript
|
function kindInThisContext (options) {
if (this.kind === 'function' && this.memberof) {
return 'method'
} else if (this.kind === 'member' && !this.isEnum && this.memberof) {
return 'property'
} else if (this.kind === 'member' && this.isEnum && this.memberof) {
return 'enum property'
} else if (this.kind === 'member' && this.isEnum && !this.memberof) {
return 'enum'
} else if (this.kind === 'member' && this.scope === 'global') {
return 'variable'
} else {
return this.kind
}
}
|
[
"function",
"kindInThisContext",
"(",
"options",
")",
"{",
"if",
"(",
"this",
".",
"kind",
"===",
"'function'",
"&&",
"this",
".",
"memberof",
")",
"{",
"return",
"'method'",
"}",
"else",
"if",
"(",
"this",
".",
"kind",
"===",
"'member'",
"&&",
"!",
"this",
".",
"isEnum",
"&&",
"this",
".",
"memberof",
")",
"{",
"return",
"'property'",
"}",
"else",
"if",
"(",
"this",
".",
"kind",
"===",
"'member'",
"&&",
"this",
".",
"isEnum",
"&&",
"this",
".",
"memberof",
")",
"{",
"return",
"'enum property'",
"}",
"else",
"if",
"(",
"this",
".",
"kind",
"===",
"'member'",
"&&",
"this",
".",
"isEnum",
"&&",
"!",
"this",
".",
"memberof",
")",
"{",
"return",
"'enum'",
"}",
"else",
"if",
"(",
"this",
".",
"kind",
"===",
"'member'",
"&&",
"this",
".",
"scope",
"===",
"'global'",
")",
"{",
"return",
"'variable'",
"}",
"else",
"{",
"return",
"this",
".",
"kind",
"}",
"}"
] |
returns a more appropriate 'kind', depending on context
@return {string}
|
[
"returns",
"a",
"more",
"appropriate",
"kind",
"depending",
"on",
"context"
] |
a4b31ec41f3b3a523c354877ac488da33314fc1f
|
https://github.com/jsdoc2md/dmd/blob/a4b31ec41f3b3a523c354877ac488da33314fc1f/helpers/helpers.js#L250-L264
|
19,886
|
jsdoc2md/dmd
|
helpers/helpers.js
|
params
|
function params (options) {
if (this.params) {
var list = this.params.map(function (param) {
var nameSplit = param.name.split('.')
var name = nameSplit[nameSplit.length - 1]
if (nameSplit.length > 1) name = '.' + name
if (param.variable) name = '...' + name
if (param.optional) name = '[' + name + ']'
return {
indent: ' '.repeat(nameSplit.length - 1),
name: name,
type: param.type,
defaultvalue: param.defaultvalue,
description: param.description
}
})
return options.fn(list)
}
}
|
javascript
|
function params (options) {
if (this.params) {
var list = this.params.map(function (param) {
var nameSplit = param.name.split('.')
var name = nameSplit[nameSplit.length - 1]
if (nameSplit.length > 1) name = '.' + name
if (param.variable) name = '...' + name
if (param.optional) name = '[' + name + ']'
return {
indent: ' '.repeat(nameSplit.length - 1),
name: name,
type: param.type,
defaultvalue: param.defaultvalue,
description: param.description
}
})
return options.fn(list)
}
}
|
[
"function",
"params",
"(",
"options",
")",
"{",
"if",
"(",
"this",
".",
"params",
")",
"{",
"var",
"list",
"=",
"this",
".",
"params",
".",
"map",
"(",
"function",
"(",
"param",
")",
"{",
"var",
"nameSplit",
"=",
"param",
".",
"name",
".",
"split",
"(",
"'.'",
")",
"var",
"name",
"=",
"nameSplit",
"[",
"nameSplit",
".",
"length",
"-",
"1",
"]",
"if",
"(",
"nameSplit",
".",
"length",
">",
"1",
")",
"name",
"=",
"'.'",
"+",
"name",
"if",
"(",
"param",
".",
"variable",
")",
"name",
"=",
"'...'",
"+",
"name",
"if",
"(",
"param",
".",
"optional",
")",
"name",
"=",
"'['",
"+",
"name",
"+",
"']'",
"return",
"{",
"indent",
":",
"' '",
".",
"repeat",
"(",
"nameSplit",
".",
"length",
"-",
"1",
")",
",",
"name",
":",
"name",
",",
"type",
":",
"param",
".",
"type",
",",
"defaultvalue",
":",
"param",
".",
"defaultvalue",
",",
"description",
":",
"param",
".",
"description",
"}",
"}",
")",
"return",
"options",
".",
"fn",
"(",
"list",
")",
"}",
"}"
] |
block helper.. provides the data to render the @params tag
|
[
"block",
"helper",
"..",
"provides",
"the",
"data",
"to",
"render",
"the"
] |
a4b31ec41f3b3a523c354877ac488da33314fc1f
|
https://github.com/jsdoc2md/dmd/blob/a4b31ec41f3b3a523c354877ac488da33314fc1f/helpers/helpers.js#L284-L302
|
19,887
|
jsdoc2md/dmd
|
helpers/selectors.js
|
identifier
|
function identifier (options) {
var result = ddata._identifier(options)
return result ? options.fn(result) : 'ERROR, Cannot find identifier.'
}
|
javascript
|
function identifier (options) {
var result = ddata._identifier(options)
return result ? options.fn(result) : 'ERROR, Cannot find identifier.'
}
|
[
"function",
"identifier",
"(",
"options",
")",
"{",
"var",
"result",
"=",
"ddata",
".",
"_identifier",
"(",
"options",
")",
"return",
"result",
"?",
"options",
".",
"fn",
"(",
"result",
")",
":",
"'ERROR, Cannot find identifier.'",
"}"
] |
render the supplied block for the specified identifier
@static
|
[
"render",
"the",
"supplied",
"block",
"for",
"the",
"specified",
"identifier"
] |
a4b31ec41f3b3a523c354877ac488da33314fc1f
|
https://github.com/jsdoc2md/dmd/blob/a4b31ec41f3b3a523c354877ac488da33314fc1f/helpers/selectors.js#L31-L34
|
19,888
|
jsdoc2md/dmd
|
helpers/selectors.js
|
class_
|
function class_ (options) {
options.hash.kind = 'class'
var result = ddata._identifier(options)
return result ? options.fn(result) : 'ERROR, Cannot find class.'
}
|
javascript
|
function class_ (options) {
options.hash.kind = 'class'
var result = ddata._identifier(options)
return result ? options.fn(result) : 'ERROR, Cannot find class.'
}
|
[
"function",
"class_",
"(",
"options",
")",
"{",
"options",
".",
"hash",
".",
"kind",
"=",
"'class'",
"var",
"result",
"=",
"ddata",
".",
"_identifier",
"(",
"options",
")",
"return",
"result",
"?",
"options",
".",
"fn",
"(",
"result",
")",
":",
"'ERROR, Cannot find class.'",
"}"
] |
render the supplied block for the specified class
|
[
"render",
"the",
"supplied",
"block",
"for",
"the",
"specified",
"class"
] |
a4b31ec41f3b3a523c354877ac488da33314fc1f
|
https://github.com/jsdoc2md/dmd/blob/a4b31ec41f3b3a523c354877ac488da33314fc1f/helpers/selectors.js#L83-L87
|
19,889
|
jsdoc2md/dmd
|
lib/dmd.js
|
dmd
|
function dmd (templateData, options) {
options = new DmdOptions(options)
if (skipCache(options)) {
return generate(templateData, options)
} else {
const cached = dmd.cache.readSync([ templateData, options, dmdVersion ])
if (cached) {
return cached
} else {
return generate(templateData, options)
}
}
}
|
javascript
|
function dmd (templateData, options) {
options = new DmdOptions(options)
if (skipCache(options)) {
return generate(templateData, options)
} else {
const cached = dmd.cache.readSync([ templateData, options, dmdVersion ])
if (cached) {
return cached
} else {
return generate(templateData, options)
}
}
}
|
[
"function",
"dmd",
"(",
"templateData",
",",
"options",
")",
"{",
"options",
"=",
"new",
"DmdOptions",
"(",
"options",
")",
"if",
"(",
"skipCache",
"(",
"options",
")",
")",
"{",
"return",
"generate",
"(",
"templateData",
",",
"options",
")",
"}",
"else",
"{",
"const",
"cached",
"=",
"dmd",
".",
"cache",
".",
"readSync",
"(",
"[",
"templateData",
",",
"options",
",",
"dmdVersion",
"]",
")",
"if",
"(",
"cached",
")",
"{",
"return",
"cached",
"}",
"else",
"{",
"return",
"generate",
"(",
"templateData",
",",
"options",
")",
"}",
"}",
"}"
] |
Transforms doclet data into markdown documentation.
@param {object[]}
@param [options] {module:dmd-options} - The render options
@return {string}
@alias module:dmd
|
[
"Transforms",
"doclet",
"data",
"into",
"markdown",
"documentation",
"."
] |
a4b31ec41f3b3a523c354877ac488da33314fc1f
|
https://github.com/jsdoc2md/dmd/blob/a4b31ec41f3b3a523c354877ac488da33314fc1f/lib/dmd.js#L20-L32
|
19,890
|
jsdoc2md/dmd
|
helpers/ddata.js
|
_globals
|
function _globals (options) {
options.hash.scope = 'global'
return _identifiers(options).filter(function (identifier) {
if (identifier.kind === 'external') {
return identifier.description && identifier.description.length > 0
} else {
return true
}
})
}
|
javascript
|
function _globals (options) {
options.hash.scope = 'global'
return _identifiers(options).filter(function (identifier) {
if (identifier.kind === 'external') {
return identifier.description && identifier.description.length > 0
} else {
return true
}
})
}
|
[
"function",
"_globals",
"(",
"options",
")",
"{",
"options",
".",
"hash",
".",
"scope",
"=",
"'global'",
"return",
"_identifiers",
"(",
"options",
")",
".",
"filter",
"(",
"function",
"(",
"identifier",
")",
"{",
"if",
"(",
"identifier",
".",
"kind",
"===",
"'external'",
")",
"{",
"return",
"identifier",
".",
"description",
"&&",
"identifier",
".",
"description",
".",
"length",
">",
"0",
"}",
"else",
"{",
"return",
"true",
"}",
"}",
")",
"}"
] |
omits externals without a description
@static
|
[
"omits",
"externals",
"without",
"a",
"description"
] |
a4b31ec41f3b3a523c354877ac488da33314fc1f
|
https://github.com/jsdoc2md/dmd/blob/a4b31ec41f3b3a523c354877ac488da33314fc1f/helpers/ddata.js#L94-L103
|
19,891
|
jsdoc2md/dmd
|
helpers/ddata.js
|
children
|
function children (options) {
var context = _children.call(this, options)
var fn = options.fn
var inverse = options.inverse
var i = 0
var ret = ''
var data
var contextPath
if (options.data) {
data = handlebars.createFrame(options.data)
}
for (var j = context.length; i < j; i++) {
depthIncrement(options)
if (data) {
data.index = i
data.first = (i === 0)
data.last = (i === (context.length - 1))
if (contextPath) {
data.contextPath = contextPath + i
}
}
ret = ret + fn(context[i], { data: data })
depthDecrement(options)
}
if (i === 0) {
ret = inverse(this)
}
return ret
}
|
javascript
|
function children (options) {
var context = _children.call(this, options)
var fn = options.fn
var inverse = options.inverse
var i = 0
var ret = ''
var data
var contextPath
if (options.data) {
data = handlebars.createFrame(options.data)
}
for (var j = context.length; i < j; i++) {
depthIncrement(options)
if (data) {
data.index = i
data.first = (i === 0)
data.last = (i === (context.length - 1))
if (contextPath) {
data.contextPath = contextPath + i
}
}
ret = ret + fn(context[i], { data: data })
depthDecrement(options)
}
if (i === 0) {
ret = inverse(this)
}
return ret
}
|
[
"function",
"children",
"(",
"options",
")",
"{",
"var",
"context",
"=",
"_children",
".",
"call",
"(",
"this",
",",
"options",
")",
"var",
"fn",
"=",
"options",
".",
"fn",
"var",
"inverse",
"=",
"options",
".",
"inverse",
"var",
"i",
"=",
"0",
"var",
"ret",
"=",
"''",
"var",
"data",
"var",
"contextPath",
"if",
"(",
"options",
".",
"data",
")",
"{",
"data",
"=",
"handlebars",
".",
"createFrame",
"(",
"options",
".",
"data",
")",
"}",
"for",
"(",
"var",
"j",
"=",
"context",
".",
"length",
";",
"i",
"<",
"j",
";",
"i",
"++",
")",
"{",
"depthIncrement",
"(",
"options",
")",
"if",
"(",
"data",
")",
"{",
"data",
".",
"index",
"=",
"i",
"data",
".",
"first",
"=",
"(",
"i",
"===",
"0",
")",
"data",
".",
"last",
"=",
"(",
"i",
"===",
"(",
"context",
".",
"length",
"-",
"1",
")",
")",
"if",
"(",
"contextPath",
")",
"{",
"data",
".",
"contextPath",
"=",
"contextPath",
"+",
"i",
"}",
"}",
"ret",
"=",
"ret",
"+",
"fn",
"(",
"context",
"[",
"i",
"]",
",",
"{",
"data",
":",
"data",
"}",
")",
"depthDecrement",
"(",
"options",
")",
"}",
"if",
"(",
"i",
"===",
"0",
")",
"{",
"ret",
"=",
"inverse",
"(",
"this",
")",
"}",
"return",
"ret",
"}"
] |
This helper is a duplicate of the handlebars `each` helper with the one exception that `depthIncrement` is called on each iteration.
@category Block helper: selector
|
[
"This",
"helper",
"is",
"a",
"duplicate",
"of",
"the",
"handlebars",
"each",
"helper",
"with",
"the",
"one",
"exception",
"that",
"depthIncrement",
"is",
"called",
"on",
"each",
"iteration",
"."
] |
a4b31ec41f3b3a523c354877ac488da33314fc1f
|
https://github.com/jsdoc2md/dmd/blob/a4b31ec41f3b3a523c354877ac488da33314fc1f/helpers/ddata.js#L109-L143
|
19,892
|
jsdoc2md/dmd
|
helpers/ddata.js
|
indexChildren
|
function indexChildren (options) {
var context = _children.call(this, options)
var fn = options.fn
var inverse = options.inverse
var i = 0
var ret = ''
var data
var contextPath
if (options.data) {
data = handlebars.createFrame(options.data)
}
for (var j = context.length; i < j; i++) {
indexDepthIncrement(options)
if (data) {
data.index = i
data.first = (i === 0)
data.last = (i === (context.length - 1))
if (contextPath) {
data.contextPath = contextPath + i
}
}
ret = ret + fn(context[i], { data: data })
indexDepthDecrement(options)
}
if (i === 0) {
ret = inverse(this)
}
return ret
}
|
javascript
|
function indexChildren (options) {
var context = _children.call(this, options)
var fn = options.fn
var inverse = options.inverse
var i = 0
var ret = ''
var data
var contextPath
if (options.data) {
data = handlebars.createFrame(options.data)
}
for (var j = context.length; i < j; i++) {
indexDepthIncrement(options)
if (data) {
data.index = i
data.first = (i === 0)
data.last = (i === (context.length - 1))
if (contextPath) {
data.contextPath = contextPath + i
}
}
ret = ret + fn(context[i], { data: data })
indexDepthDecrement(options)
}
if (i === 0) {
ret = inverse(this)
}
return ret
}
|
[
"function",
"indexChildren",
"(",
"options",
")",
"{",
"var",
"context",
"=",
"_children",
".",
"call",
"(",
"this",
",",
"options",
")",
"var",
"fn",
"=",
"options",
".",
"fn",
"var",
"inverse",
"=",
"options",
".",
"inverse",
"var",
"i",
"=",
"0",
"var",
"ret",
"=",
"''",
"var",
"data",
"var",
"contextPath",
"if",
"(",
"options",
".",
"data",
")",
"{",
"data",
"=",
"handlebars",
".",
"createFrame",
"(",
"options",
".",
"data",
")",
"}",
"for",
"(",
"var",
"j",
"=",
"context",
".",
"length",
";",
"i",
"<",
"j",
";",
"i",
"++",
")",
"{",
"indexDepthIncrement",
"(",
"options",
")",
"if",
"(",
"data",
")",
"{",
"data",
".",
"index",
"=",
"i",
"data",
".",
"first",
"=",
"(",
"i",
"===",
"0",
")",
"data",
".",
"last",
"=",
"(",
"i",
"===",
"(",
"context",
".",
"length",
"-",
"1",
")",
")",
"if",
"(",
"contextPath",
")",
"{",
"data",
".",
"contextPath",
"=",
"contextPath",
"+",
"i",
"}",
"}",
"ret",
"=",
"ret",
"+",
"fn",
"(",
"context",
"[",
"i",
"]",
",",
"{",
"data",
":",
"data",
"}",
")",
"indexDepthDecrement",
"(",
"options",
")",
"}",
"if",
"(",
"i",
"===",
"0",
")",
"{",
"ret",
"=",
"inverse",
"(",
"this",
")",
"}",
"return",
"ret",
"}"
] |
This helper is a duplicate of the handlebars `each` helper with the one exception that `indexDepthIncrement` is called on each iteration.
@static
@category Block helper: selector
|
[
"This",
"helper",
"is",
"a",
"duplicate",
"of",
"the",
"handlebars",
"each",
"helper",
"with",
"the",
"one",
"exception",
"that",
"indexDepthIncrement",
"is",
"called",
"on",
"each",
"iteration",
"."
] |
a4b31ec41f3b3a523c354877ac488da33314fc1f
|
https://github.com/jsdoc2md/dmd/blob/a4b31ec41f3b3a523c354877ac488da33314fc1f/helpers/ddata.js#L150-L184
|
19,893
|
jsdoc2md/dmd
|
helpers/ddata.js
|
isClassMember
|
function isClassMember (options) {
var parent = arrayify(options.data.root).find(where({ id: this.memberof }))
if (parent) {
return parent.kind === 'class'
}
}
|
javascript
|
function isClassMember (options) {
var parent = arrayify(options.data.root).find(where({ id: this.memberof }))
if (parent) {
return parent.kind === 'class'
}
}
|
[
"function",
"isClassMember",
"(",
"options",
")",
"{",
"var",
"parent",
"=",
"arrayify",
"(",
"options",
".",
"data",
".",
"root",
")",
".",
"find",
"(",
"where",
"(",
"{",
"id",
":",
"this",
".",
"memberof",
"}",
")",
")",
"if",
"(",
"parent",
")",
"{",
"return",
"parent",
".",
"kind",
"===",
"'class'",
"}",
"}"
] |
returns true if the parent of the current identifier is a class
@returns {boolean}
@static
|
[
"returns",
"true",
"if",
"the",
"parent",
"of",
"the",
"current",
"identifier",
"is",
"a",
"class"
] |
a4b31ec41f3b3a523c354877ac488da33314fc1f
|
https://github.com/jsdoc2md/dmd/blob/a4b31ec41f3b3a523c354877ac488da33314fc1f/helpers/ddata.js#L389-L394
|
19,894
|
jsdoc2md/dmd
|
helpers/ddata.js
|
_orphans
|
function _orphans (options) {
options.hash.memberof = undefined
return _identifiers(options).filter(function (identifier) {
if (identifier.kind === 'external') {
return identifier.description && identifier.description.length > 0
} else {
return true
}
})
}
|
javascript
|
function _orphans (options) {
options.hash.memberof = undefined
return _identifiers(options).filter(function (identifier) {
if (identifier.kind === 'external') {
return identifier.description && identifier.description.length > 0
} else {
return true
}
})
}
|
[
"function",
"_orphans",
"(",
"options",
")",
"{",
"options",
".",
"hash",
".",
"memberof",
"=",
"undefined",
"return",
"_identifiers",
"(",
"options",
")",
".",
"filter",
"(",
"function",
"(",
"identifier",
")",
"{",
"if",
"(",
"identifier",
".",
"kind",
"===",
"'external'",
")",
"{",
"return",
"identifier",
".",
"description",
"&&",
"identifier",
".",
"description",
".",
"length",
">",
"0",
"}",
"else",
"{",
"return",
"true",
"}",
"}",
")",
"}"
] |
Returns an array of the top-level elements which have no parents. Output only includes externals which have a description.
@returns {array}
@static
@category Returns list
|
[
"Returns",
"an",
"array",
"of",
"the",
"top",
"-",
"level",
"elements",
"which",
"have",
"no",
"parents",
".",
"Output",
"only",
"includes",
"externals",
"which",
"have",
"a",
"description",
"."
] |
a4b31ec41f3b3a523c354877ac488da33314fc1f
|
https://github.com/jsdoc2md/dmd/blob/a4b31ec41f3b3a523c354877ac488da33314fc1f/helpers/ddata.js#L433-L442
|
19,895
|
jsdoc2md/dmd
|
helpers/ddata.js
|
_children
|
function _children (options) {
if (!this.id) return []
var min = options.hash.min
delete options.hash.min
options.hash.memberof = this.id
var output = _identifiers(options)
output = output.filter(function (identifier) {
if (identifier.kind === 'external') {
return identifier.description && identifier.description.length > 0
} else {
return true
}
})
if (output.length >= (min || 0)) return output
}
|
javascript
|
function _children (options) {
if (!this.id) return []
var min = options.hash.min
delete options.hash.min
options.hash.memberof = this.id
var output = _identifiers(options)
output = output.filter(function (identifier) {
if (identifier.kind === 'external') {
return identifier.description && identifier.description.length > 0
} else {
return true
}
})
if (output.length >= (min || 0)) return output
}
|
[
"function",
"_children",
"(",
"options",
")",
"{",
"if",
"(",
"!",
"this",
".",
"id",
")",
"return",
"[",
"]",
"var",
"min",
"=",
"options",
".",
"hash",
".",
"min",
"delete",
"options",
".",
"hash",
".",
"min",
"options",
".",
"hash",
".",
"memberof",
"=",
"this",
".",
"id",
"var",
"output",
"=",
"_identifiers",
"(",
"options",
")",
"output",
"=",
"output",
".",
"filter",
"(",
"function",
"(",
"identifier",
")",
"{",
"if",
"(",
"identifier",
".",
"kind",
"===",
"'external'",
")",
"{",
"return",
"identifier",
".",
"description",
"&&",
"identifier",
".",
"description",
".",
"length",
">",
"0",
"}",
"else",
"{",
"return",
"true",
"}",
"}",
")",
"if",
"(",
"output",
".",
"length",
">=",
"(",
"min",
"||",
"0",
")",
")",
"return",
"output",
"}"
] |
return the identifiers which are a `memberof` this one. Exclude externals without descriptions.
@param [sortBy] {string} - "kind"
@param [min] {number} - only returns if there are `min` children
@this {identifier}
@returns {identifier[]}
@static
|
[
"return",
"the",
"identifiers",
"which",
"are",
"a",
"memberof",
"this",
"one",
".",
"Exclude",
"externals",
"without",
"descriptions",
"."
] |
a4b31ec41f3b3a523c354877ac488da33314fc1f
|
https://github.com/jsdoc2md/dmd/blob/a4b31ec41f3b3a523c354877ac488da33314fc1f/helpers/ddata.js#L474-L488
|
19,896
|
jsdoc2md/dmd
|
helpers/ddata.js
|
descendants
|
function descendants (options) {
var min = typeof options.hash.min !== 'undefined' ? options.hash.min : 2
delete options.hash.min
options.hash.memberof = this.id
var output = []
function iterate (childrenList) {
if (childrenList.length) {
childrenList.forEach(function (child) {
output.push(child)
iterate(_children.call(child, options))
})
}
}
iterate(_children.call(this, options))
if (output.length >= (min || 0)) return output
}
|
javascript
|
function descendants (options) {
var min = typeof options.hash.min !== 'undefined' ? options.hash.min : 2
delete options.hash.min
options.hash.memberof = this.id
var output = []
function iterate (childrenList) {
if (childrenList.length) {
childrenList.forEach(function (child) {
output.push(child)
iterate(_children.call(child, options))
})
}
}
iterate(_children.call(this, options))
if (output.length >= (min || 0)) return output
}
|
[
"function",
"descendants",
"(",
"options",
")",
"{",
"var",
"min",
"=",
"typeof",
"options",
".",
"hash",
".",
"min",
"!==",
"'undefined'",
"?",
"options",
".",
"hash",
".",
"min",
":",
"2",
"delete",
"options",
".",
"hash",
".",
"min",
"options",
".",
"hash",
".",
"memberof",
"=",
"this",
".",
"id",
"var",
"output",
"=",
"[",
"]",
"function",
"iterate",
"(",
"childrenList",
")",
"{",
"if",
"(",
"childrenList",
".",
"length",
")",
"{",
"childrenList",
".",
"forEach",
"(",
"function",
"(",
"child",
")",
"{",
"output",
".",
"push",
"(",
"child",
")",
"iterate",
"(",
"_children",
".",
"call",
"(",
"child",
",",
"options",
")",
")",
"}",
")",
"}",
"}",
"iterate",
"(",
"_children",
".",
"call",
"(",
"this",
",",
"options",
")",
")",
"if",
"(",
"output",
".",
"length",
">=",
"(",
"min",
"||",
"0",
")",
")",
"return",
"output",
"}"
] |
return a flat list containing all decendants
@param [sortBy] {string} - "kind"
@param [min] {number} - only returns if there are `min` children
@this {identifier}
@returns {identifier[]}
@static
|
[
"return",
"a",
"flat",
"list",
"containing",
"all",
"decendants"
] |
a4b31ec41f3b3a523c354877ac488da33314fc1f
|
https://github.com/jsdoc2md/dmd/blob/a4b31ec41f3b3a523c354877ac488da33314fc1f/helpers/ddata.js#L498-L513
|
19,897
|
jsdoc2md/dmd
|
helpers/ddata.js
|
exported
|
function exported (options) {
var exp = arrayify(options.data.root).find(where({ '!kind': 'module', id: this.id }))
return exp || this
}
|
javascript
|
function exported (options) {
var exp = arrayify(options.data.root).find(where({ '!kind': 'module', id: this.id }))
return exp || this
}
|
[
"function",
"exported",
"(",
"options",
")",
"{",
"var",
"exp",
"=",
"arrayify",
"(",
"options",
".",
"data",
".",
"root",
")",
".",
"find",
"(",
"where",
"(",
"{",
"'!kind'",
":",
"'module'",
",",
"id",
":",
"this",
".",
"id",
"}",
")",
")",
"return",
"exp",
"||",
"this",
"}"
] |
returns the exported identifier of this module
@this {identifier} - only works on a module
@returns {identifier}
@static
|
[
"returns",
"the",
"exported",
"identifier",
"of",
"this",
"module"
] |
a4b31ec41f3b3a523c354877ac488da33314fc1f
|
https://github.com/jsdoc2md/dmd/blob/a4b31ec41f3b3a523c354877ac488da33314fc1f/helpers/ddata.js#L521-L524
|
19,898
|
jsdoc2md/dmd
|
helpers/ddata.js
|
parentObject
|
function parentObject (options) {
return arrayify(options.data.root).find(where({ id: this.memberof }))
}
|
javascript
|
function parentObject (options) {
return arrayify(options.data.root).find(where({ id: this.memberof }))
}
|
[
"function",
"parentObject",
"(",
"options",
")",
"{",
"return",
"arrayify",
"(",
"options",
".",
"data",
".",
"root",
")",
".",
"find",
"(",
"where",
"(",
"{",
"id",
":",
"this",
".",
"memberof",
"}",
")",
")",
"}"
] |
Returns the parent
@static
|
[
"Returns",
"the",
"parent"
] |
a4b31ec41f3b3a523c354877ac488da33314fc1f
|
https://github.com/jsdoc2md/dmd/blob/a4b31ec41f3b3a523c354877ac488da33314fc1f/helpers/ddata.js#L538-L540
|
19,899
|
jsdoc2md/dmd
|
helpers/ddata.js
|
parseLink
|
function parseLink (text) {
if (!text) return ''
var results = []
var matches = null
var link1 = /{@link (\S+?)}/g // {@link someSymbol}
var link2 = /\[(.+?)\]{@link (\S+?)}/g // [caption here]{@link someSymbol}
var link3 = /{@link ([^\s}]+?)\|(.+?)}/g // {@link someSymbol|caption here}
var link4 = /{@link ([^\s}\|]+?) (.+?)}/g // {@link someSymbol Caption Here}
while ((matches = link4.exec(text)) !== null) {
results.push({
original: matches[0],
caption: matches[2],
url: matches[1]
})
text = text.replace(matches[0], Buffer(matches[0].length).fill(' ').toString())
}
while ((matches = link3.exec(text)) !== null) {
results.push({
original: matches[0],
caption: matches[2],
url: matches[1]
})
text = text.replace(matches[0], Buffer(matches[0].length).fill(' ').toString())
}
while ((matches = link2.exec(text)) !== null) {
results.push({
original: matches[0],
caption: matches[1],
url: matches[2]
})
text = text.replace(matches[0], Buffer(matches[0].length).fill(' ').toString())
}
while ((matches = link1.exec(text)) !== null) {
results.push({
original: matches[0],
caption: matches[1],
url: matches[1]
})
text = text.replace(matches[0], Buffer(matches[0].length).fill(' ').toString())
}
return results
}
|
javascript
|
function parseLink (text) {
if (!text) return ''
var results = []
var matches = null
var link1 = /{@link (\S+?)}/g // {@link someSymbol}
var link2 = /\[(.+?)\]{@link (\S+?)}/g // [caption here]{@link someSymbol}
var link3 = /{@link ([^\s}]+?)\|(.+?)}/g // {@link someSymbol|caption here}
var link4 = /{@link ([^\s}\|]+?) (.+?)}/g // {@link someSymbol Caption Here}
while ((matches = link4.exec(text)) !== null) {
results.push({
original: matches[0],
caption: matches[2],
url: matches[1]
})
text = text.replace(matches[0], Buffer(matches[0].length).fill(' ').toString())
}
while ((matches = link3.exec(text)) !== null) {
results.push({
original: matches[0],
caption: matches[2],
url: matches[1]
})
text = text.replace(matches[0], Buffer(matches[0].length).fill(' ').toString())
}
while ((matches = link2.exec(text)) !== null) {
results.push({
original: matches[0],
caption: matches[1],
url: matches[2]
})
text = text.replace(matches[0], Buffer(matches[0].length).fill(' ').toString())
}
while ((matches = link1.exec(text)) !== null) {
results.push({
original: matches[0],
caption: matches[1],
url: matches[1]
})
text = text.replace(matches[0], Buffer(matches[0].length).fill(' ').toString())
}
return results
}
|
[
"function",
"parseLink",
"(",
"text",
")",
"{",
"if",
"(",
"!",
"text",
")",
"return",
"''",
"var",
"results",
"=",
"[",
"]",
"var",
"matches",
"=",
"null",
"var",
"link1",
"=",
"/",
"{@link (\\S+?)}",
"/",
"g",
"// {@link someSymbol}",
"var",
"link2",
"=",
"/",
"\\[(.+?)\\]{@link (\\S+?)}",
"/",
"g",
"// [caption here]{@link someSymbol}",
"var",
"link3",
"=",
"/",
"{@link ([^\\s}]+?)\\|(.+?)}",
"/",
"g",
"// {@link someSymbol|caption here}",
"var",
"link4",
"=",
"/",
"{@link ([^\\s}\\|]+?) (.+?)}",
"/",
"g",
"// {@link someSymbol Caption Here}",
"while",
"(",
"(",
"matches",
"=",
"link4",
".",
"exec",
"(",
"text",
")",
")",
"!==",
"null",
")",
"{",
"results",
".",
"push",
"(",
"{",
"original",
":",
"matches",
"[",
"0",
"]",
",",
"caption",
":",
"matches",
"[",
"2",
"]",
",",
"url",
":",
"matches",
"[",
"1",
"]",
"}",
")",
"text",
"=",
"text",
".",
"replace",
"(",
"matches",
"[",
"0",
"]",
",",
"Buffer",
"(",
"matches",
"[",
"0",
"]",
".",
"length",
")",
".",
"fill",
"(",
"' '",
")",
".",
"toString",
"(",
")",
")",
"}",
"while",
"(",
"(",
"matches",
"=",
"link3",
".",
"exec",
"(",
"text",
")",
")",
"!==",
"null",
")",
"{",
"results",
".",
"push",
"(",
"{",
"original",
":",
"matches",
"[",
"0",
"]",
",",
"caption",
":",
"matches",
"[",
"2",
"]",
",",
"url",
":",
"matches",
"[",
"1",
"]",
"}",
")",
"text",
"=",
"text",
".",
"replace",
"(",
"matches",
"[",
"0",
"]",
",",
"Buffer",
"(",
"matches",
"[",
"0",
"]",
".",
"length",
")",
".",
"fill",
"(",
"' '",
")",
".",
"toString",
"(",
")",
")",
"}",
"while",
"(",
"(",
"matches",
"=",
"link2",
".",
"exec",
"(",
"text",
")",
")",
"!==",
"null",
")",
"{",
"results",
".",
"push",
"(",
"{",
"original",
":",
"matches",
"[",
"0",
"]",
",",
"caption",
":",
"matches",
"[",
"1",
"]",
",",
"url",
":",
"matches",
"[",
"2",
"]",
"}",
")",
"text",
"=",
"text",
".",
"replace",
"(",
"matches",
"[",
"0",
"]",
",",
"Buffer",
"(",
"matches",
"[",
"0",
"]",
".",
"length",
")",
".",
"fill",
"(",
"' '",
")",
".",
"toString",
"(",
")",
")",
"}",
"while",
"(",
"(",
"matches",
"=",
"link1",
".",
"exec",
"(",
"text",
")",
")",
"!==",
"null",
")",
"{",
"results",
".",
"push",
"(",
"{",
"original",
":",
"matches",
"[",
"0",
"]",
",",
"caption",
":",
"matches",
"[",
"1",
"]",
",",
"url",
":",
"matches",
"[",
"1",
"]",
"}",
")",
"text",
"=",
"text",
".",
"replace",
"(",
"matches",
"[",
"0",
"]",
",",
"Buffer",
"(",
"matches",
"[",
"0",
"]",
".",
"length",
")",
".",
"fill",
"(",
"' '",
")",
".",
"toString",
"(",
")",
")",
"}",
"return",
"results",
"}"
] |
extracts url and caption data from @link tags
@param {string} - a string containing one or more {@link} tags
@returns {Array.<{original: string, caption: string, url: string}>}
@static
|
[
"extracts",
"url",
"and",
"caption",
"data",
"from"
] |
a4b31ec41f3b3a523c354877ac488da33314fc1f
|
https://github.com/jsdoc2md/dmd/blob/a4b31ec41f3b3a523c354877ac488da33314fc1f/helpers/ddata.js#L617-L662
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.