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
sequence | docstring
stringlengths 4
11.8k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 86
226
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
zaim/webcolors | gulpfile.js | fixMissing | function fixMissing (obj, defaults) {
Object.keys(defaults).forEach(function (key) {
obj[key] = obj[key] || defaults[key];
});
} | javascript | function fixMissing (obj, defaults) {
Object.keys(defaults).forEach(function (key) {
obj[key] = obj[key] || defaults[key];
});
} | [
"function",
"fixMissing",
"(",
"obj",
",",
"defaults",
")",
"{",
"Object",
".",
"keys",
"(",
"defaults",
")",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"obj",
"[",
"key",
"]",
"=",
"obj",
"[",
"key",
"]",
"||",
"defaults",
"[",
"key",
"]",
";",
"}",
")",
";",
"}"
] | Fix missing values | [
"Fix",
"missing",
"values"
] | 548d4466c653336f8c861ddedf67d432a804590e | https://github.com/zaim/webcolors/blob/548d4466c653336f8c861ddedf67d432a804590e/gulpfile.js#L31-L35 | train |
zaim/webcolors | gulpfile.js | repoIsClean | function repoIsClean (done) {
proc.exec('git status -z', function (err, stdout) {
if (!err) {
var msg = stdout.toString().trim();
if (msg && msg.length) {
err = new Error('Please commit all changes generated by building');
}
}
done(err);
});
} | javascript | function repoIsClean (done) {
proc.exec('git status -z', function (err, stdout) {
if (!err) {
var msg = stdout.toString().trim();
if (msg && msg.length) {
err = new Error('Please commit all changes generated by building');
}
}
done(err);
});
} | [
"function",
"repoIsClean",
"(",
"done",
")",
"{",
"proc",
".",
"exec",
"(",
"'git status -z'",
",",
"function",
"(",
"err",
",",
"stdout",
")",
"{",
"if",
"(",
"!",
"err",
")",
"{",
"var",
"msg",
"=",
"stdout",
".",
"toString",
"(",
")",
".",
"trim",
"(",
")",
";",
"if",
"(",
"msg",
"&&",
"msg",
".",
"length",
")",
"{",
"err",
"=",
"new",
"Error",
"(",
"'Please commit all changes generated by building'",
")",
";",
"}",
"}",
"done",
"(",
"err",
")",
";",
"}",
")",
";",
"}"
] | Check if repo is clean | [
"Check",
"if",
"repo",
"is",
"clean"
] | 548d4466c653336f8c861ddedf67d432a804590e | https://github.com/zaim/webcolors/blob/548d4466c653336f8c861ddedf67d432a804590e/gulpfile.js#L38-L48 | train |
WorldMobileCoin/wmcc-core | src/primitives/address.js | Address | function Address(options) {
if (!(this instanceof Address))
return new Address(options);
this.hash = encoding.ZERO_HASH160;
this.type = Address.types.PUBKEYHASH;
this.version = -1;
this.network = Network.primary;
if (options)
this.fromOptions(options);
} | javascript | function Address(options) {
if (!(this instanceof Address))
return new Address(options);
this.hash = encoding.ZERO_HASH160;
this.type = Address.types.PUBKEYHASH;
this.version = -1;
this.network = Network.primary;
if (options)
this.fromOptions(options);
} | [
"function",
"Address",
"(",
"options",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Address",
")",
")",
"return",
"new",
"Address",
"(",
"options",
")",
";",
"this",
".",
"hash",
"=",
"encoding",
".",
"ZERO_HASH160",
";",
"this",
".",
"type",
"=",
"Address",
".",
"types",
".",
"PUBKEYHASH",
";",
"this",
".",
"version",
"=",
"-",
"1",
";",
"this",
".",
"network",
"=",
"Network",
".",
"primary",
";",
"if",
"(",
"options",
")",
"this",
".",
"fromOptions",
"(",
"options",
")",
";",
"}"
] | Represents an address.
@alias module:primitives.Address
@constructor
@param {Object?} options
@property {Buffer} hash
@property {AddressPrefix} type
@property {Number} version
@property {Network} network | [
"Represents",
"an",
"address",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/primitives/address.js#L35-L46 | train |
WorldMobileCoin/wmcc-core | src/primitives/abstractblock.js | AbstractBlock | function AbstractBlock() {
if (!(this instanceof AbstractBlock))
return new AbstractBlock();
this.version = 1;
this.prevBlock = encoding.NULL_HASH;
this.merkleRoot = encoding.NULL_HASH;
this.time = 0;
this.bits = 0;
this.nonce = 0;
this.mutable = false;
this._hash = null;
this._hhash = null;
} | javascript | function AbstractBlock() {
if (!(this instanceof AbstractBlock))
return new AbstractBlock();
this.version = 1;
this.prevBlock = encoding.NULL_HASH;
this.merkleRoot = encoding.NULL_HASH;
this.time = 0;
this.bits = 0;
this.nonce = 0;
this.mutable = false;
this._hash = null;
this._hhash = null;
} | [
"function",
"AbstractBlock",
"(",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"AbstractBlock",
")",
")",
"return",
"new",
"AbstractBlock",
"(",
")",
";",
"this",
".",
"version",
"=",
"1",
";",
"this",
".",
"prevBlock",
"=",
"encoding",
".",
"NULL_HASH",
";",
"this",
".",
"merkleRoot",
"=",
"encoding",
".",
"NULL_HASH",
";",
"this",
".",
"time",
"=",
"0",
";",
"this",
".",
"bits",
"=",
"0",
";",
"this",
".",
"nonce",
"=",
"0",
";",
"this",
".",
"mutable",
"=",
"false",
";",
"this",
".",
"_hash",
"=",
"null",
";",
"this",
".",
"_hhash",
"=",
"null",
";",
"}"
] | The class which all block-like objects inherit from.
@alias module:primitives.AbstractBlock
@constructor
@abstract
@property {Number} version - Block version. Note
that WMCC reads versions as unsigned despite
them being signed on the protocol level. This
number will never be negative.
@property {Hash} prevBlock - Previous block hash.
@property {Hash} merkleRoot - Merkle root hash.
@property {Number} time - Timestamp.
@property {Number} bits
@property {Number} nonce | [
"The",
"class",
"which",
"all",
"block",
"-",
"like",
"objects",
"inherit",
"from",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/primitives/abstractblock.js#L41-L56 | train |
WorldMobileCoin/wmcc-core | src/node/spvnode.js | SPVNode | function SPVNode(options) {
if (!(this instanceof SPVNode))
return new SPVNode(options);
Node.call(this, options);
// SPV flag.
this.spv = true;
this.chain = new Chain({
network: this.network,
logger: this.logger,
db: this.config.str('db'),
prefix: this.config.prefix,
maxFiles: this.config.uint('max-files'),
cacheSize: this.config.mb('cache-size'),
entryCache: this.config.uint('entry-cache'),
forceFlags: this.config.bool('force-flags'),
checkpoints: this.config.bool('checkpoints'),
bip91: this.config.bool('bip91'),
bip148: this.config.bool('bip148'),
spv: true
});
this.pool = new Pool({
network: this.network,
logger: this.logger,
chain: this.chain,
prefix: this.config.prefix,
proxy: this.config.str('proxy'),
onion: this.config.bool('onion'),
upnp: this.config.bool('upnp'),
seeds: this.config.array('seeds'),
nodes: this.config.array('nodes'),
only: this.config.array('only'),
bip151: this.config.bool('bip151'),
bip150: this.config.bool('bip150'),
identityKey: this.config.buf('identity-key'),
maxOutbound: this.config.uint('max-outbound'),
persistent: this.config.bool('persistent'),
selfish: true,
listen: false
});
this.rpc = new RPC(this);
if (!HTTPServer.unsupported) {
this.http = new HTTPServer({
network: this.network,
logger: this.logger,
node: this,
prefix: this.config.prefix,
ssl: this.config.bool('ssl'),
keyFile: this.config.path('ssl-key'),
certFile: this.config.path('ssl-cert'),
host: this.config.str('http-host'),
port: this.config.uint('http-port'),
apiKey: this.config.str('api-key'),
noAuth: this.config.bool('no-auth')
});
}
this.rescanJob = null;
this.scanLock = new Lock();
this.watchLock = new Lock();
this._init();
} | javascript | function SPVNode(options) {
if (!(this instanceof SPVNode))
return new SPVNode(options);
Node.call(this, options);
// SPV flag.
this.spv = true;
this.chain = new Chain({
network: this.network,
logger: this.logger,
db: this.config.str('db'),
prefix: this.config.prefix,
maxFiles: this.config.uint('max-files'),
cacheSize: this.config.mb('cache-size'),
entryCache: this.config.uint('entry-cache'),
forceFlags: this.config.bool('force-flags'),
checkpoints: this.config.bool('checkpoints'),
bip91: this.config.bool('bip91'),
bip148: this.config.bool('bip148'),
spv: true
});
this.pool = new Pool({
network: this.network,
logger: this.logger,
chain: this.chain,
prefix: this.config.prefix,
proxy: this.config.str('proxy'),
onion: this.config.bool('onion'),
upnp: this.config.bool('upnp'),
seeds: this.config.array('seeds'),
nodes: this.config.array('nodes'),
only: this.config.array('only'),
bip151: this.config.bool('bip151'),
bip150: this.config.bool('bip150'),
identityKey: this.config.buf('identity-key'),
maxOutbound: this.config.uint('max-outbound'),
persistent: this.config.bool('persistent'),
selfish: true,
listen: false
});
this.rpc = new RPC(this);
if (!HTTPServer.unsupported) {
this.http = new HTTPServer({
network: this.network,
logger: this.logger,
node: this,
prefix: this.config.prefix,
ssl: this.config.bool('ssl'),
keyFile: this.config.path('ssl-key'),
certFile: this.config.path('ssl-cert'),
host: this.config.str('http-host'),
port: this.config.uint('http-port'),
apiKey: this.config.str('api-key'),
noAuth: this.config.bool('no-auth')
});
}
this.rescanJob = null;
this.scanLock = new Lock();
this.watchLock = new Lock();
this._init();
} | [
"function",
"SPVNode",
"(",
"options",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"SPVNode",
")",
")",
"return",
"new",
"SPVNode",
"(",
"options",
")",
";",
"Node",
".",
"call",
"(",
"this",
",",
"options",
")",
";",
"this",
".",
"spv",
"=",
"true",
";",
"this",
".",
"chain",
"=",
"new",
"Chain",
"(",
"{",
"network",
":",
"this",
".",
"network",
",",
"logger",
":",
"this",
".",
"logger",
",",
"db",
":",
"this",
".",
"config",
".",
"str",
"(",
"'db'",
")",
",",
"prefix",
":",
"this",
".",
"config",
".",
"prefix",
",",
"maxFiles",
":",
"this",
".",
"config",
".",
"uint",
"(",
"'max-files'",
")",
",",
"cacheSize",
":",
"this",
".",
"config",
".",
"mb",
"(",
"'cache-size'",
")",
",",
"entryCache",
":",
"this",
".",
"config",
".",
"uint",
"(",
"'entry-cache'",
")",
",",
"forceFlags",
":",
"this",
".",
"config",
".",
"bool",
"(",
"'force-flags'",
")",
",",
"checkpoints",
":",
"this",
".",
"config",
".",
"bool",
"(",
"'checkpoints'",
")",
",",
"bip91",
":",
"this",
".",
"config",
".",
"bool",
"(",
"'bip91'",
")",
",",
"bip148",
":",
"this",
".",
"config",
".",
"bool",
"(",
"'bip148'",
")",
",",
"spv",
":",
"true",
"}",
")",
";",
"this",
".",
"pool",
"=",
"new",
"Pool",
"(",
"{",
"network",
":",
"this",
".",
"network",
",",
"logger",
":",
"this",
".",
"logger",
",",
"chain",
":",
"this",
".",
"chain",
",",
"prefix",
":",
"this",
".",
"config",
".",
"prefix",
",",
"proxy",
":",
"this",
".",
"config",
".",
"str",
"(",
"'proxy'",
")",
",",
"onion",
":",
"this",
".",
"config",
".",
"bool",
"(",
"'onion'",
")",
",",
"upnp",
":",
"this",
".",
"config",
".",
"bool",
"(",
"'upnp'",
")",
",",
"seeds",
":",
"this",
".",
"config",
".",
"array",
"(",
"'seeds'",
")",
",",
"nodes",
":",
"this",
".",
"config",
".",
"array",
"(",
"'nodes'",
")",
",",
"only",
":",
"this",
".",
"config",
".",
"array",
"(",
"'only'",
")",
",",
"bip151",
":",
"this",
".",
"config",
".",
"bool",
"(",
"'bip151'",
")",
",",
"bip150",
":",
"this",
".",
"config",
".",
"bool",
"(",
"'bip150'",
")",
",",
"identityKey",
":",
"this",
".",
"config",
".",
"buf",
"(",
"'identity-key'",
")",
",",
"maxOutbound",
":",
"this",
".",
"config",
".",
"uint",
"(",
"'max-outbound'",
")",
",",
"persistent",
":",
"this",
".",
"config",
".",
"bool",
"(",
"'persistent'",
")",
",",
"selfish",
":",
"true",
",",
"listen",
":",
"false",
"}",
")",
";",
"this",
".",
"rpc",
"=",
"new",
"RPC",
"(",
"this",
")",
";",
"if",
"(",
"!",
"HTTPServer",
".",
"unsupported",
")",
"{",
"this",
".",
"http",
"=",
"new",
"HTTPServer",
"(",
"{",
"network",
":",
"this",
".",
"network",
",",
"logger",
":",
"this",
".",
"logger",
",",
"node",
":",
"this",
",",
"prefix",
":",
"this",
".",
"config",
".",
"prefix",
",",
"ssl",
":",
"this",
".",
"config",
".",
"bool",
"(",
"'ssl'",
")",
",",
"keyFile",
":",
"this",
".",
"config",
".",
"path",
"(",
"'ssl-key'",
")",
",",
"certFile",
":",
"this",
".",
"config",
".",
"path",
"(",
"'ssl-cert'",
")",
",",
"host",
":",
"this",
".",
"config",
".",
"str",
"(",
"'http-host'",
")",
",",
"port",
":",
"this",
".",
"config",
".",
"uint",
"(",
"'http-port'",
")",
",",
"apiKey",
":",
"this",
".",
"config",
".",
"str",
"(",
"'api-key'",
")",
",",
"noAuth",
":",
"this",
".",
"config",
".",
"bool",
"(",
"'no-auth'",
")",
"}",
")",
";",
"}",
"this",
".",
"rescanJob",
"=",
"null",
";",
"this",
".",
"scanLock",
"=",
"new",
"Lock",
"(",
")",
";",
"this",
".",
"watchLock",
"=",
"new",
"Lock",
"(",
")",
";",
"this",
".",
"_init",
"(",
")",
";",
"}"
] | Create an spv node which only maintains
a chain, a pool, and an http server.
@alias module:node.SPVNode
@extends Node
@constructor
@param {Object?} options
@param {Buffer?} options.sslKey
@param {Buffer?} options.sslCert
@param {Number?} options.httpPort
@param {String?} options.httpHost
@property {Boolean} loaded
@property {Chain} chain
@property {Pool} pool
@property {HTTPServer} http
@emits SPVNode#block
@emits SPVNode#tx
@emits SPVNode#error | [
"Create",
"an",
"spv",
"node",
"which",
"only",
"maintains",
"a",
"chain",
"a",
"pool",
"and",
"an",
"http",
"server",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/node/spvnode.js#L41-L108 | train |
gw2efficiency/recipe-calculation | src/craftingSteps.js | craftingSteps | function craftingSteps (tree, steps = [], index = 0) {
// Skip any tree parts where nothing needs to be crafted
if (!tree.components || tree.craft === false) {
return steps
}
// Go through the existing steps, and if we already have a step
// with this id, just add up the quantities
let stepIndex = steps.findIndex(step => step.id === tree.id)
if (stepIndex !== -1) {
steps[stepIndex].quantity += tree.usedQuantity
steps[stepIndex].components = steps[stepIndex].components
.map(component => {
let treeComponent = tree.components.find(tC => tC.id === component.id)
component.quantity += treeComponent.totalQuantity
return component
})
index = stepIndex
}
// We don't have a step like this yet, push a new one at the given index
if (stepIndex === -1) {
steps.splice(index, 0, {
id: tree.id,
output: tree.output,
quantity: tree.usedQuantity,
components: tree.components.map(component => {
return {id: component.id, quantity: component.totalQuantity}
})
})
}
// Go through the components and push them after the index of their parent
tree.components.map(component => craftingSteps(component, steps, index + 1))
return steps
} | javascript | function craftingSteps (tree, steps = [], index = 0) {
// Skip any tree parts where nothing needs to be crafted
if (!tree.components || tree.craft === false) {
return steps
}
// Go through the existing steps, and if we already have a step
// with this id, just add up the quantities
let stepIndex = steps.findIndex(step => step.id === tree.id)
if (stepIndex !== -1) {
steps[stepIndex].quantity += tree.usedQuantity
steps[stepIndex].components = steps[stepIndex].components
.map(component => {
let treeComponent = tree.components.find(tC => tC.id === component.id)
component.quantity += treeComponent.totalQuantity
return component
})
index = stepIndex
}
// We don't have a step like this yet, push a new one at the given index
if (stepIndex === -1) {
steps.splice(index, 0, {
id: tree.id,
output: tree.output,
quantity: tree.usedQuantity,
components: tree.components.map(component => {
return {id: component.id, quantity: component.totalQuantity}
})
})
}
// Go through the components and push them after the index of their parent
tree.components.map(component => craftingSteps(component, steps, index + 1))
return steps
} | [
"function",
"craftingSteps",
"(",
"tree",
",",
"steps",
"=",
"[",
"]",
",",
"index",
"=",
"0",
")",
"{",
"if",
"(",
"!",
"tree",
".",
"components",
"||",
"tree",
".",
"craft",
"===",
"false",
")",
"{",
"return",
"steps",
"}",
"let",
"stepIndex",
"=",
"steps",
".",
"findIndex",
"(",
"step",
"=>",
"step",
".",
"id",
"===",
"tree",
".",
"id",
")",
"if",
"(",
"stepIndex",
"!==",
"-",
"1",
")",
"{",
"steps",
"[",
"stepIndex",
"]",
".",
"quantity",
"+=",
"tree",
".",
"usedQuantity",
"steps",
"[",
"stepIndex",
"]",
".",
"components",
"=",
"steps",
"[",
"stepIndex",
"]",
".",
"components",
".",
"map",
"(",
"component",
"=>",
"{",
"let",
"treeComponent",
"=",
"tree",
".",
"components",
".",
"find",
"(",
"tC",
"=>",
"tC",
".",
"id",
"===",
"component",
".",
"id",
")",
"component",
".",
"quantity",
"+=",
"treeComponent",
".",
"totalQuantity",
"return",
"component",
"}",
")",
"index",
"=",
"stepIndex",
"}",
"if",
"(",
"stepIndex",
"===",
"-",
"1",
")",
"{",
"steps",
".",
"splice",
"(",
"index",
",",
"0",
",",
"{",
"id",
":",
"tree",
".",
"id",
",",
"output",
":",
"tree",
".",
"output",
",",
"quantity",
":",
"tree",
".",
"usedQuantity",
",",
"components",
":",
"tree",
".",
"components",
".",
"map",
"(",
"component",
"=>",
"{",
"return",
"{",
"id",
":",
"component",
".",
"id",
",",
"quantity",
":",
"component",
".",
"totalQuantity",
"}",
"}",
")",
"}",
")",
"}",
"tree",
".",
"components",
".",
"map",
"(",
"component",
"=>",
"craftingSteps",
"(",
"component",
",",
"steps",
",",
"index",
"+",
"1",
")",
")",
"return",
"steps",
"}"
] | Generate an ordered list of crafting steps | [
"Generate",
"an",
"ordered",
"list",
"of",
"crafting",
"steps"
] | 841d16750cb23c61850f8452492bfbf90db6db7c | https://github.com/gw2efficiency/recipe-calculation/blob/841d16750cb23c61850f8452492bfbf90db6db7c/src/craftingSteps.js#L29-L64 | train |
okunishinishi/node-gitconfig | lib/fetch_repo.js | getAllRemotesUrls | function getAllRemotesUrls (getGitInfo) {
const remotes = lget(getGitInfo, 'remote', {});
return Object.keys(remotes).map(key => lget(remotes[key],'url'));
} | javascript | function getAllRemotesUrls (getGitInfo) {
const remotes = lget(getGitInfo, 'remote', {});
return Object.keys(remotes).map(key => lget(remotes[key],'url'));
} | [
"function",
"getAllRemotesUrls",
"(",
"getGitInfo",
")",
"{",
"const",
"remotes",
"=",
"lget",
"(",
"getGitInfo",
",",
"'remote'",
",",
"{",
"}",
")",
";",
"return",
"Object",
".",
"keys",
"(",
"remotes",
")",
".",
"map",
"(",
"key",
"=>",
"lget",
"(",
"remotes",
"[",
"key",
"]",
",",
"'url'",
")",
")",
";",
"}"
] | Get all remote urls from current project
@function getAllRemotesUrls
@returns {Array<String>} | [
"Get",
"all",
"remote",
"urls",
"from",
"current",
"project"
] | bb1a82cb60a19f59920e043b4b3615f51d2604d4 | https://github.com/okunishinishi/node-gitconfig/blob/bb1a82cb60a19f59920e043b4b3615f51d2604d4/lib/fetch_repo.js#L19-L22 | train |
okunishinishi/node-gitconfig | lib/fetch_repo.js | getUrl | function getUrl(remoteName){
const gitInfo = getGitInfo();
return remoteName ? getRepoRemoteUrl(gitInfo, remoteName) : getAllRemotesUrls(gitInfo);
} | javascript | function getUrl(remoteName){
const gitInfo = getGitInfo();
return remoteName ? getRepoRemoteUrl(gitInfo, remoteName) : getAllRemotesUrls(gitInfo);
} | [
"function",
"getUrl",
"(",
"remoteName",
")",
"{",
"const",
"gitInfo",
"=",
"getGitInfo",
"(",
")",
";",
"return",
"remoteName",
"?",
"getRepoRemoteUrl",
"(",
"gitInfo",
",",
"remoteName",
")",
":",
"getAllRemotesUrls",
"(",
"gitInfo",
")",
";",
"}"
] | Get all remote url or all remote urls from current project
@param remoteName - string
@function getAllRemotesUrls
@returns {Array<string> | string} | [
"Get",
"all",
"remote",
"url",
"or",
"all",
"remote",
"urls",
"from",
"current",
"project"
] | bb1a82cb60a19f59920e043b4b3615f51d2604d4 | https://github.com/okunishinishi/node-gitconfig/blob/bb1a82cb60a19f59920e043b4b3615f51d2604d4/lib/fetch_repo.js#L40-L43 | train |
dashby3000/loopback-connector-twilio | lib/twilio.js | TwilioConnector | function TwilioConnector(settings) {
assert(typeof settings === 'object', 'cannot initialize TwilioConnector without a settings object');
var connector = this;
var accountSid = this.accountSid = settings.accountSid;
var authToken = this.authToken = settings.authToken;
var sgAPIKey = this.sgAPIKey = settings.sgAPIKey;
twilio = connector.twilio = require('twilio')(accountSid, authToken);
sgMail = connector.sgMail = require('@sendgrid/mail');
sgMail.setApiKey(sgAPIKey);
} | javascript | function TwilioConnector(settings) {
assert(typeof settings === 'object', 'cannot initialize TwilioConnector without a settings object');
var connector = this;
var accountSid = this.accountSid = settings.accountSid;
var authToken = this.authToken = settings.authToken;
var sgAPIKey = this.sgAPIKey = settings.sgAPIKey;
twilio = connector.twilio = require('twilio')(accountSid, authToken);
sgMail = connector.sgMail = require('@sendgrid/mail');
sgMail.setApiKey(sgAPIKey);
} | [
"function",
"TwilioConnector",
"(",
"settings",
")",
"{",
"assert",
"(",
"typeof",
"settings",
"===",
"'object'",
",",
"'cannot initialize TwilioConnector without a settings object'",
")",
";",
"var",
"connector",
"=",
"this",
";",
"var",
"accountSid",
"=",
"this",
".",
"accountSid",
"=",
"settings",
".",
"accountSid",
";",
"var",
"authToken",
"=",
"this",
".",
"authToken",
"=",
"settings",
".",
"authToken",
";",
"var",
"sgAPIKey",
"=",
"this",
".",
"sgAPIKey",
"=",
"settings",
".",
"sgAPIKey",
";",
"twilio",
"=",
"connector",
".",
"twilio",
"=",
"require",
"(",
"'twilio'",
")",
"(",
"accountSid",
",",
"authToken",
")",
";",
"sgMail",
"=",
"connector",
".",
"sgMail",
"=",
"require",
"(",
"'@sendgrid/mail'",
")",
";",
"sgMail",
".",
"setApiKey",
"(",
"sgAPIKey",
")",
";",
"}"
] | Create an instance of the connector with the given `settings`. | [
"Create",
"an",
"instance",
"of",
"the",
"connector",
"with",
"the",
"given",
"settings",
"."
] | 3c64f7414dadfbb389428f7dea1b7d4b197abb45 | https://github.com/dashby3000/loopback-connector-twilio/blob/3c64f7414dadfbb389428f7dea1b7d4b197abb45/lib/twilio.js#L16-L28 | train |
WorldMobileCoin/wmcc-core | src/wallet/masterkey.js | MasterKey | function MasterKey(options) {
if (!(this instanceof MasterKey))
return new MasterKey(options);
this.encrypted = false;
this.iv = null;
this.ciphertext = null;
this.key = null;
this.mnemonic = null;
this.alg = MasterKey.alg.PBKDF2;
this.N = 50000;
this.r = 0;
this.p = 0;
this.aesKey = null;
this.timer = null;
this.until = 0;
this._onTimeout = this.lock.bind(this);
this.locker = new Lock();
if (options)
this.fromOptions(options);
} | javascript | function MasterKey(options) {
if (!(this instanceof MasterKey))
return new MasterKey(options);
this.encrypted = false;
this.iv = null;
this.ciphertext = null;
this.key = null;
this.mnemonic = null;
this.alg = MasterKey.alg.PBKDF2;
this.N = 50000;
this.r = 0;
this.p = 0;
this.aesKey = null;
this.timer = null;
this.until = 0;
this._onTimeout = this.lock.bind(this);
this.locker = new Lock();
if (options)
this.fromOptions(options);
} | [
"function",
"MasterKey",
"(",
"options",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"MasterKey",
")",
")",
"return",
"new",
"MasterKey",
"(",
"options",
")",
";",
"this",
".",
"encrypted",
"=",
"false",
";",
"this",
".",
"iv",
"=",
"null",
";",
"this",
".",
"ciphertext",
"=",
"null",
";",
"this",
".",
"key",
"=",
"null",
";",
"this",
".",
"mnemonic",
"=",
"null",
";",
"this",
".",
"alg",
"=",
"MasterKey",
".",
"alg",
".",
"PBKDF2",
";",
"this",
".",
"N",
"=",
"50000",
";",
"this",
".",
"r",
"=",
"0",
";",
"this",
".",
"p",
"=",
"0",
";",
"this",
".",
"aesKey",
"=",
"null",
";",
"this",
".",
"timer",
"=",
"null",
";",
"this",
".",
"until",
"=",
"0",
";",
"this",
".",
"_onTimeout",
"=",
"this",
".",
"lock",
".",
"bind",
"(",
"this",
")",
";",
"this",
".",
"locker",
"=",
"new",
"Lock",
"(",
")",
";",
"if",
"(",
"options",
")",
"this",
".",
"fromOptions",
"(",
"options",
")",
";",
"}"
] | Master BIP32 key which can exist
in a timed out encrypted state.
@alias module:wallet.MasterKey
@constructor
@param {Object} options | [
"Master",
"BIP32",
"key",
"which",
"can",
"exist",
"in",
"a",
"timed",
"out",
"encrypted",
"state",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/wallet/masterkey.js#L35-L58 | train |
WorldMobileCoin/wmcc-core | src/net/bip151.js | BIP151Stream | function BIP151Stream(cipher) {
if (!(this instanceof BIP151Stream))
return new BIP151Stream(cipher);
this.cipher = BIP151.ciphers.CHACHAPOLY;
this.privateKey = secp256k1.generatePrivateKey();
this.publicKey = null;
this.k1 = null;
this.k2 = null;
this.sid = null;
if (cipher != null) {
assert(cipher === BIP151.ciphers.CHACHAPOLY, 'Unknown cipher type.');
this.cipher = cipher;
}
this.chacha = new ChaCha20();
this.aead = new AEAD();
this.tag = null;
this.seq = 0;
this.iv = Buffer.allocUnsafe(8);
this.iv.fill(0);
this.processed = 0;
this.lastRekey = 0;
} | javascript | function BIP151Stream(cipher) {
if (!(this instanceof BIP151Stream))
return new BIP151Stream(cipher);
this.cipher = BIP151.ciphers.CHACHAPOLY;
this.privateKey = secp256k1.generatePrivateKey();
this.publicKey = null;
this.k1 = null;
this.k2 = null;
this.sid = null;
if (cipher != null) {
assert(cipher === BIP151.ciphers.CHACHAPOLY, 'Unknown cipher type.');
this.cipher = cipher;
}
this.chacha = new ChaCha20();
this.aead = new AEAD();
this.tag = null;
this.seq = 0;
this.iv = Buffer.allocUnsafe(8);
this.iv.fill(0);
this.processed = 0;
this.lastRekey = 0;
} | [
"function",
"BIP151Stream",
"(",
"cipher",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"BIP151Stream",
")",
")",
"return",
"new",
"BIP151Stream",
"(",
"cipher",
")",
";",
"this",
".",
"cipher",
"=",
"BIP151",
".",
"ciphers",
".",
"CHACHAPOLY",
";",
"this",
".",
"privateKey",
"=",
"secp256k1",
".",
"generatePrivateKey",
"(",
")",
";",
"this",
".",
"publicKey",
"=",
"null",
";",
"this",
".",
"k1",
"=",
"null",
";",
"this",
".",
"k2",
"=",
"null",
";",
"this",
".",
"sid",
"=",
"null",
";",
"if",
"(",
"cipher",
"!=",
"null",
")",
"{",
"assert",
"(",
"cipher",
"===",
"BIP151",
".",
"ciphers",
".",
"CHACHAPOLY",
",",
"'Unknown cipher type.'",
")",
";",
"this",
".",
"cipher",
"=",
"cipher",
";",
"}",
"this",
".",
"chacha",
"=",
"new",
"ChaCha20",
"(",
")",
";",
"this",
".",
"aead",
"=",
"new",
"AEAD",
"(",
")",
";",
"this",
".",
"tag",
"=",
"null",
";",
"this",
".",
"seq",
"=",
"0",
";",
"this",
".",
"iv",
"=",
"Buffer",
".",
"allocUnsafe",
"(",
"8",
")",
";",
"this",
".",
"iv",
".",
"fill",
"(",
"0",
")",
";",
"this",
".",
"processed",
"=",
"0",
";",
"this",
".",
"lastRekey",
"=",
"0",
";",
"}"
] | Represents a BIP151 input or output stream.
@alias module:net.BIP151Stream
@constructor
@param {Number} cipher
@property {Buffer} publicKey
@property {Buffer} privateKey
@property {Number} cipher
@property {Buffer} k1
@property {Buffer} k2
@property {Buffer} sid
@property {ChaCha20} chacha
@property {AEAD} aead
@property {Buffer} tag
@property {Number} seq
@property {Number} processed
@property {Number} lastKey | [
"Represents",
"a",
"BIP151",
"input",
"or",
"output",
"stream",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/net/bip151.js#L66-L91 | train |
WorldMobileCoin/wmcc-core | src/net/bip151.js | BIP151 | function BIP151(cipher) {
if (!(this instanceof BIP151))
return new BIP151(cipher);
EventEmitter.call(this);
this.input = new BIP151Stream(cipher);
this.output = new BIP151Stream(cipher);
this.initReceived = false;
this.ackReceived = false;
this.initSent = false;
this.ackSent = false;
this.completed = false;
this.handshake = false;
this.pending = [];
this.total = 0;
this.waiting = 4;
this.hasSize = false;
this.timeout = null;
this.job = null;
this.onShake = null;
this.bip150 = null;
} | javascript | function BIP151(cipher) {
if (!(this instanceof BIP151))
return new BIP151(cipher);
EventEmitter.call(this);
this.input = new BIP151Stream(cipher);
this.output = new BIP151Stream(cipher);
this.initReceived = false;
this.ackReceived = false;
this.initSent = false;
this.ackSent = false;
this.completed = false;
this.handshake = false;
this.pending = [];
this.total = 0;
this.waiting = 4;
this.hasSize = false;
this.timeout = null;
this.job = null;
this.onShake = null;
this.bip150 = null;
} | [
"function",
"BIP151",
"(",
"cipher",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"BIP151",
")",
")",
"return",
"new",
"BIP151",
"(",
"cipher",
")",
";",
"EventEmitter",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"input",
"=",
"new",
"BIP151Stream",
"(",
"cipher",
")",
";",
"this",
".",
"output",
"=",
"new",
"BIP151Stream",
"(",
"cipher",
")",
";",
"this",
".",
"initReceived",
"=",
"false",
";",
"this",
".",
"ackReceived",
"=",
"false",
";",
"this",
".",
"initSent",
"=",
"false",
";",
"this",
".",
"ackSent",
"=",
"false",
";",
"this",
".",
"completed",
"=",
"false",
";",
"this",
".",
"handshake",
"=",
"false",
";",
"this",
".",
"pending",
"=",
"[",
"]",
";",
"this",
".",
"total",
"=",
"0",
";",
"this",
".",
"waiting",
"=",
"4",
";",
"this",
".",
"hasSize",
"=",
"false",
";",
"this",
".",
"timeout",
"=",
"null",
";",
"this",
".",
"job",
"=",
"null",
";",
"this",
".",
"onShake",
"=",
"null",
";",
"this",
".",
"bip150",
"=",
"null",
";",
"}"
] | Represents a BIP151 input and output stream.
Holds state for peer communication.
@alias module:net.BIP151
@constructor
@param {Number} cipher
@property {BIP151Stream} input
@property {BIP151Stream} output
@property {Boolean} initReceived
@property {Boolean} ackReceived
@property {Boolean} initSent
@property {Boolean} ackSent
@property {Object} timeout
@property {Job} job
@property {Boolean} completed
@property {Boolean} handshake | [
"Represents",
"a",
"BIP151",
"input",
"and",
"output",
"stream",
".",
"Holds",
"state",
"for",
"peer",
"communication",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/net/bip151.js#L304-L330 | train |
WorldMobileCoin/wmcc-core | src/net/socks.js | SOCKS | function SOCKS() {
if (!(this instanceof SOCKS))
return new SOCKS();
EventEmitter.call(this);
this.socket = new net.Socket();
this.state = SOCKS.states.INIT;
this.target = SOCKS.states.INIT;
this.destHost = '0.0.0.0';
this.destPort = 0;
this.username = '';
this.password = '';
this.name = 'localhost';
this.destroyed = false;
this.timeout = null;
this.proxied = false;
} | javascript | function SOCKS() {
if (!(this instanceof SOCKS))
return new SOCKS();
EventEmitter.call(this);
this.socket = new net.Socket();
this.state = SOCKS.states.INIT;
this.target = SOCKS.states.INIT;
this.destHost = '0.0.0.0';
this.destPort = 0;
this.username = '';
this.password = '';
this.name = 'localhost';
this.destroyed = false;
this.timeout = null;
this.proxied = false;
} | [
"function",
"SOCKS",
"(",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"SOCKS",
")",
")",
"return",
"new",
"SOCKS",
"(",
")",
";",
"EventEmitter",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"socket",
"=",
"new",
"net",
".",
"Socket",
"(",
")",
";",
"this",
".",
"state",
"=",
"SOCKS",
".",
"states",
".",
"INIT",
";",
"this",
".",
"target",
"=",
"SOCKS",
".",
"states",
".",
"INIT",
";",
"this",
".",
"destHost",
"=",
"'0.0.0.0'",
";",
"this",
".",
"destPort",
"=",
"0",
";",
"this",
".",
"username",
"=",
"''",
";",
"this",
".",
"password",
"=",
"''",
";",
"this",
".",
"name",
"=",
"'localhost'",
";",
"this",
".",
"destroyed",
"=",
"false",
";",
"this",
".",
"timeout",
"=",
"null",
";",
"this",
".",
"proxied",
"=",
"false",
";",
"}"
] | SOCKS state machine
@constructor | [
"SOCKS",
"state",
"machine"
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/net/socks.js#L30-L47 | train |
WorldMobileCoin/wmcc-core | src/mempool/fees.js | ConfirmStats | function ConfirmStats(type, logger) {
if (!(this instanceof ConfirmStats))
return new ConfirmStats(type, logger);
this.logger = Logger.global;
this.type = type;
this.decay = 0;
this.maxConfirms = 0;
this.buckets = new Float64Array(0);
this.bucketMap = new DoubleMap();
this.confAvg = [];
this.curBlockConf = [];
this.unconfTX = [];
this.oldUnconfTX = new Int32Array(0);
this.curBlockTX = new Int32Array(0);
this.txAvg = new Float64Array(0);
this.curBlockVal = new Float64Array(0);
this.avg = new Float64Array(0);
if (logger) {
assert(typeof logger === 'object');
this.logger = logger.context('fees');
}
} | javascript | function ConfirmStats(type, logger) {
if (!(this instanceof ConfirmStats))
return new ConfirmStats(type, logger);
this.logger = Logger.global;
this.type = type;
this.decay = 0;
this.maxConfirms = 0;
this.buckets = new Float64Array(0);
this.bucketMap = new DoubleMap();
this.confAvg = [];
this.curBlockConf = [];
this.unconfTX = [];
this.oldUnconfTX = new Int32Array(0);
this.curBlockTX = new Int32Array(0);
this.txAvg = new Float64Array(0);
this.curBlockVal = new Float64Array(0);
this.avg = new Float64Array(0);
if (logger) {
assert(typeof logger === 'object');
this.logger = logger.context('fees');
}
} | [
"function",
"ConfirmStats",
"(",
"type",
",",
"logger",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"ConfirmStats",
")",
")",
"return",
"new",
"ConfirmStats",
"(",
"type",
",",
"logger",
")",
";",
"this",
".",
"logger",
"=",
"Logger",
".",
"global",
";",
"this",
".",
"type",
"=",
"type",
";",
"this",
".",
"decay",
"=",
"0",
";",
"this",
".",
"maxConfirms",
"=",
"0",
";",
"this",
".",
"buckets",
"=",
"new",
"Float64Array",
"(",
"0",
")",
";",
"this",
".",
"bucketMap",
"=",
"new",
"DoubleMap",
"(",
")",
";",
"this",
".",
"confAvg",
"=",
"[",
"]",
";",
"this",
".",
"curBlockConf",
"=",
"[",
"]",
";",
"this",
".",
"unconfTX",
"=",
"[",
"]",
";",
"this",
".",
"oldUnconfTX",
"=",
"new",
"Int32Array",
"(",
"0",
")",
";",
"this",
".",
"curBlockTX",
"=",
"new",
"Int32Array",
"(",
"0",
")",
";",
"this",
".",
"txAvg",
"=",
"new",
"Float64Array",
"(",
"0",
")",
";",
"this",
".",
"curBlockVal",
"=",
"new",
"Float64Array",
"(",
"0",
")",
";",
"this",
".",
"avg",
"=",
"new",
"Float64Array",
"(",
"0",
")",
";",
"if",
"(",
"logger",
")",
"{",
"assert",
"(",
"typeof",
"logger",
"===",
"'object'",
")",
";",
"this",
".",
"logger",
"=",
"logger",
".",
"context",
"(",
"'fees'",
")",
";",
"}",
"}"
] | Confirmation stats.
@alias module:mempool.ConfirmStats
@constructor
@param {String} type
@param {Logger?} logger | [
"Confirmation",
"stats",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/mempool/fees.js#L52-L79 | train |
WorldMobileCoin/wmcc-core | src/mempool/fees.js | PolicyEstimator | function PolicyEstimator(logger) {
if (!(this instanceof PolicyEstimator))
return new PolicyEstimator(logger);
this.logger = Logger.global;
this.minTrackedFee = MIN_FEERATE;
this.minTrackedPri = MIN_PRIORITY;
this.feeStats = new ConfirmStats('FeeRate');
this.priStats = new ConfirmStats('Priority');
this.feeUnlikely = 0;
this.feeLikely = INF_FEERATE;
this.priUnlikely = 0;
this.priLikely = INF_PRIORITY;
this.map = new Map();
this.bestHeight = 0;
if (policy.MIN_RELAY >= MIN_FEERATE)
this.minTrackedFee = policy.MIN_RELAY;
if (policy.FREE_THRESHOLD >= MIN_PRIORITY)
this.minTrackedPri = policy.FREE_THRESHOLD;
if (logger) {
assert(typeof logger === 'object');
this.logger = logger.context('fees');
this.feeStats.logger = this.logger;
this.priStats.logger = this.logger;
}
} | javascript | function PolicyEstimator(logger) {
if (!(this instanceof PolicyEstimator))
return new PolicyEstimator(logger);
this.logger = Logger.global;
this.minTrackedFee = MIN_FEERATE;
this.minTrackedPri = MIN_PRIORITY;
this.feeStats = new ConfirmStats('FeeRate');
this.priStats = new ConfirmStats('Priority');
this.feeUnlikely = 0;
this.feeLikely = INF_FEERATE;
this.priUnlikely = 0;
this.priLikely = INF_PRIORITY;
this.map = new Map();
this.bestHeight = 0;
if (policy.MIN_RELAY >= MIN_FEERATE)
this.minTrackedFee = policy.MIN_RELAY;
if (policy.FREE_THRESHOLD >= MIN_PRIORITY)
this.minTrackedPri = policy.FREE_THRESHOLD;
if (logger) {
assert(typeof logger === 'object');
this.logger = logger.context('fees');
this.feeStats.logger = this.logger;
this.priStats.logger = this.logger;
}
} | [
"function",
"PolicyEstimator",
"(",
"logger",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"PolicyEstimator",
")",
")",
"return",
"new",
"PolicyEstimator",
"(",
"logger",
")",
";",
"this",
".",
"logger",
"=",
"Logger",
".",
"global",
";",
"this",
".",
"minTrackedFee",
"=",
"MIN_FEERATE",
";",
"this",
".",
"minTrackedPri",
"=",
"MIN_PRIORITY",
";",
"this",
".",
"feeStats",
"=",
"new",
"ConfirmStats",
"(",
"'FeeRate'",
")",
";",
"this",
".",
"priStats",
"=",
"new",
"ConfirmStats",
"(",
"'Priority'",
")",
";",
"this",
".",
"feeUnlikely",
"=",
"0",
";",
"this",
".",
"feeLikely",
"=",
"INF_FEERATE",
";",
"this",
".",
"priUnlikely",
"=",
"0",
";",
"this",
".",
"priLikely",
"=",
"INF_PRIORITY",
";",
"this",
".",
"map",
"=",
"new",
"Map",
"(",
")",
";",
"this",
".",
"bestHeight",
"=",
"0",
";",
"if",
"(",
"policy",
".",
"MIN_RELAY",
">=",
"MIN_FEERATE",
")",
"this",
".",
"minTrackedFee",
"=",
"policy",
".",
"MIN_RELAY",
";",
"if",
"(",
"policy",
".",
"FREE_THRESHOLD",
">=",
"MIN_PRIORITY",
")",
"this",
".",
"minTrackedPri",
"=",
"policy",
".",
"FREE_THRESHOLD",
";",
"if",
"(",
"logger",
")",
"{",
"assert",
"(",
"typeof",
"logger",
"===",
"'object'",
")",
";",
"this",
".",
"logger",
"=",
"logger",
".",
"context",
"(",
"'fees'",
")",
";",
"this",
".",
"feeStats",
".",
"logger",
"=",
"this",
".",
"logger",
";",
"this",
".",
"priStats",
".",
"logger",
"=",
"this",
".",
"logger",
";",
"}",
"}"
] | Estimator for fees and priority.
@alias module:mempool.PolicyEstimator
@constructor
@param {Logger?} logger | [
"Estimator",
"for",
"fees",
"and",
"priority",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/mempool/fees.js#L405-L437 | train |
Spiffyk/twitch-node-sdk | lib/twitch.gui.js | popupNWLogin | function popupNWLogin(params) {
var url = core.REDIRECT_URL + 'oauth2/authorize?' + util.param(params);
var win = nwGUI.Window.open(url, {
title: 'Login with TwitchTV',
width: WIDTH,
height: HEIGHT,
toolbar: false,
show: false,
resizable: true
});
win.on('loaded', function() {
var w = win.window;
if (w.location.hostname == 'api.twitch.tv' && w.location.pathname == '/kraken/') {
core.setSession(util.parseFragment(w.location.hash));
auth.getStatus(function(err, status) {
if (status.authenticated) {
core.events.emit('auth.login', status);
}
});
win.close();
}
else {
win.show();
win.focus();
}
});
} | javascript | function popupNWLogin(params) {
var url = core.REDIRECT_URL + 'oauth2/authorize?' + util.param(params);
var win = nwGUI.Window.open(url, {
title: 'Login with TwitchTV',
width: WIDTH,
height: HEIGHT,
toolbar: false,
show: false,
resizable: true
});
win.on('loaded', function() {
var w = win.window;
if (w.location.hostname == 'api.twitch.tv' && w.location.pathname == '/kraken/') {
core.setSession(util.parseFragment(w.location.hash));
auth.getStatus(function(err, status) {
if (status.authenticated) {
core.events.emit('auth.login', status);
}
});
win.close();
}
else {
win.show();
win.focus();
}
});
} | [
"function",
"popupNWLogin",
"(",
"params",
")",
"{",
"var",
"url",
"=",
"core",
".",
"REDIRECT_URL",
"+",
"'oauth2/authorize?'",
"+",
"util",
".",
"param",
"(",
"params",
")",
";",
"var",
"win",
"=",
"nwGUI",
".",
"Window",
".",
"open",
"(",
"url",
",",
"{",
"title",
":",
"'Login with TwitchTV'",
",",
"width",
":",
"WIDTH",
",",
"height",
":",
"HEIGHT",
",",
"toolbar",
":",
"false",
",",
"show",
":",
"false",
",",
"resizable",
":",
"true",
"}",
")",
";",
"win",
".",
"on",
"(",
"'loaded'",
",",
"function",
"(",
")",
"{",
"var",
"w",
"=",
"win",
".",
"window",
";",
"if",
"(",
"w",
".",
"location",
".",
"hostname",
"==",
"'api.twitch.tv'",
"&&",
"w",
".",
"location",
".",
"pathname",
"==",
"'/kraken/'",
")",
"{",
"core",
".",
"setSession",
"(",
"util",
".",
"parseFragment",
"(",
"w",
".",
"location",
".",
"hash",
")",
")",
";",
"auth",
".",
"getStatus",
"(",
"function",
"(",
"err",
",",
"status",
")",
"{",
"if",
"(",
"status",
".",
"authenticated",
")",
"{",
"core",
".",
"events",
".",
"emit",
"(",
"'auth.login'",
",",
"status",
")",
";",
"}",
"}",
")",
";",
"win",
".",
"close",
"(",
")",
";",
"}",
"else",
"{",
"win",
".",
"show",
"(",
")",
";",
"win",
".",
"focus",
"(",
")",
";",
"}",
"}",
")",
";",
"}"
] | Opens a login popup using NW.js's API version 0.12 or lower
@private
@method popupNWLogin
@param {Array|Object} params | [
"Opens",
"a",
"login",
"popup",
"using",
"NW",
".",
"js",
"s",
"API",
"version",
"0",
".",
"12",
"or",
"lower"
] | e98234ca52b12569298213869439d17169e26f27 | https://github.com/Spiffyk/twitch-node-sdk/blob/e98234ca52b12569298213869439d17169e26f27/lib/twitch.gui.js#L26-L56 | train |
Spiffyk/twitch-node-sdk | lib/twitch.gui.js | popupNW13Login | function popupNW13Login(params) {
var url = core.REDIRECT_URL + 'oauth2/authorize?' + util.param(params);
nw.Window.open(url, {
title: 'Login with TwitchTV',
width: WIDTH,
height: HEIGHT,
id: 'login',
resizable: true
}, function(login) {
login.on('loaded', function() {
var w = this.window;
if (w.location.hostname == 'api.twitch.tv' && w.location.pathname == '/kraken/') {
core.setSession(util.parseFragment(w.location.hash));
auth.getStatus(function(err, status) {
if (status.authenticated) {
core.events.emit('auth.login', status);
}
});
this.close();
}
else {
this.show();
this.focus();
}
});
});
} | javascript | function popupNW13Login(params) {
var url = core.REDIRECT_URL + 'oauth2/authorize?' + util.param(params);
nw.Window.open(url, {
title: 'Login with TwitchTV',
width: WIDTH,
height: HEIGHT,
id: 'login',
resizable: true
}, function(login) {
login.on('loaded', function() {
var w = this.window;
if (w.location.hostname == 'api.twitch.tv' && w.location.pathname == '/kraken/') {
core.setSession(util.parseFragment(w.location.hash));
auth.getStatus(function(err, status) {
if (status.authenticated) {
core.events.emit('auth.login', status);
}
});
this.close();
}
else {
this.show();
this.focus();
}
});
});
} | [
"function",
"popupNW13Login",
"(",
"params",
")",
"{",
"var",
"url",
"=",
"core",
".",
"REDIRECT_URL",
"+",
"'oauth2/authorize?'",
"+",
"util",
".",
"param",
"(",
"params",
")",
";",
"nw",
".",
"Window",
".",
"open",
"(",
"url",
",",
"{",
"title",
":",
"'Login with TwitchTV'",
",",
"width",
":",
"WIDTH",
",",
"height",
":",
"HEIGHT",
",",
"id",
":",
"'login'",
",",
"resizable",
":",
"true",
"}",
",",
"function",
"(",
"login",
")",
"{",
"login",
".",
"on",
"(",
"'loaded'",
",",
"function",
"(",
")",
"{",
"var",
"w",
"=",
"this",
".",
"window",
";",
"if",
"(",
"w",
".",
"location",
".",
"hostname",
"==",
"'api.twitch.tv'",
"&&",
"w",
".",
"location",
".",
"pathname",
"==",
"'/kraken/'",
")",
"{",
"core",
".",
"setSession",
"(",
"util",
".",
"parseFragment",
"(",
"w",
".",
"location",
".",
"hash",
")",
")",
";",
"auth",
".",
"getStatus",
"(",
"function",
"(",
"err",
",",
"status",
")",
"{",
"if",
"(",
"status",
".",
"authenticated",
")",
"{",
"core",
".",
"events",
".",
"emit",
"(",
"'auth.login'",
",",
"status",
")",
";",
"}",
"}",
")",
";",
"this",
".",
"close",
"(",
")",
";",
"}",
"else",
"{",
"this",
".",
"show",
"(",
")",
";",
"this",
".",
"focus",
"(",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}"
] | Opens a login popup using NW.js's API version 0.13 or higher
**THIS IS EXPERIMENTAL AT THE MOMENT!**
@private
@method popupNW13Login
@param {Array|Object} params | [
"Opens",
"a",
"login",
"popup",
"using",
"NW",
".",
"js",
"s",
"API",
"version",
"0",
".",
"13",
"or",
"higher"
] | e98234ca52b12569298213869439d17169e26f27 | https://github.com/Spiffyk/twitch-node-sdk/blob/e98234ca52b12569298213869439d17169e26f27/lib/twitch.gui.js#L67-L96 | train |
Spiffyk/twitch-node-sdk | lib/twitch.gui.js | popupElectronLogin | function popupElectronLogin(params) {
if ( require('electron').remote )
BrowserWindow = require('electron').remote.BrowserWindow;
else
BrowserWindow = require('electron').BrowserWindow;
var url = core.REDIRECT_URL + 'oauth2/authorize?' + util.param(params);
var win = new BrowserWindow({
width: WIDTH,
height: HEIGHT,
resizable: false,
show: false,
webPreferences:{
nodeIntegration: false
}
});
win.loadURL(url);
win.webContents.on('did-finish-load', function() {
var location = URL.parse(win.webContents.getURL());
if (location.hostname == 'api.twitch.tv' && location.pathname == '/kraken/') {
core.setSession(util.parseFragment(location.hash));
auth.getStatus(function(err, status) {
if (status.authenticated) {
core.events.emit('auth.login', status);
}
});
win.close();
}
else {
win.show();
}
});
} | javascript | function popupElectronLogin(params) {
if ( require('electron').remote )
BrowserWindow = require('electron').remote.BrowserWindow;
else
BrowserWindow = require('electron').BrowserWindow;
var url = core.REDIRECT_URL + 'oauth2/authorize?' + util.param(params);
var win = new BrowserWindow({
width: WIDTH,
height: HEIGHT,
resizable: false,
show: false,
webPreferences:{
nodeIntegration: false
}
});
win.loadURL(url);
win.webContents.on('did-finish-load', function() {
var location = URL.parse(win.webContents.getURL());
if (location.hostname == 'api.twitch.tv' && location.pathname == '/kraken/') {
core.setSession(util.parseFragment(location.hash));
auth.getStatus(function(err, status) {
if (status.authenticated) {
core.events.emit('auth.login', status);
}
});
win.close();
}
else {
win.show();
}
});
} | [
"function",
"popupElectronLogin",
"(",
"params",
")",
"{",
"if",
"(",
"require",
"(",
"'electron'",
")",
".",
"remote",
")",
"BrowserWindow",
"=",
"require",
"(",
"'electron'",
")",
".",
"remote",
".",
"BrowserWindow",
";",
"else",
"BrowserWindow",
"=",
"require",
"(",
"'electron'",
")",
".",
"BrowserWindow",
";",
"var",
"url",
"=",
"core",
".",
"REDIRECT_URL",
"+",
"'oauth2/authorize?'",
"+",
"util",
".",
"param",
"(",
"params",
")",
";",
"var",
"win",
"=",
"new",
"BrowserWindow",
"(",
"{",
"width",
":",
"WIDTH",
",",
"height",
":",
"HEIGHT",
",",
"resizable",
":",
"false",
",",
"show",
":",
"false",
",",
"webPreferences",
":",
"{",
"nodeIntegration",
":",
"false",
"}",
"}",
")",
";",
"win",
".",
"loadURL",
"(",
"url",
")",
";",
"win",
".",
"webContents",
".",
"on",
"(",
"'did-finish-load'",
",",
"function",
"(",
")",
"{",
"var",
"location",
"=",
"URL",
".",
"parse",
"(",
"win",
".",
"webContents",
".",
"getURL",
"(",
")",
")",
";",
"if",
"(",
"location",
".",
"hostname",
"==",
"'api.twitch.tv'",
"&&",
"location",
".",
"pathname",
"==",
"'/kraken/'",
")",
"{",
"core",
".",
"setSession",
"(",
"util",
".",
"parseFragment",
"(",
"location",
".",
"hash",
")",
")",
";",
"auth",
".",
"getStatus",
"(",
"function",
"(",
"err",
",",
"status",
")",
"{",
"if",
"(",
"status",
".",
"authenticated",
")",
"{",
"core",
".",
"events",
".",
"emit",
"(",
"'auth.login'",
",",
"status",
")",
";",
"}",
"}",
")",
";",
"win",
".",
"close",
"(",
")",
";",
"}",
"else",
"{",
"win",
".",
"show",
"(",
")",
";",
"}",
"}",
")",
";",
"}"
] | Opens a login popup using Electron's API
@private
@method popupElectronLogin
@param {Array|Object} params | [
"Opens",
"a",
"login",
"popup",
"using",
"Electron",
"s",
"API"
] | e98234ca52b12569298213869439d17169e26f27 | https://github.com/Spiffyk/twitch-node-sdk/blob/e98234ca52b12569298213869439d17169e26f27/lib/twitch.gui.js#L105-L142 | train |
Spiffyk/twitch-node-sdk | lib/twitch.gui.js | setGUIType | function setGUIType(name, nwg) {
gui_type = name;
if ( gui_type == 'nw' ) {
if ( nwg )
nwGUI = nwg;
else
throw new Error('Did not get nw.gui object with GUI type "nw"');
}
} | javascript | function setGUIType(name, nwg) {
gui_type = name;
if ( gui_type == 'nw' ) {
if ( nwg )
nwGUI = nwg;
else
throw new Error('Did not get nw.gui object with GUI type "nw"');
}
} | [
"function",
"setGUIType",
"(",
"name",
",",
"nwg",
")",
"{",
"gui_type",
"=",
"name",
";",
"if",
"(",
"gui_type",
"==",
"'nw'",
")",
"{",
"if",
"(",
"nwg",
")",
"nwGUI",
"=",
"nwg",
";",
"else",
"throw",
"new",
"Error",
"(",
"'Did not get nw.gui object with GUI type \"nw\"'",
")",
";",
"}",
"}"
] | Sets the GUI type
@private
@method setGUIType
@param {String} name The GUI ID (`nw`, `nw13`, `electron`)
@param {Object} [nwg] The NW.js `nw.gui` object for NW.js v0.12 and lower | [
"Sets",
"the",
"GUI",
"type"
] | e98234ca52b12569298213869439d17169e26f27 | https://github.com/Spiffyk/twitch-node-sdk/blob/e98234ca52b12569298213869439d17169e26f27/lib/twitch.gui.js#L152-L161 | train |
Spiffyk/twitch-node-sdk | lib/twitch.gui.js | popupLogin | function popupLogin(params) {
switch(gui_type) {
case 'nw':
popupNWLogin(params);
break;
case 'nw13':
popupNW13Login(params);
break;
case 'electron':
popupElectronLogin(params);
break;
default:
throw new Error('The Twitch SDK was not initialized with any ' +
'compatible GUI API.');
break;
}
} | javascript | function popupLogin(params) {
switch(gui_type) {
case 'nw':
popupNWLogin(params);
break;
case 'nw13':
popupNW13Login(params);
break;
case 'electron':
popupElectronLogin(params);
break;
default:
throw new Error('The Twitch SDK was not initialized with any ' +
'compatible GUI API.');
break;
}
} | [
"function",
"popupLogin",
"(",
"params",
")",
"{",
"switch",
"(",
"gui_type",
")",
"{",
"case",
"'nw'",
":",
"popupNWLogin",
"(",
"params",
")",
";",
"break",
";",
"case",
"'nw13'",
":",
"popupNW13Login",
"(",
"params",
")",
";",
"break",
";",
"case",
"'electron'",
":",
"popupElectronLogin",
"(",
"params",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"Error",
"(",
"'The Twitch SDK was not initialized with any '",
"+",
"'compatible GUI API.'",
")",
";",
"break",
";",
"}",
"}"
] | Opens a login popup
@private
@method popupLogin
@param {Array|Object} params | [
"Opens",
"a",
"login",
"popup"
] | e98234ca52b12569298213869439d17169e26f27 | https://github.com/Spiffyk/twitch-node-sdk/blob/e98234ca52b12569298213869439d17169e26f27/lib/twitch.gui.js#L181-L197 | train |
WorldMobileCoin/wmcc-core | src/utils/co.js | exec | function exec(gen) {
return new Promise((resolve, reject) => {
const step = (value, rejection) => {
let next;
try {
if (rejection)
next = gen.throw(value);
else
next = gen.next(value);
} catch (e) {
reject(e);
return;
}
if (next.done) {
resolve(next.value);
return;
}
if (!isPromise(next.value)) {
step(next.value, false);
return;
}
// eslint-disable-next-line no-use-before-define
next.value.then(succeed, fail);
};
const succeed = (value) => {
step(value, false);
};
const fail = (value) => {
step(value, true);
};
step(undefined, false);
});
} | javascript | function exec(gen) {
return new Promise((resolve, reject) => {
const step = (value, rejection) => {
let next;
try {
if (rejection)
next = gen.throw(value);
else
next = gen.next(value);
} catch (e) {
reject(e);
return;
}
if (next.done) {
resolve(next.value);
return;
}
if (!isPromise(next.value)) {
step(next.value, false);
return;
}
// eslint-disable-next-line no-use-before-define
next.value.then(succeed, fail);
};
const succeed = (value) => {
step(value, false);
};
const fail = (value) => {
step(value, true);
};
step(undefined, false);
});
} | [
"function",
"exec",
"(",
"gen",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"const",
"step",
"=",
"(",
"value",
",",
"rejection",
")",
"=>",
"{",
"let",
"next",
";",
"try",
"{",
"if",
"(",
"rejection",
")",
"next",
"=",
"gen",
".",
"throw",
"(",
"value",
")",
";",
"else",
"next",
"=",
"gen",
".",
"next",
"(",
"value",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"reject",
"(",
"e",
")",
";",
"return",
";",
"}",
"if",
"(",
"next",
".",
"done",
")",
"{",
"resolve",
"(",
"next",
".",
"value",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"isPromise",
"(",
"next",
".",
"value",
")",
")",
"{",
"step",
"(",
"next",
".",
"value",
",",
"false",
")",
";",
"return",
";",
"}",
"next",
".",
"value",
".",
"then",
"(",
"succeed",
",",
"fail",
")",
";",
"}",
";",
"const",
"succeed",
"=",
"(",
"value",
")",
"=>",
"{",
"step",
"(",
"value",
",",
"false",
")",
";",
"}",
";",
"const",
"fail",
"=",
"(",
"value",
")",
"=>",
"{",
"step",
"(",
"value",
",",
"true",
")",
";",
"}",
";",
"step",
"(",
"undefined",
",",
"false",
")",
";",
"}",
")",
";",
"}"
] | Execute an instantiated generator.
@param {Generator} gen
@returns {Promise} | [
"Execute",
"an",
"instantiated",
"generator",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/utils/co.js#L26-L65 | train |
WorldMobileCoin/wmcc-core | src/utils/co.js | promisify | function promisify(func) {
return function(...args) {
return new Promise((resolve, reject) => {
args.push(wrap(resolve, reject));
func.call(this, ...args);
});
};
} | javascript | function promisify(func) {
return function(...args) {
return new Promise((resolve, reject) => {
args.push(wrap(resolve, reject));
func.call(this, ...args);
});
};
} | [
"function",
"promisify",
"(",
"func",
")",
"{",
"return",
"function",
"(",
"...",
"args",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"args",
".",
"push",
"(",
"wrap",
"(",
"resolve",
",",
"reject",
")",
")",
";",
"func",
".",
"call",
"(",
"this",
",",
"...",
"args",
")",
";",
"}",
")",
";",
"}",
";",
"}"
] | Wrap a function that accepts node.js
style callbacks into a function that
returns a promise.
@param {Function} func
@returns {AsyncFunction} | [
"Wrap",
"a",
"function",
"that",
"accepts",
"node",
".",
"js",
"style",
"callbacks",
"into",
"a",
"function",
"that",
"returns",
"a",
"promise",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/utils/co.js#L150-L157 | train |
WorldMobileCoin/wmcc-core | src/utils/co.js | callbackify | function callbackify(func) {
return function(...args) {
if (args.length === 0
|| typeof args[args.length - 1] !== 'function') {
throw new Error(`${func.name || 'Function'} requires a callback.`);
}
const callback = args.pop();
func.call(this, ...args).then((value) => {
setImmediate(() => callback(null, value));
}, (err) => {
setImmediate(() => callback(err));
});
};
} | javascript | function callbackify(func) {
return function(...args) {
if (args.length === 0
|| typeof args[args.length - 1] !== 'function') {
throw new Error(`${func.name || 'Function'} requires a callback.`);
}
const callback = args.pop();
func.call(this, ...args).then((value) => {
setImmediate(() => callback(null, value));
}, (err) => {
setImmediate(() => callback(err));
});
};
} | [
"function",
"callbackify",
"(",
"func",
")",
"{",
"return",
"function",
"(",
"...",
"args",
")",
"{",
"if",
"(",
"args",
".",
"length",
"===",
"0",
"||",
"typeof",
"args",
"[",
"args",
".",
"length",
"-",
"1",
"]",
"!==",
"'function'",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"func",
".",
"name",
"||",
"'Function'",
"}",
"`",
")",
";",
"}",
"const",
"callback",
"=",
"args",
".",
"pop",
"(",
")",
";",
"func",
".",
"call",
"(",
"this",
",",
"...",
"args",
")",
".",
"then",
"(",
"(",
"value",
")",
"=>",
"{",
"setImmediate",
"(",
"(",
")",
"=>",
"callback",
"(",
"null",
",",
"value",
")",
")",
";",
"}",
",",
"(",
"err",
")",
"=>",
"{",
"setImmediate",
"(",
"(",
")",
"=>",
"callback",
"(",
"err",
")",
")",
";",
"}",
")",
";",
"}",
";",
"}"
] | Wrap a promise-returning function
into a function that accepts a
node.js style callback.
@param {AsyncFunction} func
@returns {Function} | [
"Wrap",
"a",
"promise",
"-",
"returning",
"function",
"into",
"a",
"function",
"that",
"accepts",
"a",
"node",
".",
"js",
"style",
"callback",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/utils/co.js#L167-L182 | train |
WorldMobileCoin/wmcc-core | src/utils/co.js | every | async function every(jobs) {
const result = await Promise.all(jobs);
for (const item of result) {
if (!item)
return false;
}
return true;
} | javascript | async function every(jobs) {
const result = await Promise.all(jobs);
for (const item of result) {
if (!item)
return false;
}
return true;
} | [
"async",
"function",
"every",
"(",
"jobs",
")",
"{",
"const",
"result",
"=",
"await",
"Promise",
".",
"all",
"(",
"jobs",
")",
";",
"for",
"(",
"const",
"item",
"of",
"result",
")",
"{",
"if",
"(",
"!",
"item",
")",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Execute each promise and
have them pass a truth test.
@method
@param {Promise[]} jobs
@returns {Promise} | [
"Execute",
"each",
"promise",
"and",
"have",
"them",
"pass",
"a",
"truth",
"test",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/utils/co.js#L192-L201 | train |
WorldMobileCoin/wmcc-core | src/utils/co.js | startInterval | function startInterval(func, time, self) {
const ctx = {
timer: null,
stopped: false
};
const cb = async () => {
assert(ctx.timer != null);
ctx.timer = null;
try {
await func.call(self);
} finally {
if (!ctx.stopped)
ctx.timer = setTimeout(cb, time);
}
};
ctx.timer = setTimeout(cb, time);
return ctx;
} | javascript | function startInterval(func, time, self) {
const ctx = {
timer: null,
stopped: false
};
const cb = async () => {
assert(ctx.timer != null);
ctx.timer = null;
try {
await func.call(self);
} finally {
if (!ctx.stopped)
ctx.timer = setTimeout(cb, time);
}
};
ctx.timer = setTimeout(cb, time);
return ctx;
} | [
"function",
"startInterval",
"(",
"func",
",",
"time",
",",
"self",
")",
"{",
"const",
"ctx",
"=",
"{",
"timer",
":",
"null",
",",
"stopped",
":",
"false",
"}",
";",
"const",
"cb",
"=",
"async",
"(",
")",
"=>",
"{",
"assert",
"(",
"ctx",
".",
"timer",
"!=",
"null",
")",
";",
"ctx",
".",
"timer",
"=",
"null",
";",
"try",
"{",
"await",
"func",
".",
"call",
"(",
"self",
")",
";",
"}",
"finally",
"{",
"if",
"(",
"!",
"ctx",
".",
"stopped",
")",
"ctx",
".",
"timer",
"=",
"setTimeout",
"(",
"cb",
",",
"time",
")",
";",
"}",
"}",
";",
"ctx",
".",
"timer",
"=",
"setTimeout",
"(",
"cb",
",",
"time",
")",
";",
"return",
"ctx",
";",
"}"
] | Start an interval. Wait for promise
to resolve on each iteration.
@param {Function} func
@param {Number?} time
@param {Object?} self
@returns {Object} | [
"Start",
"an",
"interval",
".",
"Wait",
"for",
"promise",
"to",
"resolve",
"on",
"each",
"iteration",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/utils/co.js#L212-L233 | train |
WorldMobileCoin/wmcc-core | src/utils/co.js | stopInterval | function stopInterval(ctx) {
assert(ctx);
if (ctx.timer != null) {
clearTimeout(ctx.timer);
ctx.timer = null;
}
ctx.stopped = true;
} | javascript | function stopInterval(ctx) {
assert(ctx);
if (ctx.timer != null) {
clearTimeout(ctx.timer);
ctx.timer = null;
}
ctx.stopped = true;
} | [
"function",
"stopInterval",
"(",
"ctx",
")",
"{",
"assert",
"(",
"ctx",
")",
";",
"if",
"(",
"ctx",
".",
"timer",
"!=",
"null",
")",
"{",
"clearTimeout",
"(",
"ctx",
".",
"timer",
")",
";",
"ctx",
".",
"timer",
"=",
"null",
";",
"}",
"ctx",
".",
"stopped",
"=",
"true",
";",
"}"
] | Clear an interval.
@param {Object} ctx | [
"Clear",
"an",
"interval",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/utils/co.js#L240-L247 | train |
WorldMobileCoin/wmcc-core | src/utils/co.js | startTimeout | function startTimeout(func, time, self) {
return {
timer: setTimeout(func.bind(self), time),
stopped: false
};
} | javascript | function startTimeout(func, time, self) {
return {
timer: setTimeout(func.bind(self), time),
stopped: false
};
} | [
"function",
"startTimeout",
"(",
"func",
",",
"time",
",",
"self",
")",
"{",
"return",
"{",
"timer",
":",
"setTimeout",
"(",
"func",
".",
"bind",
"(",
"self",
")",
",",
"time",
")",
",",
"stopped",
":",
"false",
"}",
";",
"}"
] | Start a timeout.
@param {Function} func
@param {Number?} time
@param {Object?} self
@returns {Object} | [
"Start",
"a",
"timeout",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/utils/co.js#L257-L262 | train |
WorldMobileCoin/wmcc-core | src/utils/co.js | stopTimeout | function stopTimeout(ctx) {
assert(ctx);
if (ctx.timer != null) {
clearTimeout(ctx.timer);
ctx.timer = null;
}
ctx.stopped = true;
} | javascript | function stopTimeout(ctx) {
assert(ctx);
if (ctx.timer != null) {
clearTimeout(ctx.timer);
ctx.timer = null;
}
ctx.stopped = true;
} | [
"function",
"stopTimeout",
"(",
"ctx",
")",
"{",
"assert",
"(",
"ctx",
")",
";",
"if",
"(",
"ctx",
".",
"timer",
"!=",
"null",
")",
"{",
"clearTimeout",
"(",
"ctx",
".",
"timer",
")",
";",
"ctx",
".",
"timer",
"=",
"null",
";",
"}",
"ctx",
".",
"stopped",
"=",
"true",
";",
"}"
] | Clear a timeout.
@param {Object} ctx | [
"Clear",
"a",
"timeout",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/utils/co.js#L269-L276 | train |
bigpipe/bigpipe.js | bigpipe.js | BigPipe | function BigPipe(options) {
if (!(this instanceof BigPipe)) return new BigPipe(options);
options = options || {};
this.expected = +options.pagelets || 0; // Pagelets that this page requires.
this.allowed = +options.pagelets || 0; // Pagelets that are allowed for this page.
this.maximum = options.limit || 20; // Max Pagelet instances we can reuse.
this.readyState = BigPipe.LOADING; // Current readyState.
this.options = options; // Reference to the used options.
this.templates = {}; // Collection of templates.
this.pagelets = []; // Collection of different pagelets.
this.freelist = []; // Collection of unused Pagelet instances.
this.rendered = []; // List of already rendered pagelets.
this.progress = 0; // Percentage loaded.
this.assets = {}; // Asset cache.
this.root = document.documentElement; // The <html> element.
EventEmitter.call(this);
this.configure(options);
} | javascript | function BigPipe(options) {
if (!(this instanceof BigPipe)) return new BigPipe(options);
options = options || {};
this.expected = +options.pagelets || 0; // Pagelets that this page requires.
this.allowed = +options.pagelets || 0; // Pagelets that are allowed for this page.
this.maximum = options.limit || 20; // Max Pagelet instances we can reuse.
this.readyState = BigPipe.LOADING; // Current readyState.
this.options = options; // Reference to the used options.
this.templates = {}; // Collection of templates.
this.pagelets = []; // Collection of different pagelets.
this.freelist = []; // Collection of unused Pagelet instances.
this.rendered = []; // List of already rendered pagelets.
this.progress = 0; // Percentage loaded.
this.assets = {}; // Asset cache.
this.root = document.documentElement; // The <html> element.
EventEmitter.call(this);
this.configure(options);
} | [
"function",
"BigPipe",
"(",
"options",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"BigPipe",
")",
")",
"return",
"new",
"BigPipe",
"(",
"options",
")",
";",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"this",
".",
"expected",
"=",
"+",
"options",
".",
"pagelets",
"||",
"0",
";",
"this",
".",
"allowed",
"=",
"+",
"options",
".",
"pagelets",
"||",
"0",
";",
"this",
".",
"maximum",
"=",
"options",
".",
"limit",
"||",
"20",
";",
"this",
".",
"readyState",
"=",
"BigPipe",
".",
"LOADING",
";",
"this",
".",
"options",
"=",
"options",
";",
"this",
".",
"templates",
"=",
"{",
"}",
";",
"this",
".",
"pagelets",
"=",
"[",
"]",
";",
"this",
".",
"freelist",
"=",
"[",
"]",
";",
"this",
".",
"rendered",
"=",
"[",
"]",
";",
"this",
".",
"progress",
"=",
"0",
";",
"this",
".",
"assets",
"=",
"{",
"}",
";",
"this",
".",
"root",
"=",
"document",
".",
"documentElement",
";",
"EventEmitter",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"configure",
"(",
"options",
")",
";",
"}"
] | BigPipe is the client-side library which is automatically added to pages which
uses the BigPipe framework.
Options:
- limit: The amount pagelet instances we can reuse.
- pagelets: The amount of pagelets we're expecting to load.
- id: The id of the page that we're loading.
@constructor
@param {Object} options BigPipe configuration.
@api public | [
"BigPipe",
"is",
"the",
"client",
"-",
"side",
"library",
"which",
"is",
"automatically",
"added",
"to",
"pages",
"which",
"uses",
"the",
"BigPipe",
"framework",
"."
] | 80fe2630d363ed2b69f85d28792a9095a4167e3b | https://github.com/bigpipe/bigpipe.js/blob/80fe2630d363ed2b69f85d28792a9095a4167e3b/bigpipe.js#L22-L43 | train |
Autarc/react-htmltree | lib/utilities.js | setDeep | function setDeep(map, listKey, keyPath, value) {
if (!Array.isArray(listKey)) {
listKey = [listKey];
}
var change = typeof value === 'function' ? 'updateIn' : 'setIn';
var subPaths = getPaths(map, listKey, keyPath);
return map.withMutations(function (map) {
subPaths.forEach(function (keyPath) {
return map[change](keyPath, value);
});
});
function getPaths(map, listKeys, keyPath) {
var overview = arguments.length <= 3 || arguments[3] === undefined ? [keyPath] : arguments[3];
var list = map.getIn(listKeys);
if (list) {
var size = list.size;
for (var i = 0; i < size; i++) {
overview.push([].concat(_toConsumableArray(listKeys), [i], _toConsumableArray(keyPath)));
getPaths(map, [].concat(_toConsumableArray(listKeys), [i, listKeys[0]]), keyPath, overview);
}
}
return overview;
}
} | javascript | function setDeep(map, listKey, keyPath, value) {
if (!Array.isArray(listKey)) {
listKey = [listKey];
}
var change = typeof value === 'function' ? 'updateIn' : 'setIn';
var subPaths = getPaths(map, listKey, keyPath);
return map.withMutations(function (map) {
subPaths.forEach(function (keyPath) {
return map[change](keyPath, value);
});
});
function getPaths(map, listKeys, keyPath) {
var overview = arguments.length <= 3 || arguments[3] === undefined ? [keyPath] : arguments[3];
var list = map.getIn(listKeys);
if (list) {
var size = list.size;
for (var i = 0; i < size; i++) {
overview.push([].concat(_toConsumableArray(listKeys), [i], _toConsumableArray(keyPath)));
getPaths(map, [].concat(_toConsumableArray(listKeys), [i, listKeys[0]]), keyPath, overview);
}
}
return overview;
}
} | [
"function",
"setDeep",
"(",
"map",
",",
"listKey",
",",
"keyPath",
",",
"value",
")",
"{",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"listKey",
")",
")",
"{",
"listKey",
"=",
"[",
"listKey",
"]",
";",
"}",
"var",
"change",
"=",
"typeof",
"value",
"===",
"'function'",
"?",
"'updateIn'",
":",
"'setIn'",
";",
"var",
"subPaths",
"=",
"getPaths",
"(",
"map",
",",
"listKey",
",",
"keyPath",
")",
";",
"return",
"map",
".",
"withMutations",
"(",
"function",
"(",
"map",
")",
"{",
"subPaths",
".",
"forEach",
"(",
"function",
"(",
"keyPath",
")",
"{",
"return",
"map",
"[",
"change",
"]",
"(",
"keyPath",
",",
"value",
")",
";",
"}",
")",
";",
"}",
")",
";",
"function",
"getPaths",
"(",
"map",
",",
"listKeys",
",",
"keyPath",
")",
"{",
"var",
"overview",
"=",
"arguments",
".",
"length",
"<=",
"3",
"||",
"arguments",
"[",
"3",
"]",
"===",
"undefined",
"?",
"[",
"keyPath",
"]",
":",
"arguments",
"[",
"3",
"]",
";",
"var",
"list",
"=",
"map",
".",
"getIn",
"(",
"listKeys",
")",
";",
"if",
"(",
"list",
")",
"{",
"var",
"size",
"=",
"list",
".",
"size",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"size",
";",
"i",
"++",
")",
"{",
"overview",
".",
"push",
"(",
"[",
"]",
".",
"concat",
"(",
"_toConsumableArray",
"(",
"listKeys",
")",
",",
"[",
"i",
"]",
",",
"_toConsumableArray",
"(",
"keyPath",
")",
")",
")",
";",
"getPaths",
"(",
"map",
",",
"[",
"]",
".",
"concat",
"(",
"_toConsumableArray",
"(",
"listKeys",
")",
",",
"[",
"i",
",",
"listKeys",
"[",
"0",
"]",
"]",
")",
",",
"keyPath",
",",
"overview",
")",
";",
"}",
"}",
"return",
"overview",
";",
"}",
"}"
] | Changes the the values in the nested collection
@param {Immutable.Map} map - [description]
@param {Array} listKey - [description]
@param {Array} keyPath - [description]
@param {*|Function} value - [description] | [
"Changes",
"the",
"the",
"values",
"in",
"the",
"nested",
"collection"
] | 90af47a18d77bf3a33c2ae7b7ac0d387435923d9 | https://github.com/Autarc/react-htmltree/blob/90af47a18d77bf3a33c2ae7b7ac0d387435923d9/lib/utilities.js#L67-L92 | train |
WorldMobileCoin/wmcc-core | src/node/node.js | Node | function Node(options) {
if (!(this instanceof Node))
return new Node(options);
AsyncObject.call(this);
this.config = new Config('wmcc');
this.config.inject(options);
this.config.load(options);
if (options.config)
this.config.open('wmcc.conf');
this.network = Network.get(this.config.network);
this.startTime = -1;
this.bound = [];
this.plugins = Object.create(null);
this.stack = [];
this.logger = null;
this.workers = null;
this.spv = false;
this.chain = null;
this.fees = null;
this.mempool = null;
this.pool = null;
this.miner = null;
this.http = null;
this.init();
} | javascript | function Node(options) {
if (!(this instanceof Node))
return new Node(options);
AsyncObject.call(this);
this.config = new Config('wmcc');
this.config.inject(options);
this.config.load(options);
if (options.config)
this.config.open('wmcc.conf');
this.network = Network.get(this.config.network);
this.startTime = -1;
this.bound = [];
this.plugins = Object.create(null);
this.stack = [];
this.logger = null;
this.workers = null;
this.spv = false;
this.chain = null;
this.fees = null;
this.mempool = null;
this.pool = null;
this.miner = null;
this.http = null;
this.init();
} | [
"function",
"Node",
"(",
"options",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Node",
")",
")",
"return",
"new",
"Node",
"(",
"options",
")",
";",
"AsyncObject",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"config",
"=",
"new",
"Config",
"(",
"'wmcc'",
")",
";",
"this",
".",
"config",
".",
"inject",
"(",
"options",
")",
";",
"this",
".",
"config",
".",
"load",
"(",
"options",
")",
";",
"if",
"(",
"options",
".",
"config",
")",
"this",
".",
"config",
".",
"open",
"(",
"'wmcc.conf'",
")",
";",
"this",
".",
"network",
"=",
"Network",
".",
"get",
"(",
"this",
".",
"config",
".",
"network",
")",
";",
"this",
".",
"startTime",
"=",
"-",
"1",
";",
"this",
".",
"bound",
"=",
"[",
"]",
";",
"this",
".",
"plugins",
"=",
"Object",
".",
"create",
"(",
"null",
")",
";",
"this",
".",
"stack",
"=",
"[",
"]",
";",
"this",
".",
"logger",
"=",
"null",
";",
"this",
".",
"workers",
"=",
"null",
";",
"this",
".",
"spv",
"=",
"false",
";",
"this",
".",
"chain",
"=",
"null",
";",
"this",
".",
"fees",
"=",
"null",
";",
"this",
".",
"mempool",
"=",
"null",
";",
"this",
".",
"pool",
"=",
"null",
";",
"this",
".",
"miner",
"=",
"null",
";",
"this",
".",
"http",
"=",
"null",
";",
"this",
".",
"init",
"(",
")",
";",
"}"
] | Base class from which every other
Node-like object inherits.
@alias module:node.Node
@constructor
@abstract
@param {Object} options | [
"Base",
"class",
"from",
"which",
"every",
"other",
"Node",
"-",
"like",
"object",
"inherits",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/node/node.js#L33-L64 | train |
decs/texas | texas.js | function (format) {
return function (card) {
card = getCode(card);
if (!card)
return undefined;
card--;
return format({rank: card >> 2, suit: card & 3});
};
} | javascript | function (format) {
return function (card) {
card = getCode(card);
if (!card)
return undefined;
card--;
return format({rank: card >> 2, suit: card & 3});
};
} | [
"function",
"(",
"format",
")",
"{",
"return",
"function",
"(",
"card",
")",
"{",
"card",
"=",
"getCode",
"(",
"card",
")",
";",
"if",
"(",
"!",
"card",
")",
"return",
"undefined",
";",
"card",
"--",
";",
"return",
"format",
"(",
"{",
"rank",
":",
"card",
">>",
"2",
",",
"suit",
":",
"card",
"&",
"3",
"}",
")",
";",
"}",
";",
"}"
] | Helper function to create card formatters. | [
"Helper",
"function",
"to",
"create",
"card",
"formatters",
"."
] | b3fc63ea2a6e3efc2da45add6052629bdd02dff6 | https://github.com/decs/texas/blob/b3fc63ea2a6e3efc2da45add6052629bdd02dff6/texas.js#L55-L63 | train |
|
decs/texas | texas.js | function (format) {
var res = _.range(1, deckSize + 1);
var buffer = crypto.randomBytes(deckSize << 2);
for (var pos = res.length - 1; pos > 0; pos--) {
var rand = buffer.readUInt32LE(pos << 2) % (pos + 1);
var temp = res[pos];
res[pos] = res[rand];
res[rand] = temp;
};
return format ? _.map(res, format) : res;
} | javascript | function (format) {
var res = _.range(1, deckSize + 1);
var buffer = crypto.randomBytes(deckSize << 2);
for (var pos = res.length - 1; pos > 0; pos--) {
var rand = buffer.readUInt32LE(pos << 2) % (pos + 1);
var temp = res[pos];
res[pos] = res[rand];
res[rand] = temp;
};
return format ? _.map(res, format) : res;
} | [
"function",
"(",
"format",
")",
"{",
"var",
"res",
"=",
"_",
".",
"range",
"(",
"1",
",",
"deckSize",
"+",
"1",
")",
";",
"var",
"buffer",
"=",
"crypto",
".",
"randomBytes",
"(",
"deckSize",
"<<",
"2",
")",
";",
"for",
"(",
"var",
"pos",
"=",
"res",
".",
"length",
"-",
"1",
";",
"pos",
">",
"0",
";",
"pos",
"--",
")",
"{",
"var",
"rand",
"=",
"buffer",
".",
"readUInt32LE",
"(",
"pos",
"<<",
"2",
")",
"%",
"(",
"pos",
"+",
"1",
")",
";",
"var",
"temp",
"=",
"res",
"[",
"pos",
"]",
";",
"res",
"[",
"pos",
"]",
"=",
"res",
"[",
"rand",
"]",
";",
"res",
"[",
"rand",
"]",
"=",
"temp",
";",
"}",
";",
"return",
"format",
"?",
"_",
".",
"map",
"(",
"res",
",",
"format",
")",
":",
"res",
";",
"}"
] | Creates a new shuffled deck. | [
"Creates",
"a",
"new",
"shuffled",
"deck",
"."
] | b3fc63ea2a6e3efc2da45add6052629bdd02dff6 | https://github.com/decs/texas/blob/b3fc63ea2a6e3efc2da45add6052629bdd02dff6/texas.js#L68-L78 | train |
|
decs/texas | texas.js | function (cards) {
var res = deckSize + 1;
for (var c = 0; c < cards.length; c++)
res = evaluator[res + getCode(cards[c])];
if (cards.length < 7)
res = evaluator[res];
return {name: hands[res >> 12], value: res};
} | javascript | function (cards) {
var res = deckSize + 1;
for (var c = 0; c < cards.length; c++)
res = evaluator[res + getCode(cards[c])];
if (cards.length < 7)
res = evaluator[res];
return {name: hands[res >> 12], value: res};
} | [
"function",
"(",
"cards",
")",
"{",
"var",
"res",
"=",
"deckSize",
"+",
"1",
";",
"for",
"(",
"var",
"c",
"=",
"0",
";",
"c",
"<",
"cards",
".",
"length",
";",
"c",
"++",
")",
"res",
"=",
"evaluator",
"[",
"res",
"+",
"getCode",
"(",
"cards",
"[",
"c",
"]",
")",
"]",
";",
"if",
"(",
"cards",
".",
"length",
"<",
"7",
")",
"res",
"=",
"evaluator",
"[",
"res",
"]",
";",
"return",
"{",
"name",
":",
"hands",
"[",
"res",
">>",
"12",
"]",
",",
"value",
":",
"res",
"}",
";",
"}"
] | Evaluates the 5 to 7 card hands. | [
"Evaluates",
"the",
"5",
"to",
"7",
"card",
"hands",
"."
] | b3fc63ea2a6e3efc2da45add6052629bdd02dff6 | https://github.com/decs/texas/blob/b3fc63ea2a6e3efc2da45add6052629bdd02dff6/texas.js#L81-L88 | train |
|
decs/texas | texas.js | function () {
var freq = new Int32Array(hands.length);
var start = Date.now();
for (var c1 = 1; c1 <= deckSize; c1++) {
var r1 = evaluator[deckSize + c1 + 1];
for (var c2 = c1 + 1; c2 <= deckSize; c2++) {
var r2 = evaluator[r1 + c2];
for (var c3 = c2 + 1; c3 <= deckSize; c3++) {
var r3 = evaluator[r2 + c3];
for (var c4 = c3 + 1; c4 <= deckSize; c4++) {
var r4 = evaluator[r3 + c4];
for (var c5 = c4 + 1; c5 <= deckSize; c5++) {
var r5 = evaluator[r4 + c5];
for (var c6 = c5 + 1; c6 <= deckSize; c6++) {
var r6 = evaluator[r5 + c6];
for (var c7 = c6 + 1; c7 <= deckSize; c7++) {
var r7 = evaluator[r6 + c7];
freq[r7 >> 12]++;
} } } } } } }
var finish = Date.now();
var total = 0;
for (var key = 0; key < hands.length; key++) {
total += freq[key];
console.log(hands[key] + ': ' + freq[key]);
}
console.log('Total: ' + total);
console.log((finish - start) + 'ms');
} | javascript | function () {
var freq = new Int32Array(hands.length);
var start = Date.now();
for (var c1 = 1; c1 <= deckSize; c1++) {
var r1 = evaluator[deckSize + c1 + 1];
for (var c2 = c1 + 1; c2 <= deckSize; c2++) {
var r2 = evaluator[r1 + c2];
for (var c3 = c2 + 1; c3 <= deckSize; c3++) {
var r3 = evaluator[r2 + c3];
for (var c4 = c3 + 1; c4 <= deckSize; c4++) {
var r4 = evaluator[r3 + c4];
for (var c5 = c4 + 1; c5 <= deckSize; c5++) {
var r5 = evaluator[r4 + c5];
for (var c6 = c5 + 1; c6 <= deckSize; c6++) {
var r6 = evaluator[r5 + c6];
for (var c7 = c6 + 1; c7 <= deckSize; c7++) {
var r7 = evaluator[r6 + c7];
freq[r7 >> 12]++;
} } } } } } }
var finish = Date.now();
var total = 0;
for (var key = 0; key < hands.length; key++) {
total += freq[key];
console.log(hands[key] + ': ' + freq[key]);
}
console.log('Total: ' + total);
console.log((finish - start) + 'ms');
} | [
"function",
"(",
")",
"{",
"var",
"freq",
"=",
"new",
"Int32Array",
"(",
"hands",
".",
"length",
")",
";",
"var",
"start",
"=",
"Date",
".",
"now",
"(",
")",
";",
"for",
"(",
"var",
"c1",
"=",
"1",
";",
"c1",
"<=",
"deckSize",
";",
"c1",
"++",
")",
"{",
"var",
"r1",
"=",
"evaluator",
"[",
"deckSize",
"+",
"c1",
"+",
"1",
"]",
";",
"for",
"(",
"var",
"c2",
"=",
"c1",
"+",
"1",
";",
"c2",
"<=",
"deckSize",
";",
"c2",
"++",
")",
"{",
"var",
"r2",
"=",
"evaluator",
"[",
"r1",
"+",
"c2",
"]",
";",
"for",
"(",
"var",
"c3",
"=",
"c2",
"+",
"1",
";",
"c3",
"<=",
"deckSize",
";",
"c3",
"++",
")",
"{",
"var",
"r3",
"=",
"evaluator",
"[",
"r2",
"+",
"c3",
"]",
";",
"for",
"(",
"var",
"c4",
"=",
"c3",
"+",
"1",
";",
"c4",
"<=",
"deckSize",
";",
"c4",
"++",
")",
"{",
"var",
"r4",
"=",
"evaluator",
"[",
"r3",
"+",
"c4",
"]",
";",
"for",
"(",
"var",
"c5",
"=",
"c4",
"+",
"1",
";",
"c5",
"<=",
"deckSize",
";",
"c5",
"++",
")",
"{",
"var",
"r5",
"=",
"evaluator",
"[",
"r4",
"+",
"c5",
"]",
";",
"for",
"(",
"var",
"c6",
"=",
"c5",
"+",
"1",
";",
"c6",
"<=",
"deckSize",
";",
"c6",
"++",
")",
"{",
"var",
"r6",
"=",
"evaluator",
"[",
"r5",
"+",
"c6",
"]",
";",
"for",
"(",
"var",
"c7",
"=",
"c6",
"+",
"1",
";",
"c7",
"<=",
"deckSize",
";",
"c7",
"++",
")",
"{",
"var",
"r7",
"=",
"evaluator",
"[",
"r6",
"+",
"c7",
"]",
";",
"freq",
"[",
"r7",
">>",
"12",
"]",
"++",
";",
"}",
"}",
"}",
"}",
"}",
"}",
"}",
"var",
"finish",
"=",
"Date",
".",
"now",
"(",
")",
";",
"var",
"total",
"=",
"0",
";",
"for",
"(",
"var",
"key",
"=",
"0",
";",
"key",
"<",
"hands",
".",
"length",
";",
"key",
"++",
")",
"{",
"total",
"+=",
"freq",
"[",
"key",
"]",
";",
"console",
".",
"log",
"(",
"hands",
"[",
"key",
"]",
"+",
"': '",
"+",
"freq",
"[",
"key",
"]",
")",
";",
"}",
"console",
".",
"log",
"(",
"'Total: '",
"+",
"total",
")",
";",
"console",
".",
"log",
"(",
"(",
"finish",
"-",
"start",
")",
"+",
"'ms'",
")",
";",
"}"
] | Benchmarks the evaluator within all possible 7 card hands. | [
"Benchmarks",
"the",
"evaluator",
"within",
"all",
"possible",
"7",
"card",
"hands",
"."
] | b3fc63ea2a6e3efc2da45add6052629bdd02dff6 | https://github.com/decs/texas/blob/b3fc63ea2a6e3efc2da45add6052629bdd02dff6/texas.js#L181-L208 | train |
|
gw2efficiency/recipe-calculation | src/treeAdjustQuantity.js | treeAdjustQuantity | function treeAdjustQuantity (amount, tree, availableItems, ignoreAvailable = false, nesting = 0) {
tree = {...tree}
tree.output = tree.output || 1
// Calculate the total quantity needed
let treeQuantity = amount * tree.quantity
// Round amount to nearest multiple of the tree output
treeQuantity = Math.ceil(treeQuantity / tree.output) * tree.output
tree.totalQuantity = Math.round(treeQuantity)
// If the item is available and the higher tree is not
// bought or already available get as many items of it as possible
// (This ignores the root node, because we *always* want to craft all of these)
let availableQuantity = 0
if (nesting > 0 && !ignoreAvailable && availableItems[tree.id]) {
availableQuantity = Math.min(availableItems[tree.id], tree.totalQuantity)
availableItems[tree.id] -= availableQuantity
}
tree.usedQuantity = tree.totalQuantity - availableQuantity
if (!tree.components) {
return tree
}
// Get the amount of components that need to be crafted
// e.g. a recipe outputs 10 and we need 20 -> 2x components
let componentAmount = Math.ceil(tree.usedQuantity / tree.output)
// Ignore available items in components if the tree
// doesn't get crafted or is completely available anyway
ignoreAvailable = tree.craft === false || tree.usedQuantity === 0 || ignoreAvailable
// Adjust the quantity for all tree's subcomponents
tree.components = tree.components.map(component => {
return treeAdjustQuantity(componentAmount, component, availableItems, ignoreAvailable, ++nesting)
})
return tree
} | javascript | function treeAdjustQuantity (amount, tree, availableItems, ignoreAvailable = false, nesting = 0) {
tree = {...tree}
tree.output = tree.output || 1
// Calculate the total quantity needed
let treeQuantity = amount * tree.quantity
// Round amount to nearest multiple of the tree output
treeQuantity = Math.ceil(treeQuantity / tree.output) * tree.output
tree.totalQuantity = Math.round(treeQuantity)
// If the item is available and the higher tree is not
// bought or already available get as many items of it as possible
// (This ignores the root node, because we *always* want to craft all of these)
let availableQuantity = 0
if (nesting > 0 && !ignoreAvailable && availableItems[tree.id]) {
availableQuantity = Math.min(availableItems[tree.id], tree.totalQuantity)
availableItems[tree.id] -= availableQuantity
}
tree.usedQuantity = tree.totalQuantity - availableQuantity
if (!tree.components) {
return tree
}
// Get the amount of components that need to be crafted
// e.g. a recipe outputs 10 and we need 20 -> 2x components
let componentAmount = Math.ceil(tree.usedQuantity / tree.output)
// Ignore available items in components if the tree
// doesn't get crafted or is completely available anyway
ignoreAvailable = tree.craft === false || tree.usedQuantity === 0 || ignoreAvailable
// Adjust the quantity for all tree's subcomponents
tree.components = tree.components.map(component => {
return treeAdjustQuantity(componentAmount, component, availableItems, ignoreAvailable, ++nesting)
})
return tree
} | [
"function",
"treeAdjustQuantity",
"(",
"amount",
",",
"tree",
",",
"availableItems",
",",
"ignoreAvailable",
"=",
"false",
",",
"nesting",
"=",
"0",
")",
"{",
"tree",
"=",
"{",
"...",
"tree",
"}",
"tree",
".",
"output",
"=",
"tree",
".",
"output",
"||",
"1",
"let",
"treeQuantity",
"=",
"amount",
"*",
"tree",
".",
"quantity",
"treeQuantity",
"=",
"Math",
".",
"ceil",
"(",
"treeQuantity",
"/",
"tree",
".",
"output",
")",
"*",
"tree",
".",
"output",
"tree",
".",
"totalQuantity",
"=",
"Math",
".",
"round",
"(",
"treeQuantity",
")",
"let",
"availableQuantity",
"=",
"0",
"if",
"(",
"nesting",
">",
"0",
"&&",
"!",
"ignoreAvailable",
"&&",
"availableItems",
"[",
"tree",
".",
"id",
"]",
")",
"{",
"availableQuantity",
"=",
"Math",
".",
"min",
"(",
"availableItems",
"[",
"tree",
".",
"id",
"]",
",",
"tree",
".",
"totalQuantity",
")",
"availableItems",
"[",
"tree",
".",
"id",
"]",
"-=",
"availableQuantity",
"}",
"tree",
".",
"usedQuantity",
"=",
"tree",
".",
"totalQuantity",
"-",
"availableQuantity",
"if",
"(",
"!",
"tree",
".",
"components",
")",
"{",
"return",
"tree",
"}",
"let",
"componentAmount",
"=",
"Math",
".",
"ceil",
"(",
"tree",
".",
"usedQuantity",
"/",
"tree",
".",
"output",
")",
"ignoreAvailable",
"=",
"tree",
".",
"craft",
"===",
"false",
"||",
"tree",
".",
"usedQuantity",
"===",
"0",
"||",
"ignoreAvailable",
"tree",
".",
"components",
"=",
"tree",
".",
"components",
".",
"map",
"(",
"component",
"=>",
"{",
"return",
"treeAdjustQuantity",
"(",
"componentAmount",
",",
"component",
",",
"availableItems",
",",
"ignoreAvailable",
",",
"++",
"nesting",
")",
"}",
")",
"return",
"tree",
"}"
] | Go through a recipe tree and set 'totalQuantity' based on the wanted amount and the output of recipes and sub-recipes | [
"Go",
"through",
"a",
"recipe",
"tree",
"and",
"set",
"totalQuantity",
"based",
"on",
"the",
"wanted",
"amount",
"and",
"the",
"output",
"of",
"recipes",
"and",
"sub",
"-",
"recipes"
] | 841d16750cb23c61850f8452492bfbf90db6db7c | https://github.com/gw2efficiency/recipe-calculation/blob/841d16750cb23c61850f8452492bfbf90db6db7c/src/treeAdjustQuantity.js#L11-L50 | train |
WorldMobileCoin/wmcc-core | src/http/request.js | request | function request(options) {
if (typeof options === 'string')
options = { uri: options };
options.buffer = true;
return new Promise((resolve, reject) => {
const req = new Request(options);
req.on('error', err => reject(err));
req.on('end', () => resolve(req));
req.start();
req.end();
});
} | javascript | function request(options) {
if (typeof options === 'string')
options = { uri: options };
options.buffer = true;
return new Promise((resolve, reject) => {
const req = new Request(options);
req.on('error', err => reject(err));
req.on('end', () => resolve(req));
req.start();
req.end();
});
} | [
"function",
"request",
"(",
"options",
")",
"{",
"if",
"(",
"typeof",
"options",
"===",
"'string'",
")",
"options",
"=",
"{",
"uri",
":",
"options",
"}",
";",
"options",
".",
"buffer",
"=",
"true",
";",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"const",
"req",
"=",
"new",
"Request",
"(",
"options",
")",
";",
"req",
".",
"on",
"(",
"'error'",
",",
"err",
"=>",
"reject",
"(",
"err",
")",
")",
";",
"req",
".",
"on",
"(",
"'end'",
",",
"(",
")",
"=>",
"resolve",
"(",
"req",
")",
")",
";",
"req",
".",
"start",
"(",
")",
";",
"req",
".",
"end",
"(",
")",
";",
"}",
")",
";",
"}"
] | Make an HTTP request.
@alias module:http.request
@param {Object} options
@param {String} options.uri
@param {Object?} options.query
@param {Object?} options.body
@param {Object?} options.json
@param {Object?} options.form
@param {String?} options.type - One of `"json"`,
`"form"`, `"text"`, or `"bin"`.
@param {String?} options.agent - User agent string.
@param {Object?} [options.strictSSL=true] - Whether to accept bad certs.
@param {Object?} options.method - HTTP method.
@param {Object?} options.auth
@param {String?} options.auth.username
@param {String?} options.auth.password
@param {String?} options.expect - Type to expect (see options.type).
Error will be returned if the response is not of this type.
@param {Number?} options.limit - Byte limit on response.
@returns {Promise} | [
"Make",
"an",
"HTTP",
"request",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/http/request.js#L564-L579 | train |
ucd-cws/calvin-network-tools | nodejs/lib/utils.js | fileExistsSync | function fileExistsSync(path) {
try {
fs.accessSync(path, fs.F_OK);
} catch (e) {
return false;
}
return true;
} | javascript | function fileExistsSync(path) {
try {
fs.accessSync(path, fs.F_OK);
} catch (e) {
return false;
}
return true;
} | [
"function",
"fileExistsSync",
"(",
"path",
")",
"{",
"try",
"{",
"fs",
".",
"accessSync",
"(",
"path",
",",
"fs",
".",
"F_OK",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | stupid node. | [
"stupid",
"node",
"."
] | 9c276972394878dfb6927b56303fca4c4a2bf8f5 | https://github.com/ucd-cws/calvin-network-tools/blob/9c276972394878dfb6927b56303fca4c4a2bf8f5/nodejs/lib/utils.js#L38-L45 | train |
solderjs/node-pakman | lib/get-module-tree.js | traverseLeaf | function traverseLeaf(next, requireString, requireIndex) {
var reqPath
, reqDeps
;
if ('.' === requireString[0]) {
reqPath = url.resolve('/' + leaf.modulepath, requireString).substr(1); // strip leading '/'
} else {
// TODO handle absolute paths
reqPath = requireString;
}
// check that we haven't visited this dependency tree already
reqDeps = allDepsList[reqPath];
if (reqDeps) {
reqDeps.requiredAs[requireString] = true;
leaf.dependencyList[requireIndex] = reqDeps;
next();
return;
}
getModuleTreeHelper(null, allDepsList, pkg, leaf, requireString, function (err, deps) {
if (err) {
callback(err);
return;
}
leaf.dependencyList[requireIndex] = deps;
next();
});
} | javascript | function traverseLeaf(next, requireString, requireIndex) {
var reqPath
, reqDeps
;
if ('.' === requireString[0]) {
reqPath = url.resolve('/' + leaf.modulepath, requireString).substr(1); // strip leading '/'
} else {
// TODO handle absolute paths
reqPath = requireString;
}
// check that we haven't visited this dependency tree already
reqDeps = allDepsList[reqPath];
if (reqDeps) {
reqDeps.requiredAs[requireString] = true;
leaf.dependencyList[requireIndex] = reqDeps;
next();
return;
}
getModuleTreeHelper(null, allDepsList, pkg, leaf, requireString, function (err, deps) {
if (err) {
callback(err);
return;
}
leaf.dependencyList[requireIndex] = deps;
next();
});
} | [
"function",
"traverseLeaf",
"(",
"next",
",",
"requireString",
",",
"requireIndex",
")",
"{",
"var",
"reqPath",
",",
"reqDeps",
";",
"if",
"(",
"'.'",
"===",
"requireString",
"[",
"0",
"]",
")",
"{",
"reqPath",
"=",
"url",
".",
"resolve",
"(",
"'/'",
"+",
"leaf",
".",
"modulepath",
",",
"requireString",
")",
".",
"substr",
"(",
"1",
")",
";",
"}",
"else",
"{",
"reqPath",
"=",
"requireString",
";",
"}",
"reqDeps",
"=",
"allDepsList",
"[",
"reqPath",
"]",
";",
"if",
"(",
"reqDeps",
")",
"{",
"reqDeps",
".",
"requiredAs",
"[",
"requireString",
"]",
"=",
"true",
";",
"leaf",
".",
"dependencyList",
"[",
"requireIndex",
"]",
"=",
"reqDeps",
";",
"next",
"(",
")",
";",
"return",
";",
"}",
"getModuleTreeHelper",
"(",
"null",
",",
"allDepsList",
",",
"pkg",
",",
"leaf",
",",
"requireString",
",",
"function",
"(",
"err",
",",
"deps",
")",
"{",
"if",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
")",
";",
"return",
";",
"}",
"leaf",
".",
"dependencyList",
"[",
"requireIndex",
"]",
"=",
"deps",
";",
"next",
"(",
")",
";",
"}",
")",
";",
"}"
] | turns require strings into dependency objects | [
"turns",
"require",
"strings",
"into",
"dependency",
"objects"
] | 2f2bef996bedc9d69e8320c943a188d665859e20 | https://github.com/solderjs/node-pakman/blob/2f2bef996bedc9d69e8320c943a188d665859e20/lib/get-module-tree.js#L22-L52 | train |
WorldMobileCoin/wmcc-core | src/mempool/mempoolentry.js | MempoolEntry | function MempoolEntry(options) {
if (!(this instanceof MempoolEntry))
return new MempoolEntry(options);
this.tx = null;
this.height = -1;
this.size = 0;
this.sigops = 0;
this.priority = 0;
this.fee = 0;
this.deltaFee = 0;
this.time = 0;
this.value = 0;
this.coinbase = false;
this.dependencies = false;
this.descFee = 0;
this.descSize = 0;
if (options)
this.fromOptions(options);
} | javascript | function MempoolEntry(options) {
if (!(this instanceof MempoolEntry))
return new MempoolEntry(options);
this.tx = null;
this.height = -1;
this.size = 0;
this.sigops = 0;
this.priority = 0;
this.fee = 0;
this.deltaFee = 0;
this.time = 0;
this.value = 0;
this.coinbase = false;
this.dependencies = false;
this.descFee = 0;
this.descSize = 0;
if (options)
this.fromOptions(options);
} | [
"function",
"MempoolEntry",
"(",
"options",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"MempoolEntry",
")",
")",
"return",
"new",
"MempoolEntry",
"(",
"options",
")",
";",
"this",
".",
"tx",
"=",
"null",
";",
"this",
".",
"height",
"=",
"-",
"1",
";",
"this",
".",
"size",
"=",
"0",
";",
"this",
".",
"sigops",
"=",
"0",
";",
"this",
".",
"priority",
"=",
"0",
";",
"this",
".",
"fee",
"=",
"0",
";",
"this",
".",
"deltaFee",
"=",
"0",
";",
"this",
".",
"time",
"=",
"0",
";",
"this",
".",
"value",
"=",
"0",
";",
"this",
".",
"coinbase",
"=",
"false",
";",
"this",
".",
"dependencies",
"=",
"false",
";",
"this",
".",
"descFee",
"=",
"0",
";",
"this",
".",
"descSize",
"=",
"0",
";",
"if",
"(",
"options",
")",
"this",
".",
"fromOptions",
"(",
"options",
")",
";",
"}"
] | Represents a mempool entry.
@alias module:mempool.MempoolEntry
@constructor
@param {Object} options
@param {TX} options.tx - Transaction in mempool.
@param {Number} options.height - Entry height.
@param {Number} options.priority - Entry priority.
@param {Number} options.time - Entry time.
@param {Amount} options.value - Value of on-chain coins.
@property {TX} tx
@property {Number} height
@property {Number} priority
@property {Number} time
@property {Amount} value | [
"Represents",
"a",
"mempool",
"entry",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/mempool/mempoolentry.js#L37-L57 | train |
solderjs/node-pakman | lib/reduce-tree.js | mapByDepth | function mapByDepth(rootPackage) {
var depth = 0
, allDeps = {}
, superDepsList = {}
;
function traverseDeps(childPackage) {
depth += 1;
childPackage.dependencyTree = childPackage.dependencyTree || {};
Object.keys(childPackage.dependencyTree).forEach(function (depName) {
var childDeps = (childPackage.dependencyTree[depName] || {}) || {}
;
if (superDepsList[depName]) {
// a dependency can't (meaning shouldn't) have a path in which it depends on itself
// this kind of resolution isn't as important as it once was
// since the modules can be loaded out-of-order
return;
}
superDepsList[depName] = true;
allDeps[depth] = allDeps[depth] || [];
allDeps[depth].push(depName);
if (childDeps) {
traverseDeps(childDeps);
}
superDepsList[depName] = false;
});
depth -= 1;
}
traverseDeps(rootPackage);
return allDeps;
} | javascript | function mapByDepth(rootPackage) {
var depth = 0
, allDeps = {}
, superDepsList = {}
;
function traverseDeps(childPackage) {
depth += 1;
childPackage.dependencyTree = childPackage.dependencyTree || {};
Object.keys(childPackage.dependencyTree).forEach(function (depName) {
var childDeps = (childPackage.dependencyTree[depName] || {}) || {}
;
if (superDepsList[depName]) {
// a dependency can't (meaning shouldn't) have a path in which it depends on itself
// this kind of resolution isn't as important as it once was
// since the modules can be loaded out-of-order
return;
}
superDepsList[depName] = true;
allDeps[depth] = allDeps[depth] || [];
allDeps[depth].push(depName);
if (childDeps) {
traverseDeps(childDeps);
}
superDepsList[depName] = false;
});
depth -= 1;
}
traverseDeps(rootPackage);
return allDeps;
} | [
"function",
"mapByDepth",
"(",
"rootPackage",
")",
"{",
"var",
"depth",
"=",
"0",
",",
"allDeps",
"=",
"{",
"}",
",",
"superDepsList",
"=",
"{",
"}",
";",
"function",
"traverseDeps",
"(",
"childPackage",
")",
"{",
"depth",
"+=",
"1",
";",
"childPackage",
".",
"dependencyTree",
"=",
"childPackage",
".",
"dependencyTree",
"||",
"{",
"}",
";",
"Object",
".",
"keys",
"(",
"childPackage",
".",
"dependencyTree",
")",
".",
"forEach",
"(",
"function",
"(",
"depName",
")",
"{",
"var",
"childDeps",
"=",
"(",
"childPackage",
".",
"dependencyTree",
"[",
"depName",
"]",
"||",
"{",
"}",
")",
"||",
"{",
"}",
";",
"if",
"(",
"superDepsList",
"[",
"depName",
"]",
")",
"{",
"return",
";",
"}",
"superDepsList",
"[",
"depName",
"]",
"=",
"true",
";",
"allDeps",
"[",
"depth",
"]",
"=",
"allDeps",
"[",
"depth",
"]",
"||",
"[",
"]",
";",
"allDeps",
"[",
"depth",
"]",
".",
"push",
"(",
"depName",
")",
";",
"if",
"(",
"childDeps",
")",
"{",
"traverseDeps",
"(",
"childDeps",
")",
";",
"}",
"superDepsList",
"[",
"depName",
"]",
"=",
"false",
";",
"}",
")",
";",
"depth",
"-=",
"1",
";",
"}",
"traverseDeps",
"(",
"rootPackage",
")",
";",
"return",
"allDeps",
";",
"}"
] | You could traverse it like this | [
"You",
"could",
"traverse",
"it",
"like",
"this"
] | 2f2bef996bedc9d69e8320c943a188d665859e20 | https://github.com/solderjs/node-pakman/blob/2f2bef996bedc9d69e8320c943a188d665859e20/lib/reduce-tree.js#L6-L45 | train |
justsocialapps/just-sdk | examples/browser/browser-app.js | init | function init() {
// initialize the SDK with the domain where Just is running and the
// OAuth 2.0 implicit flow parameters
sdk = new window.JustSDK({
domain: 'JUSTDOMAIN',
oauth2: {
// adapt this to point to the correct domain and path
redirect_uri: 'https://YOURDOMAIN/browser-app-authorized.html',
// the client ID of this app. Must have been registered at the
// Just installation configured under 'domain' above.
client_id: 'YOUR_CLIENT_ID',
flow: 'implicit'
}
});
var loginBtn = document.querySelector('#login');
var logoutBtn = document.querySelector('#logout');
loginBtn.addEventListener('click', function() {
printInfo();
});
logoutBtn.addEventListener('click', function() {
window.localStorage.removeItem('just:accessToken:' + sdk.config.domain);
window.location.reload();
});
getToken(false).then(function() {
logoutBtn.style.display = '';
loginBtn.style.display = 'none';
printInfo();
}, function() {
loginBtn.style.display = '';
logoutBtn.style.display = 'none';
});
} | javascript | function init() {
// initialize the SDK with the domain where Just is running and the
// OAuth 2.0 implicit flow parameters
sdk = new window.JustSDK({
domain: 'JUSTDOMAIN',
oauth2: {
// adapt this to point to the correct domain and path
redirect_uri: 'https://YOURDOMAIN/browser-app-authorized.html',
// the client ID of this app. Must have been registered at the
// Just installation configured under 'domain' above.
client_id: 'YOUR_CLIENT_ID',
flow: 'implicit'
}
});
var loginBtn = document.querySelector('#login');
var logoutBtn = document.querySelector('#logout');
loginBtn.addEventListener('click', function() {
printInfo();
});
logoutBtn.addEventListener('click', function() {
window.localStorage.removeItem('just:accessToken:' + sdk.config.domain);
window.location.reload();
});
getToken(false).then(function() {
logoutBtn.style.display = '';
loginBtn.style.display = 'none';
printInfo();
}, function() {
loginBtn.style.display = '';
logoutBtn.style.display = 'none';
});
} | [
"function",
"init",
"(",
")",
"{",
"sdk",
"=",
"new",
"window",
".",
"JustSDK",
"(",
"{",
"domain",
":",
"'JUSTDOMAIN'",
",",
"oauth2",
":",
"{",
"redirect_uri",
":",
"'https://YOURDOMAIN/browser-app-authorized.html'",
",",
"client_id",
":",
"'YOUR_CLIENT_ID'",
",",
"flow",
":",
"'implicit'",
"}",
"}",
")",
";",
"var",
"loginBtn",
"=",
"document",
".",
"querySelector",
"(",
"'#login'",
")",
";",
"var",
"logoutBtn",
"=",
"document",
".",
"querySelector",
"(",
"'#logout'",
")",
";",
"loginBtn",
".",
"addEventListener",
"(",
"'click'",
",",
"function",
"(",
")",
"{",
"printInfo",
"(",
")",
";",
"}",
")",
";",
"logoutBtn",
".",
"addEventListener",
"(",
"'click'",
",",
"function",
"(",
")",
"{",
"window",
".",
"localStorage",
".",
"removeItem",
"(",
"'just:accessToken:'",
"+",
"sdk",
".",
"config",
".",
"domain",
")",
";",
"window",
".",
"location",
".",
"reload",
"(",
")",
";",
"}",
")",
";",
"getToken",
"(",
"false",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"logoutBtn",
".",
"style",
".",
"display",
"=",
"''",
";",
"loginBtn",
".",
"style",
".",
"display",
"=",
"'none'",
";",
"printInfo",
"(",
")",
";",
"}",
",",
"function",
"(",
")",
"{",
"loginBtn",
".",
"style",
".",
"display",
"=",
"''",
";",
"logoutBtn",
".",
"style",
".",
"display",
"=",
"'none'",
";",
"}",
")",
";",
"}"
] | this function is called right after the DOM has loaded | [
"this",
"function",
"is",
"called",
"right",
"after",
"the",
"DOM",
"has",
"loaded"
] | af547343b06624e157ee16fca0a546bb1a3b7a7d | https://github.com/justsocialapps/just-sdk/blob/af547343b06624e157ee16fca0a546bb1a3b7a7d/examples/browser/browser-app.js#L31-L64 | train |
WorldMobileCoin/wmcc-core | src/db/memdb.js | MemDB | function MemDB(location) {
if (!(this instanceof MemDB))
return new MemDB(location);
this.location = location || 'memory';
this.options = {};
this.tree = new RBT(cmp, true);
} | javascript | function MemDB(location) {
if (!(this instanceof MemDB))
return new MemDB(location);
this.location = location || 'memory';
this.options = {};
this.tree = new RBT(cmp, true);
} | [
"function",
"MemDB",
"(",
"location",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"MemDB",
")",
")",
"return",
"new",
"MemDB",
"(",
"location",
")",
";",
"this",
".",
"location",
"=",
"location",
"||",
"'memory'",
";",
"this",
".",
"options",
"=",
"{",
"}",
";",
"this",
".",
"tree",
"=",
"new",
"RBT",
"(",
"cmp",
",",
"true",
")",
";",
"}"
] | In memory database for wmcc_core
using a red-black tree backend.
@alias module:db.MemDB
@constructor
@param {String?} location - Phony location.
@param {Object?} options
@param {Function} options.compare - Comparator. | [
"In",
"memory",
"database",
"for",
"wmcc_core",
"using",
"a",
"red",
"-",
"black",
"tree",
"backend",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/db/memdb.js#L27-L34 | train |
WorldMobileCoin/wmcc-core | src/primitives/input.js | Input | function Input(options) {
if (!(this instanceof Input))
return new Input(options);
this.prevout = new Outpoint();
this.script = new Script();
this.sequence = 0xffffffff;
this.witness = new Witness();
if (options)
this.fromOptions(options);
} | javascript | function Input(options) {
if (!(this instanceof Input))
return new Input(options);
this.prevout = new Outpoint();
this.script = new Script();
this.sequence = 0xffffffff;
this.witness = new Witness();
if (options)
this.fromOptions(options);
} | [
"function",
"Input",
"(",
"options",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Input",
")",
")",
"return",
"new",
"Input",
"(",
"options",
")",
";",
"this",
".",
"prevout",
"=",
"new",
"Outpoint",
"(",
")",
";",
"this",
".",
"script",
"=",
"new",
"Script",
"(",
")",
";",
"this",
".",
"sequence",
"=",
"0xffffffff",
";",
"this",
".",
"witness",
"=",
"new",
"Witness",
"(",
")",
";",
"if",
"(",
"options",
")",
"this",
".",
"fromOptions",
"(",
"options",
")",
";",
"}"
] | Represents a transaction input.
@alias module:primitives.Input
@constructor
@param {NakedInput} options
@property {Outpoint} prevout - Outpoint.
@property {Script} script - Input script / scriptSig.
@property {Number} sequence - nSequence.
@property {Witness} witness - Witness (empty if not present). | [
"Represents",
"a",
"transaction",
"input",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/primitives/input.js#L34-L45 | train |
WorldMobileCoin/wmcc-core | src/protocol/timedata.js | TimeData | function TimeData(limit) {
if (!(this instanceof TimeData))
return new TimeData(limit);
EventEmitter.call(this);
if (limit == null)
limit = 200;
this.samples = [];
this.known = new Map();
this.limit = limit;
this.offset = 0;
this.checked = false;
this.ntp = new NTP();
} | javascript | function TimeData(limit) {
if (!(this instanceof TimeData))
return new TimeData(limit);
EventEmitter.call(this);
if (limit == null)
limit = 200;
this.samples = [];
this.known = new Map();
this.limit = limit;
this.offset = 0;
this.checked = false;
this.ntp = new NTP();
} | [
"function",
"TimeData",
"(",
"limit",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"TimeData",
")",
")",
"return",
"new",
"TimeData",
"(",
"limit",
")",
";",
"EventEmitter",
".",
"call",
"(",
"this",
")",
";",
"if",
"(",
"limit",
"==",
"null",
")",
"limit",
"=",
"200",
";",
"this",
".",
"samples",
"=",
"[",
"]",
";",
"this",
".",
"known",
"=",
"new",
"Map",
"(",
")",
";",
"this",
".",
"limit",
"=",
"limit",
";",
"this",
".",
"offset",
"=",
"0",
";",
"this",
".",
"checked",
"=",
"false",
";",
"this",
".",
"ntp",
"=",
"new",
"NTP",
"(",
")",
";",
"}"
] | An object which handles "adjusted time". This may not
look it, but this is actually a semi-consensus-critical
piece of code. It handles version packets from peers
and calculates what to offset our system clock's time by.
@alias module:protocol.TimeData
@constructor
@param {Number} [limit=200]
@property {Array} samples
@property {Object} known
@property {Number} limit
@property {Number} offset | [
"An",
"object",
"which",
"handles",
"adjusted",
"time",
".",
"This",
"may",
"not",
"look",
"it",
"but",
"this",
"is",
"actually",
"a",
"semi",
"-",
"consensus",
"-",
"critical",
"piece",
"of",
"code",
".",
"It",
"handles",
"version",
"packets",
"from",
"peers",
"and",
"calculates",
"what",
"to",
"offset",
"our",
"system",
"clock",
"s",
"time",
"by",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/protocol/timedata.js#L31-L46 | train |
WorldMobileCoin/wmcc-core | src/primitives/headers.js | Headers | function Headers(options) {
if (!(this instanceof Headers))
return new Headers(options);
AbstractBlock.call(this);
if (options)
this.parseOptions(options);
} | javascript | function Headers(options) {
if (!(this instanceof Headers))
return new Headers(options);
AbstractBlock.call(this);
if (options)
this.parseOptions(options);
} | [
"function",
"Headers",
"(",
"options",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Headers",
")",
")",
"return",
"new",
"Headers",
"(",
"options",
")",
";",
"AbstractBlock",
".",
"call",
"(",
"this",
")",
";",
"if",
"(",
"options",
")",
"this",
".",
"parseOptions",
"(",
"options",
")",
";",
"}"
] | Represents block headers obtained from the network via `headers`.
@alias module:primitives.Headers
@constructor
@extends AbstractBlock
@param {NakedBlock} options | [
"Represents",
"block",
"headers",
"obtained",
"from",
"the",
"network",
"via",
"headers",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/primitives/headers.js#L27-L35 | train |
WorldMobileCoin/wmcc-core | src/wallet/nodeclient.js | NodeClient | function NodeClient(node) {
if (!(this instanceof NodeClient))
return new NodeClient(node);
AsyncObject.call(this);
this.node = node;
this.network = node.network;
this.filter = null;
this.listen = false;
this._init();
} | javascript | function NodeClient(node) {
if (!(this instanceof NodeClient))
return new NodeClient(node);
AsyncObject.call(this);
this.node = node;
this.network = node.network;
this.filter = null;
this.listen = false;
this._init();
} | [
"function",
"NodeClient",
"(",
"node",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"NodeClient",
")",
")",
"return",
"new",
"NodeClient",
"(",
"node",
")",
";",
"AsyncObject",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"node",
"=",
"node",
";",
"this",
".",
"network",
"=",
"node",
".",
"network",
";",
"this",
".",
"filter",
"=",
"null",
";",
"this",
".",
"listen",
"=",
"false",
";",
"this",
".",
"_init",
"(",
")",
";",
"}"
] | NodeClient
Sort of a fake local client for separation of concerns.
@alias module:node.NodeClient
@constructor | [
"NodeClient",
"Sort",
"of",
"a",
"fake",
"local",
"client",
"for",
"separation",
"of",
"concerns",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/wallet/nodeclient.js#L22-L34 | train |
WorldMobileCoin/wmcc-core | src/bip70/paymentdetails.js | PaymentDetails | function PaymentDetails(options) {
if (!(this instanceof PaymentDetails))
return new PaymentDetails(options);
this.network = null;
this.outputs = [];
this.time = util.now();
this.expires = -1;
this.memo = null;
this.paymentUrl = null;
this.merchantData = null;
if (options)
this.fromOptions(options);
} | javascript | function PaymentDetails(options) {
if (!(this instanceof PaymentDetails))
return new PaymentDetails(options);
this.network = null;
this.outputs = [];
this.time = util.now();
this.expires = -1;
this.memo = null;
this.paymentUrl = null;
this.merchantData = null;
if (options)
this.fromOptions(options);
} | [
"function",
"PaymentDetails",
"(",
"options",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"PaymentDetails",
")",
")",
"return",
"new",
"PaymentDetails",
"(",
"options",
")",
";",
"this",
".",
"network",
"=",
"null",
";",
"this",
".",
"outputs",
"=",
"[",
"]",
";",
"this",
".",
"time",
"=",
"util",
".",
"now",
"(",
")",
";",
"this",
".",
"expires",
"=",
"-",
"1",
";",
"this",
".",
"memo",
"=",
"null",
";",
"this",
".",
"paymentUrl",
"=",
"null",
";",
"this",
".",
"merchantData",
"=",
"null",
";",
"if",
"(",
"options",
")",
"this",
".",
"fromOptions",
"(",
"options",
")",
";",
"}"
] | Represents BIP70 payment details.
@alias module:bip70.PaymentDetails
@constructor
@param {Object?} options
@property {String|null} network
@property {Output[]} outputs
@property {Number} time
@property {Number} expires
@property {String|null} memo
@property {String|null} paymentUrl
@property {Buffer|null} merchantData | [
"Represents",
"BIP70",
"payment",
"details",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/bip70/paymentdetails.js#L33-L47 | train |
WorldMobileCoin/wmcc-core | src/coins/compress.js | compressScript | function compressScript(script, bw) {
// Attempt to compress the output scripts.
// We can _only_ ever compress them if
// they are serialized as minimaldata, as
// we need to recreate them when we read
// them.
// P2PKH -> 0 | key-hash
// Saves 5 bytes.
const pkh = script.getPubkeyhash(true);
if (pkh) {
bw.writeU8(0);
bw.writeBytes(pkh);
return bw;
}
// P2SH -> 1 | script-hash
// Saves 3 bytes.
const sh = script.getScripthash();
if (sh) {
bw.writeU8(1);
bw.writeBytes(sh);
return bw;
}
// P2PK -> 2-5 | compressed-key
// Only works if the key is valid.
// Saves up to 35 bytes.
const pk = script.getPubkey(true);
if (pk) {
if (publicKeyVerify(pk)) {
const key = compressKey(pk);
bw.writeBytes(key);
return bw;
}
}
// Raw -> varlen + 10 | script
bw.writeVarint(script.raw.length + COMPRESS_TYPES);
bw.writeBytes(script.raw);
return bw;
} | javascript | function compressScript(script, bw) {
// Attempt to compress the output scripts.
// We can _only_ ever compress them if
// they are serialized as minimaldata, as
// we need to recreate them when we read
// them.
// P2PKH -> 0 | key-hash
// Saves 5 bytes.
const pkh = script.getPubkeyhash(true);
if (pkh) {
bw.writeU8(0);
bw.writeBytes(pkh);
return bw;
}
// P2SH -> 1 | script-hash
// Saves 3 bytes.
const sh = script.getScripthash();
if (sh) {
bw.writeU8(1);
bw.writeBytes(sh);
return bw;
}
// P2PK -> 2-5 | compressed-key
// Only works if the key is valid.
// Saves up to 35 bytes.
const pk = script.getPubkey(true);
if (pk) {
if (publicKeyVerify(pk)) {
const key = compressKey(pk);
bw.writeBytes(key);
return bw;
}
}
// Raw -> varlen + 10 | script
bw.writeVarint(script.raw.length + COMPRESS_TYPES);
bw.writeBytes(script.raw);
return bw;
} | [
"function",
"compressScript",
"(",
"script",
",",
"bw",
")",
"{",
"const",
"pkh",
"=",
"script",
".",
"getPubkeyhash",
"(",
"true",
")",
";",
"if",
"(",
"pkh",
")",
"{",
"bw",
".",
"writeU8",
"(",
"0",
")",
";",
"bw",
".",
"writeBytes",
"(",
"pkh",
")",
";",
"return",
"bw",
";",
"}",
"const",
"sh",
"=",
"script",
".",
"getScripthash",
"(",
")",
";",
"if",
"(",
"sh",
")",
"{",
"bw",
".",
"writeU8",
"(",
"1",
")",
";",
"bw",
".",
"writeBytes",
"(",
"sh",
")",
";",
"return",
"bw",
";",
"}",
"const",
"pk",
"=",
"script",
".",
"getPubkey",
"(",
"true",
")",
";",
"if",
"(",
"pk",
")",
"{",
"if",
"(",
"publicKeyVerify",
"(",
"pk",
")",
")",
"{",
"const",
"key",
"=",
"compressKey",
"(",
"pk",
")",
";",
"bw",
".",
"writeBytes",
"(",
"key",
")",
";",
"return",
"bw",
";",
"}",
"}",
"bw",
".",
"writeVarint",
"(",
"script",
".",
"raw",
".",
"length",
"+",
"COMPRESS_TYPES",
")",
";",
"bw",
".",
"writeBytes",
"(",
"script",
".",
"raw",
")",
";",
"return",
"bw",
";",
"}"
] | Compress a script, write directly to the buffer.
@param {Script} script
@param {BufferWriter} bw | [
"Compress",
"a",
"script",
"write",
"directly",
"to",
"the",
"buffer",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/coins/compress.js#L36-L78 | train |
WorldMobileCoin/wmcc-core | src/coins/compress.js | sizeScript | function sizeScript(script) {
if (script.isPubkeyhash(true))
return 21;
if (script.isScripthash())
return 21;
const pk = script.getPubkey(true);
if (pk) {
if (publicKeyVerify(pk))
return 33;
}
let size = 0;
size += encoding.sizeVarint(script.raw.length + COMPRESS_TYPES);
size += script.raw.length;
return size;
} | javascript | function sizeScript(script) {
if (script.isPubkeyhash(true))
return 21;
if (script.isScripthash())
return 21;
const pk = script.getPubkey(true);
if (pk) {
if (publicKeyVerify(pk))
return 33;
}
let size = 0;
size += encoding.sizeVarint(script.raw.length + COMPRESS_TYPES);
size += script.raw.length;
return size;
} | [
"function",
"sizeScript",
"(",
"script",
")",
"{",
"if",
"(",
"script",
".",
"isPubkeyhash",
"(",
"true",
")",
")",
"return",
"21",
";",
"if",
"(",
"script",
".",
"isScripthash",
"(",
")",
")",
"return",
"21",
";",
"const",
"pk",
"=",
"script",
".",
"getPubkey",
"(",
"true",
")",
";",
"if",
"(",
"pk",
")",
"{",
"if",
"(",
"publicKeyVerify",
"(",
"pk",
")",
")",
"return",
"33",
";",
"}",
"let",
"size",
"=",
"0",
";",
"size",
"+=",
"encoding",
".",
"sizeVarint",
"(",
"script",
".",
"raw",
".",
"length",
"+",
"COMPRESS_TYPES",
")",
";",
"size",
"+=",
"script",
".",
"raw",
".",
"length",
";",
"return",
"size",
";",
"}"
] | Calculate script size.
@returns {Number} | [
"Calculate",
"script",
"size",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/coins/compress.js#L135-L153 | train |
WorldMobileCoin/wmcc-core | src/coins/compress.js | compressOutput | function compressOutput(output, bw) {
bw.writeVarint(output.value);
compressScript(output.script, bw);
return bw;
} | javascript | function compressOutput(output, bw) {
bw.writeVarint(output.value);
compressScript(output.script, bw);
return bw;
} | [
"function",
"compressOutput",
"(",
"output",
",",
"bw",
")",
"{",
"bw",
".",
"writeVarint",
"(",
"output",
".",
"value",
")",
";",
"compressScript",
"(",
"output",
".",
"script",
",",
"bw",
")",
";",
"return",
"bw",
";",
"}"
] | Compress an output.
@param {Output} output
@param {BufferWriter} bw | [
"Compress",
"an",
"output",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/coins/compress.js#L161-L165 | train |
WorldMobileCoin/wmcc-core | src/coins/compress.js | sizeOutput | function sizeOutput(output) {
let size = 0;
size += encoding.sizeVarint(output.value);
size += sizeScript(output.script);
return size;
} | javascript | function sizeOutput(output) {
let size = 0;
size += encoding.sizeVarint(output.value);
size += sizeScript(output.script);
return size;
} | [
"function",
"sizeOutput",
"(",
"output",
")",
"{",
"let",
"size",
"=",
"0",
";",
"size",
"+=",
"encoding",
".",
"sizeVarint",
"(",
"output",
".",
"value",
")",
";",
"size",
"+=",
"sizeScript",
"(",
"output",
".",
"script",
")",
";",
"return",
"size",
";",
"}"
] | Calculate output size.
@returns {Number} | [
"Calculate",
"output",
"size",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/coins/compress.js#L184-L189 | train |
WorldMobileCoin/wmcc-core | src/coins/compress.js | compressValue | function compressValue(value) {
if (value === 0)
return 0;
let exp = 0;
while (value % 10 === 0 && exp < 9) {
value /= 10;
exp++;
}
if (exp < 9) {
const last = value % 10;
value = (value - last) / 10;
return 1 + 10 * (9 * value + last - 1) + exp;
}
return 10 + 10 * (value - 1);
} | javascript | function compressValue(value) {
if (value === 0)
return 0;
let exp = 0;
while (value % 10 === 0 && exp < 9) {
value /= 10;
exp++;
}
if (exp < 9) {
const last = value % 10;
value = (value - last) / 10;
return 1 + 10 * (9 * value + last - 1) + exp;
}
return 10 + 10 * (value - 1);
} | [
"function",
"compressValue",
"(",
"value",
")",
"{",
"if",
"(",
"value",
"===",
"0",
")",
"return",
"0",
";",
"let",
"exp",
"=",
"0",
";",
"while",
"(",
"value",
"%",
"10",
"===",
"0",
"&&",
"exp",
"<",
"9",
")",
"{",
"value",
"/=",
"10",
";",
"exp",
"++",
";",
"}",
"if",
"(",
"exp",
"<",
"9",
")",
"{",
"const",
"last",
"=",
"value",
"%",
"10",
";",
"value",
"=",
"(",
"value",
"-",
"last",
")",
"/",
"10",
";",
"return",
"1",
"+",
"10",
"*",
"(",
"9",
"*",
"value",
"+",
"last",
"-",
"1",
")",
"+",
"exp",
";",
"}",
"return",
"10",
"+",
"10",
"*",
"(",
"value",
"-",
"1",
")",
";",
"}"
] | Compress value using an exponent. Takes advantage of
the fact that many bitcoin values are divisible by 10.
@see https://github.com/btcsuite/btcd/blob/master/blockchain/compress.go
@param {Amount} value
@returns {Number} | [
"Compress",
"value",
"using",
"an",
"exponent",
".",
"Takes",
"advantage",
"of",
"the",
"fact",
"that",
"many",
"bitcoin",
"values",
"are",
"divisible",
"by",
"10",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/coins/compress.js#L199-L216 | train |
WorldMobileCoin/wmcc-core | src/coins/compress.js | decompressValue | function decompressValue(value) {
if (value === 0)
return 0;
value--;
let exp = value % 10;
value = (value - exp) / 10;
let n;
if (exp < 9) {
const last = value % 9;
value = (value - last) / 9;
n = value * 10 + last + 1;
} else {
n = value + 1;
}
while (exp > 0) {
n *= 10;
exp--;
}
return n;
} | javascript | function decompressValue(value) {
if (value === 0)
return 0;
value--;
let exp = value % 10;
value = (value - exp) / 10;
let n;
if (exp < 9) {
const last = value % 9;
value = (value - last) / 9;
n = value * 10 + last + 1;
} else {
n = value + 1;
}
while (exp > 0) {
n *= 10;
exp--;
}
return n;
} | [
"function",
"decompressValue",
"(",
"value",
")",
"{",
"if",
"(",
"value",
"===",
"0",
")",
"return",
"0",
";",
"value",
"--",
";",
"let",
"exp",
"=",
"value",
"%",
"10",
";",
"value",
"=",
"(",
"value",
"-",
"exp",
")",
"/",
"10",
";",
"let",
"n",
";",
"if",
"(",
"exp",
"<",
"9",
")",
"{",
"const",
"last",
"=",
"value",
"%",
"9",
";",
"value",
"=",
"(",
"value",
"-",
"last",
")",
"/",
"9",
";",
"n",
"=",
"value",
"*",
"10",
"+",
"last",
"+",
"1",
";",
"}",
"else",
"{",
"n",
"=",
"value",
"+",
"1",
";",
"}",
"while",
"(",
"exp",
">",
"0",
")",
"{",
"n",
"*=",
"10",
";",
"exp",
"--",
";",
"}",
"return",
"n",
";",
"}"
] | Decompress value.
@param {Number} value - Compressed value.
@returns {Amount} value | [
"Decompress",
"value",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/coins/compress.js#L224-L249 | train |
WorldMobileCoin/wmcc-core | src/coins/compress.js | compressKey | function compressKey(key) {
let out;
switch (key[0]) {
case 0x02:
case 0x03:
// Key is already compressed.
out = key;
break;
case 0x04:
// Compress the key normally.
out = secp256k1.publicKeyConvert(key, true);
// Store the oddness.
// Pseudo-hybrid format.
out[0] = 0x04 | (key[64] & 0x01);
break;
default:
throw new Error('Bad point format.');
}
assert(out.length === 33);
return out;
} | javascript | function compressKey(key) {
let out;
switch (key[0]) {
case 0x02:
case 0x03:
// Key is already compressed.
out = key;
break;
case 0x04:
// Compress the key normally.
out = secp256k1.publicKeyConvert(key, true);
// Store the oddness.
// Pseudo-hybrid format.
out[0] = 0x04 | (key[64] & 0x01);
break;
default:
throw new Error('Bad point format.');
}
assert(out.length === 33);
return out;
} | [
"function",
"compressKey",
"(",
"key",
")",
"{",
"let",
"out",
";",
"switch",
"(",
"key",
"[",
"0",
"]",
")",
"{",
"case",
"0x02",
":",
"case",
"0x03",
":",
"out",
"=",
"key",
";",
"break",
";",
"case",
"0x04",
":",
"out",
"=",
"secp256k1",
".",
"publicKeyConvert",
"(",
"key",
",",
"true",
")",
";",
"out",
"[",
"0",
"]",
"=",
"0x04",
"|",
"(",
"key",
"[",
"64",
"]",
"&",
"0x01",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"Error",
"(",
"'Bad point format.'",
")",
";",
"}",
"assert",
"(",
"out",
".",
"length",
"===",
"33",
")",
";",
"return",
"out",
";",
"}"
] | Compress a public key to coins compression format.
@param {Buffer} key
@returns {Buffer} | [
"Compress",
"a",
"public",
"key",
"to",
"coins",
"compression",
"format",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/coins/compress.js#L281-L304 | train |
WorldMobileCoin/wmcc-core | src/coins/compress.js | decompressKey | function decompressKey(key) {
const format = key[0];
assert(key.length === 33);
switch (format) {
case 0x02:
case 0x03:
return key;
case 0x04:
key[0] = 0x02;
break;
case 0x05:
key[0] = 0x03;
break;
default:
throw new Error('Bad point format.');
}
// Decompress the key.
const out = secp256k1.publicKeyConvert(key, false);
// Reset the first byte so as not to
// mutate the original buffer.
key[0] = format;
return out;
} | javascript | function decompressKey(key) {
const format = key[0];
assert(key.length === 33);
switch (format) {
case 0x02:
case 0x03:
return key;
case 0x04:
key[0] = 0x02;
break;
case 0x05:
key[0] = 0x03;
break;
default:
throw new Error('Bad point format.');
}
// Decompress the key.
const out = secp256k1.publicKeyConvert(key, false);
// Reset the first byte so as not to
// mutate the original buffer.
key[0] = format;
return out;
} | [
"function",
"decompressKey",
"(",
"key",
")",
"{",
"const",
"format",
"=",
"key",
"[",
"0",
"]",
";",
"assert",
"(",
"key",
".",
"length",
"===",
"33",
")",
";",
"switch",
"(",
"format",
")",
"{",
"case",
"0x02",
":",
"case",
"0x03",
":",
"return",
"key",
";",
"case",
"0x04",
":",
"key",
"[",
"0",
"]",
"=",
"0x02",
";",
"break",
";",
"case",
"0x05",
":",
"key",
"[",
"0",
"]",
"=",
"0x03",
";",
"break",
";",
"default",
":",
"throw",
"new",
"Error",
"(",
"'Bad point format.'",
")",
";",
"}",
"const",
"out",
"=",
"secp256k1",
".",
"publicKeyConvert",
"(",
"key",
",",
"false",
")",
";",
"key",
"[",
"0",
"]",
"=",
"format",
";",
"return",
"out",
";",
"}"
] | Decompress a public key from the coins compression format.
@param {Buffer} key
@returns {Buffer} | [
"Decompress",
"a",
"public",
"key",
"from",
"the",
"coins",
"compression",
"format",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/coins/compress.js#L312-L339 | train |
WorldMobileCoin/wmcc-core | src/net/parser.js | Parser | function Parser(network) {
if (!(this instanceof Parser))
return new Parser(network);
EventEmitter.call(this);
this.network = Network.get(network);
this.pending = [];
this.total = 0;
this.waiting = 24;
this.header = null;
} | javascript | function Parser(network) {
if (!(this instanceof Parser))
return new Parser(network);
EventEmitter.call(this);
this.network = Network.get(network);
this.pending = [];
this.total = 0;
this.waiting = 24;
this.header = null;
} | [
"function",
"Parser",
"(",
"network",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Parser",
")",
")",
"return",
"new",
"Parser",
"(",
"network",
")",
";",
"EventEmitter",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"network",
"=",
"Network",
".",
"get",
"(",
"network",
")",
";",
"this",
".",
"pending",
"=",
"[",
"]",
";",
"this",
".",
"total",
"=",
"0",
";",
"this",
".",
"waiting",
"=",
"24",
";",
"this",
".",
"header",
"=",
"null",
";",
"}"
] | Protocol packet parser
@alias module:net.Parser
@constructor
@param {Network} network
@emits Parser#error
@emits Parser#packet | [
"Protocol",
"packet",
"parser"
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/net/parser.js#L33-L45 | train |
WorldMobileCoin/wmcc-core | src/db/lowlevelup.js | LowlevelUp | function LowlevelUp(backend, location, options) {
if (!(this instanceof LowlevelUp))
return new LowlevelUp(backend, location, options);
assert(typeof backend === 'function', 'Backend is required.');
assert(typeof location === 'string', 'Filename is required.');
this.options = new LLUOptions(options);
this.backend = backend;
this.location = location;
this.locker = new Lock();
this.loading = false;
this.closing = false;
this.loaded = false;
this.db = null;
this.binding = null;
this.init();
} | javascript | function LowlevelUp(backend, location, options) {
if (!(this instanceof LowlevelUp))
return new LowlevelUp(backend, location, options);
assert(typeof backend === 'function', 'Backend is required.');
assert(typeof location === 'string', 'Filename is required.');
this.options = new LLUOptions(options);
this.backend = backend;
this.location = location;
this.locker = new Lock();
this.loading = false;
this.closing = false;
this.loaded = false;
this.db = null;
this.binding = null;
this.init();
} | [
"function",
"LowlevelUp",
"(",
"backend",
",",
"location",
",",
"options",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"LowlevelUp",
")",
")",
"return",
"new",
"LowlevelUp",
"(",
"backend",
",",
"location",
",",
"options",
")",
";",
"assert",
"(",
"typeof",
"backend",
"===",
"'function'",
",",
"'Backend is required.'",
")",
";",
"assert",
"(",
"typeof",
"location",
"===",
"'string'",
",",
"'Filename is required.'",
")",
";",
"this",
".",
"options",
"=",
"new",
"LLUOptions",
"(",
"options",
")",
";",
"this",
".",
"backend",
"=",
"backend",
";",
"this",
".",
"location",
"=",
"location",
";",
"this",
".",
"locker",
"=",
"new",
"Lock",
"(",
")",
";",
"this",
".",
"loading",
"=",
"false",
";",
"this",
".",
"closing",
"=",
"false",
";",
"this",
".",
"loaded",
"=",
"false",
";",
"this",
".",
"db",
"=",
"null",
";",
"this",
".",
"binding",
"=",
"null",
";",
"this",
".",
"init",
"(",
")",
";",
"}"
] | Extremely low-level version of levelup.
This avoids pulling in extra deps and
lowers memory usage.
@alias module:db.LowlevelUp
@constructor
@param {Function} backend - Database backend.
@param {String} location - File location.
@param {Object?} options - Leveldown options. | [
"Extremely",
"low",
"-",
"level",
"version",
"of",
"levelup",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/db/lowlevelup.js#L36-L56 | train |
WorldMobileCoin/wmcc-core | src/primitives/mtx.js | MTX | function MTX(options) {
if (!(this instanceof MTX))
return new MTX(options);
TX.call(this);
this.mutable = true;
this.changeIndex = -1;
this.view = new CoinView();
if (options)
this.fromOptions(options);
} | javascript | function MTX(options) {
if (!(this instanceof MTX))
return new MTX(options);
TX.call(this);
this.mutable = true;
this.changeIndex = -1;
this.view = new CoinView();
if (options)
this.fromOptions(options);
} | [
"function",
"MTX",
"(",
"options",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"MTX",
")",
")",
"return",
"new",
"MTX",
"(",
"options",
")",
";",
"TX",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"mutable",
"=",
"true",
";",
"this",
".",
"changeIndex",
"=",
"-",
"1",
";",
"this",
".",
"view",
"=",
"new",
"CoinView",
"(",
")",
";",
"if",
"(",
"options",
")",
"this",
".",
"fromOptions",
"(",
"options",
")",
";",
"}"
] | A mutable transaction object.
@alias module:primitives.MTX
@extends TX
@constructor
@param {Object} options
@param {Number?} options.version
@param {Number?} options.changeIndex
@param {Input[]?} options.inputs
@param {Output[]?} options.outputs
@property {Number} version - Transaction version.
@property {Number} flag - Flag field for segregated witness.
Always non-zero (1 if not present).
@property {Input[]} inputs
@property {Output[]} outputs
@property {Number} locktime - nLockTime
@property {CoinView} view | [
"A",
"mutable",
"transaction",
"object",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/primitives/mtx.js#L49-L61 | train |
WorldMobileCoin/wmcc-core | src/primitives/mtx.js | FundingError | function FundingError(msg, available, required) {
Error.call(this);
this.type = 'FundingError';
this.message = msg;
this.availableFunds = -1;
this.requiredFunds = -1;
if (available != null) {
this.message += ` (available=${Amount.wmcc(available)},`;
this.message += ` required=${Amount.wmcc(required)})`;
this.availableFunds = available;
this.requiredFunds = required;
}
if (Error.captureStackTrace)
Error.captureStackTrace(this, FundingError);
} | javascript | function FundingError(msg, available, required) {
Error.call(this);
this.type = 'FundingError';
this.message = msg;
this.availableFunds = -1;
this.requiredFunds = -1;
if (available != null) {
this.message += ` (available=${Amount.wmcc(available)},`;
this.message += ` required=${Amount.wmcc(required)})`;
this.availableFunds = available;
this.requiredFunds = required;
}
if (Error.captureStackTrace)
Error.captureStackTrace(this, FundingError);
} | [
"function",
"FundingError",
"(",
"msg",
",",
"available",
",",
"required",
")",
"{",
"Error",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"type",
"=",
"'FundingError'",
";",
"this",
".",
"message",
"=",
"msg",
";",
"this",
".",
"availableFunds",
"=",
"-",
"1",
";",
"this",
".",
"requiredFunds",
"=",
"-",
"1",
";",
"if",
"(",
"available",
"!=",
"null",
")",
"{",
"this",
".",
"message",
"+=",
"`",
"${",
"Amount",
".",
"wmcc",
"(",
"available",
")",
"}",
"`",
";",
"this",
".",
"message",
"+=",
"`",
"${",
"Amount",
".",
"wmcc",
"(",
"required",
")",
"}",
"`",
";",
"this",
".",
"availableFunds",
"=",
"available",
";",
"this",
".",
"requiredFunds",
"=",
"required",
";",
"}",
"if",
"(",
"Error",
".",
"captureStackTrace",
")",
"Error",
".",
"captureStackTrace",
"(",
"this",
",",
"FundingError",
")",
";",
"}"
] | An error thrown from the coin selector.
@constructor
@ignore
@extends Error
@param {String} msg
@param {Amount} available
@param {Amount} required
@property {String} message - Error message.
@property {Amount} availableFunds
@property {Amount} requiredFunds | [
"An",
"error",
"thrown",
"from",
"the",
"coin",
"selector",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/primitives/mtx.js#L1915-L1932 | train |
WorldMobileCoin/wmcc-core | src/workers/workerpool.js | WorkerPool | function WorkerPool(options) {
if (!(this instanceof WorkerPool))
return new WorkerPool(options);
EventEmitter.call(this);
this.enabled = false;
this.size = getCores();
this.timeout = 120000;
this.file = process.env.WMCC_WORKER_FILE || 'worker.js';
this.children = new Map();
this.uid = 0;
this.set(options);
} | javascript | function WorkerPool(options) {
if (!(this instanceof WorkerPool))
return new WorkerPool(options);
EventEmitter.call(this);
this.enabled = false;
this.size = getCores();
this.timeout = 120000;
this.file = process.env.WMCC_WORKER_FILE || 'worker.js';
this.children = new Map();
this.uid = 0;
this.set(options);
} | [
"function",
"WorkerPool",
"(",
"options",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"WorkerPool",
")",
")",
"return",
"new",
"WorkerPool",
"(",
"options",
")",
";",
"EventEmitter",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"enabled",
"=",
"false",
";",
"this",
".",
"size",
"=",
"getCores",
"(",
")",
";",
"this",
".",
"timeout",
"=",
"120000",
";",
"this",
".",
"file",
"=",
"process",
".",
"env",
".",
"WMCC_WORKER_FILE",
"||",
"'worker.js'",
";",
"this",
".",
"children",
"=",
"new",
"Map",
"(",
")",
";",
"this",
".",
"uid",
"=",
"0",
";",
"this",
".",
"set",
"(",
"options",
")",
";",
"}"
] | A worker pool.
@alias module:workers.WorkerPool
@constructor
@param {Object} options
@param {Number} [options.size=num-cores] - Max pool size.
@param {Number} [options.timeout=120000] - Execution timeout.
@property {Number} size
@property {Number} timeout
@property {Map} children
@property {Number} uid | [
"A",
"worker",
"pool",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/workers/workerpool.js#L41-L56 | train |
WorldMobileCoin/wmcc-core | src/workers/workerpool.js | Worker | function Worker(file) {
if (!(this instanceof Worker))
return new Worker(file);
EventEmitter.call(this);
this.id = -1;
this.framer = new Framer();
this.parser = new Parser();
this.pending = new Map();
this.child = new Child(file);
this.init();
} | javascript | function Worker(file) {
if (!(this instanceof Worker))
return new Worker(file);
EventEmitter.call(this);
this.id = -1;
this.framer = new Framer();
this.parser = new Parser();
this.pending = new Map();
this.child = new Child(file);
this.init();
} | [
"function",
"Worker",
"(",
"file",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Worker",
")",
")",
"return",
"new",
"Worker",
"(",
"file",
")",
";",
"EventEmitter",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"id",
"=",
"-",
"1",
";",
"this",
".",
"framer",
"=",
"new",
"Framer",
"(",
")",
";",
"this",
".",
"parser",
"=",
"new",
"Parser",
"(",
")",
";",
"this",
".",
"pending",
"=",
"new",
"Map",
"(",
")",
";",
"this",
".",
"child",
"=",
"new",
"Child",
"(",
"file",
")",
";",
"this",
".",
"init",
"(",
")",
";",
"}"
] | Represents a worker.
@alias module:workers.Worker
@constructor
@param {String} file | [
"Represents",
"a",
"worker",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/workers/workerpool.js#L369-L383 | train |
Karnith/machinepack-sailsgulpify | templates/gulpfile.js | invokeConfigFn | function invokeConfigFn(tasks) {
for (var taskName in tasks) {
if (tasks.hasOwnProperty(taskName)) {
tasks[taskName](gulp, plugins, growl, path);
}
}
} | javascript | function invokeConfigFn(tasks) {
for (var taskName in tasks) {
if (tasks.hasOwnProperty(taskName)) {
tasks[taskName](gulp, plugins, growl, path);
}
}
} | [
"function",
"invokeConfigFn",
"(",
"tasks",
")",
"{",
"for",
"(",
"var",
"taskName",
"in",
"tasks",
")",
"{",
"if",
"(",
"tasks",
".",
"hasOwnProperty",
"(",
"taskName",
")",
")",
"{",
"tasks",
"[",
"taskName",
"]",
"(",
"gulp",
",",
"plugins",
",",
"growl",
",",
"path",
")",
";",
"}",
"}",
"}"
] | Invokes the function from a Grunt configuration module with
a single argument - the `grunt` object. | [
"Invokes",
"the",
"function",
"from",
"a",
"Grunt",
"configuration",
"module",
"with",
"a",
"single",
"argument",
"-",
"the",
"grunt",
"object",
"."
] | 38424f98d59cac4240e676159bd25e3bc82ad8ac | https://github.com/Karnith/machinepack-sailsgulpify/blob/38424f98d59cac4240e676159bd25e3bc82ad8ac/templates/gulpfile.js#L66-L72 | train |
axyjs/node-custom-errors | index.js | create | function create(name, parent, defmessage, abstract, construct) {
if (typeof name === "object") {
return create(name.name, name.parent, name.defmessage, name.abstract, name.construct);
}
parent = parent || global.Error;
if ((defmessage === null) || (defmessage === undefined)) {
if (parent.ce && parent.ce.hasOwnProperty("defmessage")) {
defmessage = parent.ce.defmessage;
}
}
if (typeof construct !== "function") {
if (parent.ce && (typeof parent.ce.construct === "function")) {
construct = parent.ce.construct;
} else {
construct = null;
}
}
function CustomError(message) {
Error.call(this);
Error.captureStackTrace(this, CustomError);
if (abstract) {
throw new AbstractError(name);
}
if (construct) {
construct.apply(this, arguments);
} else {
if ((message !== undefined) && (message !== null)) {
this.message = message;
}
}
}
CustomError.prototype = Object.create(parent.prototype);
CustomError.prototype.constructor = CustomError;
CustomError.prototype.name = name;
CustomError.prototype.message = defmessage;
CustomError.prototype.parent = helpers.parent;
CustomError.ce = {
parent: parent,
defmessage: defmessage,
construct: construct
};
CustomError.inherit = helpers.inherit;
CustomError.toString = function () {
return "[Error class " + name + "]";
};
CustomError.init = function init() {
return call.apply(construct, slice.call(arguments));
};
return CustomError;
} | javascript | function create(name, parent, defmessage, abstract, construct) {
if (typeof name === "object") {
return create(name.name, name.parent, name.defmessage, name.abstract, name.construct);
}
parent = parent || global.Error;
if ((defmessage === null) || (defmessage === undefined)) {
if (parent.ce && parent.ce.hasOwnProperty("defmessage")) {
defmessage = parent.ce.defmessage;
}
}
if (typeof construct !== "function") {
if (parent.ce && (typeof parent.ce.construct === "function")) {
construct = parent.ce.construct;
} else {
construct = null;
}
}
function CustomError(message) {
Error.call(this);
Error.captureStackTrace(this, CustomError);
if (abstract) {
throw new AbstractError(name);
}
if (construct) {
construct.apply(this, arguments);
} else {
if ((message !== undefined) && (message !== null)) {
this.message = message;
}
}
}
CustomError.prototype = Object.create(parent.prototype);
CustomError.prototype.constructor = CustomError;
CustomError.prototype.name = name;
CustomError.prototype.message = defmessage;
CustomError.prototype.parent = helpers.parent;
CustomError.ce = {
parent: parent,
defmessage: defmessage,
construct: construct
};
CustomError.inherit = helpers.inherit;
CustomError.toString = function () {
return "[Error class " + name + "]";
};
CustomError.init = function init() {
return call.apply(construct, slice.call(arguments));
};
return CustomError;
} | [
"function",
"create",
"(",
"name",
",",
"parent",
",",
"defmessage",
",",
"abstract",
",",
"construct",
")",
"{",
"if",
"(",
"typeof",
"name",
"===",
"\"object\"",
")",
"{",
"return",
"create",
"(",
"name",
".",
"name",
",",
"name",
".",
"parent",
",",
"name",
".",
"defmessage",
",",
"name",
".",
"abstract",
",",
"name",
".",
"construct",
")",
";",
"}",
"parent",
"=",
"parent",
"||",
"global",
".",
"Error",
";",
"if",
"(",
"(",
"defmessage",
"===",
"null",
")",
"||",
"(",
"defmessage",
"===",
"undefined",
")",
")",
"{",
"if",
"(",
"parent",
".",
"ce",
"&&",
"parent",
".",
"ce",
".",
"hasOwnProperty",
"(",
"\"defmessage\"",
")",
")",
"{",
"defmessage",
"=",
"parent",
".",
"ce",
".",
"defmessage",
";",
"}",
"}",
"if",
"(",
"typeof",
"construct",
"!==",
"\"function\"",
")",
"{",
"if",
"(",
"parent",
".",
"ce",
"&&",
"(",
"typeof",
"parent",
".",
"ce",
".",
"construct",
"===",
"\"function\"",
")",
")",
"{",
"construct",
"=",
"parent",
".",
"ce",
".",
"construct",
";",
"}",
"else",
"{",
"construct",
"=",
"null",
";",
"}",
"}",
"function",
"CustomError",
"(",
"message",
")",
"{",
"Error",
".",
"call",
"(",
"this",
")",
";",
"Error",
".",
"captureStackTrace",
"(",
"this",
",",
"CustomError",
")",
";",
"if",
"(",
"abstract",
")",
"{",
"throw",
"new",
"AbstractError",
"(",
"name",
")",
";",
"}",
"if",
"(",
"construct",
")",
"{",
"construct",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"}",
"else",
"{",
"if",
"(",
"(",
"message",
"!==",
"undefined",
")",
"&&",
"(",
"message",
"!==",
"null",
")",
")",
"{",
"this",
".",
"message",
"=",
"message",
";",
"}",
"}",
"}",
"CustomError",
".",
"prototype",
"=",
"Object",
".",
"create",
"(",
"parent",
".",
"prototype",
")",
";",
"CustomError",
".",
"prototype",
".",
"constructor",
"=",
"CustomError",
";",
"CustomError",
".",
"prototype",
".",
"name",
"=",
"name",
";",
"CustomError",
".",
"prototype",
".",
"message",
"=",
"defmessage",
";",
"CustomError",
".",
"prototype",
".",
"parent",
"=",
"helpers",
".",
"parent",
";",
"CustomError",
".",
"ce",
"=",
"{",
"parent",
":",
"parent",
",",
"defmessage",
":",
"defmessage",
",",
"construct",
":",
"construct",
"}",
";",
"CustomError",
".",
"inherit",
"=",
"helpers",
".",
"inherit",
";",
"CustomError",
".",
"toString",
"=",
"function",
"(",
")",
"{",
"return",
"\"[Error class \"",
"+",
"name",
"+",
"\"]\"",
";",
"}",
";",
"CustomError",
".",
"init",
"=",
"function",
"init",
"(",
")",
"{",
"return",
"call",
".",
"apply",
"(",
"construct",
",",
"slice",
".",
"call",
"(",
"arguments",
")",
")",
";",
"}",
";",
"return",
"CustomError",
";",
"}"
] | Create a custom error class
@param {(String|Object)} name
the name of exception (or dictionary of arguments)
@param {Function} [parent]
the parent exception class (constructor) (Error by default)
@param {String} [defmessage]
the default message
@param {Boolean} [abstract]
the flag of an abstract class
@param {Function} [construct]
the custom constructor for this class
@return {Function}
the constructor of custom error | [
"Create",
"a",
"custom",
"error",
"class"
] | 45cf42257c666b8dbffcafe0636985d3973b83c7 | https://github.com/axyjs/node-custom-errors/blob/45cf42257c666b8dbffcafe0636985d3973b83c7/index.js#L32-L81 | train |
axyjs/node-custom-errors | index.js | parent | function parent() {
var ce = this.constructor.ce;
if (ce && ce.parent) {
ce = ce.parent.ce;
if (ce && (typeof ce.construct === "function")) {
ce.construct.apply(this, arguments);
}
}
} | javascript | function parent() {
var ce = this.constructor.ce;
if (ce && ce.parent) {
ce = ce.parent.ce;
if (ce && (typeof ce.construct === "function")) {
ce.construct.apply(this, arguments);
}
}
} | [
"function",
"parent",
"(",
")",
"{",
"var",
"ce",
"=",
"this",
".",
"constructor",
".",
"ce",
";",
"if",
"(",
"ce",
"&&",
"ce",
".",
"parent",
")",
"{",
"ce",
"=",
"ce",
".",
"parent",
".",
"ce",
";",
"if",
"(",
"ce",
"&&",
"(",
"typeof",
"ce",
".",
"construct",
"===",
"\"function\"",
")",
")",
"{",
"ce",
".",
"construct",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"}",
"}",
"}"
] | Execute the parent constructor
@name CustomErrors#parent | [
"Execute",
"the",
"parent",
"constructor"
] | 45cf42257c666b8dbffcafe0636985d3973b83c7 | https://github.com/axyjs/node-custom-errors/blob/45cf42257c666b8dbffcafe0636985d3973b83c7/index.js#L89-L97 | train |
axyjs/node-custom-errors | index.js | inherit | function inherit(name, defmessage, abstract, construct) {
if (typeof name === "object") {
name.parent = this;
return create(name);
}
return create(name, this, defmessage, abstract, construct);
} | javascript | function inherit(name, defmessage, abstract, construct) {
if (typeof name === "object") {
name.parent = this;
return create(name);
}
return create(name, this, defmessage, abstract, construct);
} | [
"function",
"inherit",
"(",
"name",
",",
"defmessage",
",",
"abstract",
",",
"construct",
")",
"{",
"if",
"(",
"typeof",
"name",
"===",
"\"object\"",
")",
"{",
"name",
".",
"parent",
"=",
"this",
";",
"return",
"create",
"(",
"name",
")",
";",
"}",
"return",
"create",
"(",
"name",
",",
"this",
",",
"defmessage",
",",
"abstract",
",",
"construct",
")",
";",
"}"
] | Inherit from this class
@name CustomErrors.inherit
@public
@param {(String|Object)} name
@param {String} [defmessage]
@param {Boolean} [abstract]
@param {Function} [construct]
@return {Function} | [
"Inherit",
"from",
"this",
"class"
] | 45cf42257c666b8dbffcafe0636985d3973b83c7 | https://github.com/axyjs/node-custom-errors/blob/45cf42257c666b8dbffcafe0636985d3973b83c7/index.js#L110-L116 | train |
axyjs/node-custom-errors | index.js | Block | function Block(errors, namespace, base, lazy) {
if ((base === undefined) || (base === true) || (base === null)) {
base = "Base";
} else if (base === false) {
base = Error;
} else if (typeof base !== "function") {
base = "" + base;
}
this.p = {
errors: errors,
namespace: namespace,
prefix: namespace ? (namespace + ".") : "",
base: base,
lazy: !!lazy
};
this.created = false;
if (!this.p.lazy) {
this.createAll();
}
} | javascript | function Block(errors, namespace, base, lazy) {
if ((base === undefined) || (base === true) || (base === null)) {
base = "Base";
} else if (base === false) {
base = Error;
} else if (typeof base !== "function") {
base = "" + base;
}
this.p = {
errors: errors,
namespace: namespace,
prefix: namespace ? (namespace + ".") : "",
base: base,
lazy: !!lazy
};
this.created = false;
if (!this.p.lazy) {
this.createAll();
}
} | [
"function",
"Block",
"(",
"errors",
",",
"namespace",
",",
"base",
",",
"lazy",
")",
"{",
"if",
"(",
"(",
"base",
"===",
"undefined",
")",
"||",
"(",
"base",
"===",
"true",
")",
"||",
"(",
"base",
"===",
"null",
")",
")",
"{",
"base",
"=",
"\"Base\"",
";",
"}",
"else",
"if",
"(",
"base",
"===",
"false",
")",
"{",
"base",
"=",
"Error",
";",
"}",
"else",
"if",
"(",
"typeof",
"base",
"!==",
"\"function\"",
")",
"{",
"base",
"=",
"\"\"",
"+",
"base",
";",
"}",
"this",
".",
"p",
"=",
"{",
"errors",
":",
"errors",
",",
"namespace",
":",
"namespace",
",",
"prefix",
":",
"namespace",
"?",
"(",
"namespace",
"+",
"\".\"",
")",
":",
"\"\"",
",",
"base",
":",
"base",
",",
"lazy",
":",
"!",
"!",
"lazy",
"}",
";",
"this",
".",
"created",
"=",
"false",
";",
"if",
"(",
"!",
"this",
".",
"p",
".",
"lazy",
")",
"{",
"this",
".",
"createAll",
"(",
")",
";",
"}",
"}"
] | Class of errors block
@class Block
@exports
@param {Object} errors
a dictionary "error name" => "parameters" (mixed)
@param {String} [namespace]
a basic namespace for the block
@param {*} [base]
a basic error class for the block
@param {Boolean} [lazy]
use lazy load | [
"Class",
"of",
"errors",
"block"
] | 45cf42257c666b8dbffcafe0636985d3973b83c7 | https://github.com/axyjs/node-custom-errors/blob/45cf42257c666b8dbffcafe0636985d3973b83c7/index.js#L151-L170 | train |
WorldMobileCoin/wmcc-core | src/primitives/output.js | Output | function Output(options) {
if (!(this instanceof Output))
return new Output(options);
this.value = 0;
this.script = new Script();
if (options)
this.fromOptions(options);
} | javascript | function Output(options) {
if (!(this instanceof Output))
return new Output(options);
this.value = 0;
this.script = new Script();
if (options)
this.fromOptions(options);
} | [
"function",
"Output",
"(",
"options",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Output",
")",
")",
"return",
"new",
"Output",
"(",
"options",
")",
";",
"this",
".",
"value",
"=",
"0",
";",
"this",
".",
"script",
"=",
"new",
"Script",
"(",
")",
";",
"if",
"(",
"options",
")",
"this",
".",
"fromOptions",
"(",
"options",
")",
";",
"}"
] | Represents a transaction output.
@alias module:primitives.Output
@constructor
@param {NakedOutput} options
@property {Amount} value - Value in wmcoins.
@property {Script} script | [
"Represents",
"a",
"transaction",
"output",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/primitives/output.js#L34-L43 | train |
WorldMobileCoin/wmcc-core | src/http/rpcclient.js | RPCClient | function RPCClient(options) {
if (!(this instanceof RPCClient))
return new RPCClient(options);
if (!options)
options = {};
if (typeof options === 'string')
options = { uri: options };
this.options = options;
this.network = Network.get(options.network);
this.uri = options.uri || `http://localhost:${this.network.rpcPort}`;
this.apiKey = options.apiKey;
this.id = 0;
} | javascript | function RPCClient(options) {
if (!(this instanceof RPCClient))
return new RPCClient(options);
if (!options)
options = {};
if (typeof options === 'string')
options = { uri: options };
this.options = options;
this.network = Network.get(options.network);
this.uri = options.uri || `http://localhost:${this.network.rpcPort}`;
this.apiKey = options.apiKey;
this.id = 0;
} | [
"function",
"RPCClient",
"(",
"options",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"RPCClient",
")",
")",
"return",
"new",
"RPCClient",
"(",
"options",
")",
";",
"if",
"(",
"!",
"options",
")",
"options",
"=",
"{",
"}",
";",
"if",
"(",
"typeof",
"options",
"===",
"'string'",
")",
"options",
"=",
"{",
"uri",
":",
"options",
"}",
";",
"this",
".",
"options",
"=",
"options",
";",
"this",
".",
"network",
"=",
"Network",
".",
"get",
"(",
"options",
".",
"network",
")",
";",
"this",
".",
"uri",
"=",
"options",
".",
"uri",
"||",
"`",
"${",
"this",
".",
"network",
".",
"rpcPort",
"}",
"`",
";",
"this",
".",
"apiKey",
"=",
"options",
".",
"apiKey",
";",
"this",
".",
"id",
"=",
"0",
";",
"}"
] | WMCC RPC client.
@alias module:http.RPCClient
@constructor
@param {String} uri
@param {Object?} options | [
"WMCC",
"RPC",
"client",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/http/rpcclient.js#L24-L40 | train |
rubenoost/knx-dpt | src/index.js | function (dptid) {
var baseId = null;
var subId = null;
// Parse the dpt id
// If it is a raw number
if (typeof dptid === 'number' && isFinite(dptid)) {
// we're passed in a raw number (9)
baseId = dptid;
// If it is a string
} else if (typeof dptid == 'string') {
var m = dptid.toUpperCase().match(/(\d+)(\.(\d+))?/);
baseId = parseInt(m[1]);
if (m[3]) {
subId = m[3];
}
}
// Verify whether it exists
if (baseId === null || !layouts[baseId] || (subId !== null && !layouts[baseId].subs[subId])) {
console.trace("no such DPT: %j", dptid);
throw "No such DPT";
} else {
return buildDPT(baseId, subId);
}
} | javascript | function (dptid) {
var baseId = null;
var subId = null;
// Parse the dpt id
// If it is a raw number
if (typeof dptid === 'number' && isFinite(dptid)) {
// we're passed in a raw number (9)
baseId = dptid;
// If it is a string
} else if (typeof dptid == 'string') {
var m = dptid.toUpperCase().match(/(\d+)(\.(\d+))?/);
baseId = parseInt(m[1]);
if (m[3]) {
subId = m[3];
}
}
// Verify whether it exists
if (baseId === null || !layouts[baseId] || (subId !== null && !layouts[baseId].subs[subId])) {
console.trace("no such DPT: %j", dptid);
throw "No such DPT";
} else {
return buildDPT(baseId, subId);
}
} | [
"function",
"(",
"dptid",
")",
"{",
"var",
"baseId",
"=",
"null",
";",
"var",
"subId",
"=",
"null",
";",
"if",
"(",
"typeof",
"dptid",
"===",
"'number'",
"&&",
"isFinite",
"(",
"dptid",
")",
")",
"{",
"baseId",
"=",
"dptid",
";",
"}",
"else",
"if",
"(",
"typeof",
"dptid",
"==",
"'string'",
")",
"{",
"var",
"m",
"=",
"dptid",
".",
"toUpperCase",
"(",
")",
".",
"match",
"(",
"/",
"(\\d+)(\\.(\\d+))?",
"/",
")",
";",
"baseId",
"=",
"parseInt",
"(",
"m",
"[",
"1",
"]",
")",
";",
"if",
"(",
"m",
"[",
"3",
"]",
")",
"{",
"subId",
"=",
"m",
"[",
"3",
"]",
";",
"}",
"}",
"if",
"(",
"baseId",
"===",
"null",
"||",
"!",
"layouts",
"[",
"baseId",
"]",
"||",
"(",
"subId",
"!==",
"null",
"&&",
"!",
"layouts",
"[",
"baseId",
"]",
".",
"subs",
"[",
"subId",
"]",
")",
")",
"{",
"console",
".",
"trace",
"(",
"\"no such DPT: %j\"",
",",
"dptid",
")",
";",
"throw",
"\"No such DPT\"",
";",
"}",
"else",
"{",
"return",
"buildDPT",
"(",
"baseId",
",",
"subId",
")",
";",
"}",
"}"
] | a generic DPT resolution function
@param dptid The datapoint id. Allowed formats: 9/"9"/"9.001"/"DPT9.001" | [
"a",
"generic",
"DPT",
"resolution",
"function"
] | b4b3ca6c946f4c26d09e045a7d0b6553ea8bbfae | https://github.com/rubenoost/knx-dpt/blob/b4b3ca6c946f4c26d09e045a7d0b6553ea8bbfae/src/index.js#L71-L96 | train |
|
Spiffyk/twitch-node-sdk | lib/twitch.core.js | api | function api(options, callback) {
if (!session) {
throw new Error('You must call init() before api()');
}
var version = options.version || 'v3';
var params = options.params || {};
callback = callback || function() {};
var authenticated = !!session.token,
url = REDIRECT_PATH + (options.url || options.method || '');
if (authenticated) params.oauth_token = session.token;
var request_options = {
host: REDIRECT_HOST,
path: url + '?' + util.param(params),
method: options.verb || 'GET',
headers: {
"Accept": "application/vnd.twitchtv." + version + "+json",
"Client-ID": clientId
}
};
var req = https.request(request_options, function(res) {
log('Response status:', res.statusCode, res.statusMessage);
res.setEncoding('utf8');
var responseBody = "";
res.on('data', function(data) {
responseBody += data;
});
res.on('end', function() {
var data = JSON.parse(responseBody);
if (res.statusCode >= 200 && res.statusCode < 300) { // Status 2xx means success
log('Response Data:', data);
callback(null, data || null);
}
else {
if (authenticated && res.statusCode === HTTP_CODES.unauthorized) {
auth.logout(function() {
callback(data, null);
});
}
else {
callback(data, null);
}
}
});
});
req.on('error', function (e) {
log('API Error:', e);
callback(e, null);
});
req.end();
} | javascript | function api(options, callback) {
if (!session) {
throw new Error('You must call init() before api()');
}
var version = options.version || 'v3';
var params = options.params || {};
callback = callback || function() {};
var authenticated = !!session.token,
url = REDIRECT_PATH + (options.url || options.method || '');
if (authenticated) params.oauth_token = session.token;
var request_options = {
host: REDIRECT_HOST,
path: url + '?' + util.param(params),
method: options.verb || 'GET',
headers: {
"Accept": "application/vnd.twitchtv." + version + "+json",
"Client-ID": clientId
}
};
var req = https.request(request_options, function(res) {
log('Response status:', res.statusCode, res.statusMessage);
res.setEncoding('utf8');
var responseBody = "";
res.on('data', function(data) {
responseBody += data;
});
res.on('end', function() {
var data = JSON.parse(responseBody);
if (res.statusCode >= 200 && res.statusCode < 300) { // Status 2xx means success
log('Response Data:', data);
callback(null, data || null);
}
else {
if (authenticated && res.statusCode === HTTP_CODES.unauthorized) {
auth.logout(function() {
callback(data, null);
});
}
else {
callback(data, null);
}
}
});
});
req.on('error', function (e) {
log('API Error:', e);
callback(e, null);
});
req.end();
} | [
"function",
"api",
"(",
"options",
",",
"callback",
")",
"{",
"if",
"(",
"!",
"session",
")",
"{",
"throw",
"new",
"Error",
"(",
"'You must call init() before api()'",
")",
";",
"}",
"var",
"version",
"=",
"options",
".",
"version",
"||",
"'v3'",
";",
"var",
"params",
"=",
"options",
".",
"params",
"||",
"{",
"}",
";",
"callback",
"=",
"callback",
"||",
"function",
"(",
")",
"{",
"}",
";",
"var",
"authenticated",
"=",
"!",
"!",
"session",
".",
"token",
",",
"url",
"=",
"REDIRECT_PATH",
"+",
"(",
"options",
".",
"url",
"||",
"options",
".",
"method",
"||",
"''",
")",
";",
"if",
"(",
"authenticated",
")",
"params",
".",
"oauth_token",
"=",
"session",
".",
"token",
";",
"var",
"request_options",
"=",
"{",
"host",
":",
"REDIRECT_HOST",
",",
"path",
":",
"url",
"+",
"'?'",
"+",
"util",
".",
"param",
"(",
"params",
")",
",",
"method",
":",
"options",
".",
"verb",
"||",
"'GET'",
",",
"headers",
":",
"{",
"\"Accept\"",
":",
"\"application/vnd.twitchtv.\"",
"+",
"version",
"+",
"\"+json\"",
",",
"\"Client-ID\"",
":",
"clientId",
"}",
"}",
";",
"var",
"req",
"=",
"https",
".",
"request",
"(",
"request_options",
",",
"function",
"(",
"res",
")",
"{",
"log",
"(",
"'Response status:'",
",",
"res",
".",
"statusCode",
",",
"res",
".",
"statusMessage",
")",
";",
"res",
".",
"setEncoding",
"(",
"'utf8'",
")",
";",
"var",
"responseBody",
"=",
"\"\"",
";",
"res",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"data",
")",
"{",
"responseBody",
"+=",
"data",
";",
"}",
")",
";",
"res",
".",
"on",
"(",
"'end'",
",",
"function",
"(",
")",
"{",
"var",
"data",
"=",
"JSON",
".",
"parse",
"(",
"responseBody",
")",
";",
"if",
"(",
"res",
".",
"statusCode",
">=",
"200",
"&&",
"res",
".",
"statusCode",
"<",
"300",
")",
"{",
"log",
"(",
"'Response Data:'",
",",
"data",
")",
";",
"callback",
"(",
"null",
",",
"data",
"||",
"null",
")",
";",
"}",
"else",
"{",
"if",
"(",
"authenticated",
"&&",
"res",
".",
"statusCode",
"===",
"HTTP_CODES",
".",
"unauthorized",
")",
"{",
"auth",
".",
"logout",
"(",
"function",
"(",
")",
"{",
"callback",
"(",
"data",
",",
"null",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"callback",
"(",
"data",
",",
"null",
")",
";",
"}",
"}",
"}",
")",
";",
"}",
")",
";",
"req",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
"e",
")",
"{",
"log",
"(",
"'API Error:'",
",",
"e",
")",
";",
"callback",
"(",
"e",
",",
"null",
")",
";",
"}",
")",
";",
"req",
".",
"end",
"(",
")",
";",
"}"
] | Performs asynchronous calls to the Twitch API.
`options` can have the following fields:
* `method` - The method of the API like `'channel'`.
* `params` - The parameters to augment the amount or type of data received.
* `verb` - The HTTP method like `'GET'`, `'PUT'` and `'DELETE'`
* `version` - The API version to use. Default is `'v3'`
@method api
@param {Object} options The object containing options
@param {function(err, data)} [callback] | [
"Performs",
"asynchronous",
"calls",
"to",
"the",
"Twitch",
"API",
"."
] | e98234ca52b12569298213869439d17169e26f27 | https://github.com/Spiffyk/twitch-node-sdk/blob/e98234ca52b12569298213869439d17169e26f27/lib/twitch.core.js#L69-L130 | train |
artikcloud/artikcloud-js | src/api/RegistrationsApi.js | function(apiClient) {
this.apiClient = apiClient || ApiClient.instance;
/**
* Callback function to receive the result of the confirmUser operation.
* @callback module:api/RegistrationsApi~confirmUserCallback
* @param {String} error Error message, if any.
* @param module:model/DeviceRegConfirmUserResponseEnvelope data The data returned by the service call.
* @param {String} response The complete HTTP response.
*/
/**
* Confirm User
* This call updates the registration request issued earlier by associating it with an authenticated user and captures all additional information required to add a new device.
* @param module:model/DeviceRegConfirmUserRequest registrationInfo Device Registration information.
* @param {module:api/RegistrationsApi~confirmUserCallback} callback The callback function, accepting three arguments: error, data, response
* data is of type: module:model/DeviceRegConfirmUserResponseEnvelope
*/
this.confirmUser = function(registrationInfo, callback) {
var postBody = registrationInfo;
// verify the required parameter 'registrationInfo' is set
if (registrationInfo == undefined || registrationInfo == null) {
throw "Missing the required parameter 'registrationInfo' when calling confirmUser";
}
var pathParams = {
};
var queryParams = {
};
var headerParams = {
};
var formParams = {
};
var authNames = ['artikcloud_oauth'];
var contentTypes = [];
var accepts = ['application/json'];
var returnType = DeviceRegConfirmUserResponseEnvelope;
return this.apiClient.callApi(
'/devices/registrations/pin', 'PUT',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
}
/**
* Callback function to receive the result of the getRequestStatusForUser operation.
* @callback module:api/RegistrationsApi~getRequestStatusForUserCallback
* @param {String} error Error message, if any.
* @param module:model/DeviceRegStatusResponseEnvelope data The data returned by the service call.
* @param {String} response The complete HTTP response.
*/
/**
* Get Request Status For User
* This call checks the status of the request so users can poll and know when registration is complete.
* @param String requestId Request ID.
* @param {module:api/RegistrationsApi~getRequestStatusForUserCallback} callback The callback function, accepting three arguments: error, data, response
* data is of type: module:model/DeviceRegStatusResponseEnvelope
*/
this.getRequestStatusForUser = function(requestId, callback) {
var postBody = null;
// verify the required parameter 'requestId' is set
if (requestId == undefined || requestId == null) {
throw "Missing the required parameter 'requestId' when calling getRequestStatusForUser";
}
var pathParams = {
'requestId': requestId
};
var queryParams = {
};
var headerParams = {
};
var formParams = {
};
var authNames = ['artikcloud_oauth'];
var contentTypes = [];
var accepts = ['application/json'];
var returnType = DeviceRegStatusResponseEnvelope;
return this.apiClient.callApi(
'/devices/registrations/{requestId}/status', 'GET',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
}
/**
* Callback function to receive the result of the unregisterDevice operation.
* @callback module:api/RegistrationsApi~unregisterDeviceCallback
* @param {String} error Error message, if any.
* @param module:model/UnregisterDeviceResponseEnvelope data The data returned by the service call.
* @param {String} response The complete HTTP response.
*/
/**
* Unregister Device
* This call clears any associations from the secure device registration.
* @param String deviceId Device ID.
* @param {module:api/RegistrationsApi~unregisterDeviceCallback} callback The callback function, accepting three arguments: error, data, response
* data is of type: module:model/UnregisterDeviceResponseEnvelope
*/
this.unregisterDevice = function(deviceId, callback) {
var postBody = null;
// verify the required parameter 'deviceId' is set
if (deviceId == undefined || deviceId == null) {
throw "Missing the required parameter 'deviceId' when calling unregisterDevice";
}
var pathParams = {
'deviceId': deviceId
};
var queryParams = {
};
var headerParams = {
};
var formParams = {
};
var authNames = ['artikcloud_oauth'];
var contentTypes = [];
var accepts = ['application/json'];
var returnType = UnregisterDeviceResponseEnvelope;
return this.apiClient.callApi(
'/devices/{deviceId}/registrations', 'DELETE',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
}
} | javascript | function(apiClient) {
this.apiClient = apiClient || ApiClient.instance;
/**
* Callback function to receive the result of the confirmUser operation.
* @callback module:api/RegistrationsApi~confirmUserCallback
* @param {String} error Error message, if any.
* @param module:model/DeviceRegConfirmUserResponseEnvelope data The data returned by the service call.
* @param {String} response The complete HTTP response.
*/
/**
* Confirm User
* This call updates the registration request issued earlier by associating it with an authenticated user and captures all additional information required to add a new device.
* @param module:model/DeviceRegConfirmUserRequest registrationInfo Device Registration information.
* @param {module:api/RegistrationsApi~confirmUserCallback} callback The callback function, accepting three arguments: error, data, response
* data is of type: module:model/DeviceRegConfirmUserResponseEnvelope
*/
this.confirmUser = function(registrationInfo, callback) {
var postBody = registrationInfo;
// verify the required parameter 'registrationInfo' is set
if (registrationInfo == undefined || registrationInfo == null) {
throw "Missing the required parameter 'registrationInfo' when calling confirmUser";
}
var pathParams = {
};
var queryParams = {
};
var headerParams = {
};
var formParams = {
};
var authNames = ['artikcloud_oauth'];
var contentTypes = [];
var accepts = ['application/json'];
var returnType = DeviceRegConfirmUserResponseEnvelope;
return this.apiClient.callApi(
'/devices/registrations/pin', 'PUT',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
}
/**
* Callback function to receive the result of the getRequestStatusForUser operation.
* @callback module:api/RegistrationsApi~getRequestStatusForUserCallback
* @param {String} error Error message, if any.
* @param module:model/DeviceRegStatusResponseEnvelope data The data returned by the service call.
* @param {String} response The complete HTTP response.
*/
/**
* Get Request Status For User
* This call checks the status of the request so users can poll and know when registration is complete.
* @param String requestId Request ID.
* @param {module:api/RegistrationsApi~getRequestStatusForUserCallback} callback The callback function, accepting three arguments: error, data, response
* data is of type: module:model/DeviceRegStatusResponseEnvelope
*/
this.getRequestStatusForUser = function(requestId, callback) {
var postBody = null;
// verify the required parameter 'requestId' is set
if (requestId == undefined || requestId == null) {
throw "Missing the required parameter 'requestId' when calling getRequestStatusForUser";
}
var pathParams = {
'requestId': requestId
};
var queryParams = {
};
var headerParams = {
};
var formParams = {
};
var authNames = ['artikcloud_oauth'];
var contentTypes = [];
var accepts = ['application/json'];
var returnType = DeviceRegStatusResponseEnvelope;
return this.apiClient.callApi(
'/devices/registrations/{requestId}/status', 'GET',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
}
/**
* Callback function to receive the result of the unregisterDevice operation.
* @callback module:api/RegistrationsApi~unregisterDeviceCallback
* @param {String} error Error message, if any.
* @param module:model/UnregisterDeviceResponseEnvelope data The data returned by the service call.
* @param {String} response The complete HTTP response.
*/
/**
* Unregister Device
* This call clears any associations from the secure device registration.
* @param String deviceId Device ID.
* @param {module:api/RegistrationsApi~unregisterDeviceCallback} callback The callback function, accepting three arguments: error, data, response
* data is of type: module:model/UnregisterDeviceResponseEnvelope
*/
this.unregisterDevice = function(deviceId, callback) {
var postBody = null;
// verify the required parameter 'deviceId' is set
if (deviceId == undefined || deviceId == null) {
throw "Missing the required parameter 'deviceId' when calling unregisterDevice";
}
var pathParams = {
'deviceId': deviceId
};
var queryParams = {
};
var headerParams = {
};
var formParams = {
};
var authNames = ['artikcloud_oauth'];
var contentTypes = [];
var accepts = ['application/json'];
var returnType = UnregisterDeviceResponseEnvelope;
return this.apiClient.callApi(
'/devices/{deviceId}/registrations', 'DELETE',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
}
} | [
"function",
"(",
"apiClient",
")",
"{",
"this",
".",
"apiClient",
"=",
"apiClient",
"||",
"ApiClient",
".",
"instance",
";",
"this",
".",
"confirmUser",
"=",
"function",
"(",
"registrationInfo",
",",
"callback",
")",
"{",
"var",
"postBody",
"=",
"registrationInfo",
";",
"if",
"(",
"registrationInfo",
"==",
"undefined",
"||",
"registrationInfo",
"==",
"null",
")",
"{",
"throw",
"\"Missing the required parameter 'registrationInfo' when calling confirmUser\"",
";",
"}",
"var",
"pathParams",
"=",
"{",
"}",
";",
"var",
"queryParams",
"=",
"{",
"}",
";",
"var",
"headerParams",
"=",
"{",
"}",
";",
"var",
"formParams",
"=",
"{",
"}",
";",
"var",
"authNames",
"=",
"[",
"'artikcloud_oauth'",
"]",
";",
"var",
"contentTypes",
"=",
"[",
"]",
";",
"var",
"accepts",
"=",
"[",
"'application/json'",
"]",
";",
"var",
"returnType",
"=",
"DeviceRegConfirmUserResponseEnvelope",
";",
"return",
"this",
".",
"apiClient",
".",
"callApi",
"(",
"'/devices/registrations/pin'",
",",
"'PUT'",
",",
"pathParams",
",",
"queryParams",
",",
"headerParams",
",",
"formParams",
",",
"postBody",
",",
"authNames",
",",
"contentTypes",
",",
"accepts",
",",
"returnType",
",",
"callback",
")",
";",
"}",
"this",
".",
"getRequestStatusForUser",
"=",
"function",
"(",
"requestId",
",",
"callback",
")",
"{",
"var",
"postBody",
"=",
"null",
";",
"if",
"(",
"requestId",
"==",
"undefined",
"||",
"requestId",
"==",
"null",
")",
"{",
"throw",
"\"Missing the required parameter 'requestId' when calling getRequestStatusForUser\"",
";",
"}",
"var",
"pathParams",
"=",
"{",
"'requestId'",
":",
"requestId",
"}",
";",
"var",
"queryParams",
"=",
"{",
"}",
";",
"var",
"headerParams",
"=",
"{",
"}",
";",
"var",
"formParams",
"=",
"{",
"}",
";",
"var",
"authNames",
"=",
"[",
"'artikcloud_oauth'",
"]",
";",
"var",
"contentTypes",
"=",
"[",
"]",
";",
"var",
"accepts",
"=",
"[",
"'application/json'",
"]",
";",
"var",
"returnType",
"=",
"DeviceRegStatusResponseEnvelope",
";",
"return",
"this",
".",
"apiClient",
".",
"callApi",
"(",
"'/devices/registrations/{requestId}/status'",
",",
"'GET'",
",",
"pathParams",
",",
"queryParams",
",",
"headerParams",
",",
"formParams",
",",
"postBody",
",",
"authNames",
",",
"contentTypes",
",",
"accepts",
",",
"returnType",
",",
"callback",
")",
";",
"}",
"this",
".",
"unregisterDevice",
"=",
"function",
"(",
"deviceId",
",",
"callback",
")",
"{",
"var",
"postBody",
"=",
"null",
";",
"if",
"(",
"deviceId",
"==",
"undefined",
"||",
"deviceId",
"==",
"null",
")",
"{",
"throw",
"\"Missing the required parameter 'deviceId' when calling unregisterDevice\"",
";",
"}",
"var",
"pathParams",
"=",
"{",
"'deviceId'",
":",
"deviceId",
"}",
";",
"var",
"queryParams",
"=",
"{",
"}",
";",
"var",
"headerParams",
"=",
"{",
"}",
";",
"var",
"formParams",
"=",
"{",
"}",
";",
"var",
"authNames",
"=",
"[",
"'artikcloud_oauth'",
"]",
";",
"var",
"contentTypes",
"=",
"[",
"]",
";",
"var",
"accepts",
"=",
"[",
"'application/json'",
"]",
";",
"var",
"returnType",
"=",
"UnregisterDeviceResponseEnvelope",
";",
"return",
"this",
".",
"apiClient",
".",
"callApi",
"(",
"'/devices/{deviceId}/registrations'",
",",
"'DELETE'",
",",
"pathParams",
",",
"queryParams",
",",
"headerParams",
",",
"formParams",
",",
"postBody",
",",
"authNames",
",",
"contentTypes",
",",
"accepts",
",",
"returnType",
",",
"callback",
")",
";",
"}",
"}"
] | Registrations service.
@module api/RegistrationsApi
@version 2.0.6
Constructs a new RegistrationsApi.
@alias module:api/RegistrationsApi
@class
@param {module:ApiClient} apiClient Optional API client implementation to use, default to {@link module:ApiClient#instance}
if unspecified. | [
"Registrations",
"service",
"."
] | 509fb7e6a42f09cec15a78b035372cb7353e250a | https://github.com/artikcloud/artikcloud-js/blob/509fb7e6a42f09cec15a78b035372cb7353e250a/src/api/RegistrationsApi.js#L31-L171 | train |
|
WorldMobileCoin/wmcc-core | src/utils/lock.js | Lock | function Lock(named) {
if (!(this instanceof Lock))
return Lock.create(named);
this.named = named === true;
this.jobs = [];
this.busy = false;
this.destroyed = false;
this.map = new Map();
this.current = null;
this.unlocker = this.unlock.bind(this);
} | javascript | function Lock(named) {
if (!(this instanceof Lock))
return Lock.create(named);
this.named = named === true;
this.jobs = [];
this.busy = false;
this.destroyed = false;
this.map = new Map();
this.current = null;
this.unlocker = this.unlock.bind(this);
} | [
"function",
"Lock",
"(",
"named",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Lock",
")",
")",
"return",
"Lock",
".",
"create",
"(",
"named",
")",
";",
"this",
".",
"named",
"=",
"named",
"===",
"true",
";",
"this",
".",
"jobs",
"=",
"[",
"]",
";",
"this",
".",
"busy",
"=",
"false",
";",
"this",
".",
"destroyed",
"=",
"false",
";",
"this",
".",
"map",
"=",
"new",
"Map",
"(",
")",
";",
"this",
".",
"current",
"=",
"null",
";",
"this",
".",
"unlocker",
"=",
"this",
".",
"unlock",
".",
"bind",
"(",
"this",
")",
";",
"}"
] | Represents a mutex lock for locking asynchronous object methods.
@alias module:utils.Lock
@constructor
@param {Boolean?} named - Whether to
maintain a map of queued jobs by job name. | [
"Represents",
"a",
"mutex",
"lock",
"for",
"locking",
"asynchronous",
"object",
"methods",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/utils/lock.js#L24-L38 | train |
WorldMobileCoin/wmcc-core | src/crypto/scrypt.js | derive | function derive(passwd, salt, N, r, p, len) {
if (r * p >= (1 << 30))
throw new Error('EFBIG');
if ((N & (N - 1)) !== 0 || N === 0)
throw new Error('EINVAL');
if (N > 0xffffffff)
throw new Error('EINVAL');
const XY = Buffer.allocUnsafe(256 * r);
const V = Buffer.allocUnsafe(128 * r * N);
const B = pbkdf2.derive(passwd, salt, 1, p * 128 * r, 'sha256');
for (let i = 0; i < p; i++)
smix(B, i * 128 * r, r, N, V, XY);
return pbkdf2.derive(passwd, B, 1, len, 'sha256');
} | javascript | function derive(passwd, salt, N, r, p, len) {
if (r * p >= (1 << 30))
throw new Error('EFBIG');
if ((N & (N - 1)) !== 0 || N === 0)
throw new Error('EINVAL');
if (N > 0xffffffff)
throw new Error('EINVAL');
const XY = Buffer.allocUnsafe(256 * r);
const V = Buffer.allocUnsafe(128 * r * N);
const B = pbkdf2.derive(passwd, salt, 1, p * 128 * r, 'sha256');
for (let i = 0; i < p; i++)
smix(B, i * 128 * r, r, N, V, XY);
return pbkdf2.derive(passwd, B, 1, len, 'sha256');
} | [
"function",
"derive",
"(",
"passwd",
",",
"salt",
",",
"N",
",",
"r",
",",
"p",
",",
"len",
")",
"{",
"if",
"(",
"r",
"*",
"p",
">=",
"(",
"1",
"<<",
"30",
")",
")",
"throw",
"new",
"Error",
"(",
"'EFBIG'",
")",
";",
"if",
"(",
"(",
"N",
"&",
"(",
"N",
"-",
"1",
")",
")",
"!==",
"0",
"||",
"N",
"===",
"0",
")",
"throw",
"new",
"Error",
"(",
"'EINVAL'",
")",
";",
"if",
"(",
"N",
">",
"0xffffffff",
")",
"throw",
"new",
"Error",
"(",
"'EINVAL'",
")",
";",
"const",
"XY",
"=",
"Buffer",
".",
"allocUnsafe",
"(",
"256",
"*",
"r",
")",
";",
"const",
"V",
"=",
"Buffer",
".",
"allocUnsafe",
"(",
"128",
"*",
"r",
"*",
"N",
")",
";",
"const",
"B",
"=",
"pbkdf2",
".",
"derive",
"(",
"passwd",
",",
"salt",
",",
"1",
",",
"p",
"*",
"128",
"*",
"r",
",",
"'sha256'",
")",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"p",
";",
"i",
"++",
")",
"smix",
"(",
"B",
",",
"i",
"*",
"128",
"*",
"r",
",",
"r",
",",
"N",
",",
"V",
",",
"XY",
")",
";",
"return",
"pbkdf2",
".",
"derive",
"(",
"passwd",
",",
"B",
",",
"1",
",",
"len",
",",
"'sha256'",
")",
";",
"}"
] | Javascript scrypt implementation. Scrypt is
used in bip38. WMCC_Core doesn't support bip38
yet, but here it is, just in case.
@alias module:crypto/scrypt.derive
@param {Buffer} passwd
@param {Buffer} salt
@param {Number} N
@param {Number} r
@param {Number} p
@param {Number} len
@returns {Buffer} | [
"Javascript",
"scrypt",
"implementation",
".",
"Scrypt",
"is",
"used",
"in",
"bip38",
".",
"WMCC_Core",
"doesn",
"t",
"support",
"bip38",
"yet",
"but",
"here",
"it",
"is",
"just",
"in",
"case",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/crypto/scrypt.js#L64-L83 | train |
WorldMobileCoin/wmcc-core | src/crypto/scrypt.js | deriveAsync | async function deriveAsync(passwd, salt, N, r, p, len) {
if (r * p >= (1 << 30))
throw new Error('EFBIG');
if ((N & (N - 1)) !== 0 || N === 0)
throw new Error('EINVAL');
if (N > 0xffffffff)
throw new Error('EINVAL');
const XY = Buffer.allocUnsafe(256 * r);
const V = Buffer.allocUnsafe(128 * r * N);
const B = await pbkdf2.deriveAsync(passwd, salt, 1, p * 128 * r, 'sha256');
for (let i = 0; i < p; i++)
await smixAsync(B, i * 128 * r, r, N, V, XY);
return await pbkdf2.deriveAsync(passwd, B, 1, len, 'sha256');
} | javascript | async function deriveAsync(passwd, salt, N, r, p, len) {
if (r * p >= (1 << 30))
throw new Error('EFBIG');
if ((N & (N - 1)) !== 0 || N === 0)
throw new Error('EINVAL');
if (N > 0xffffffff)
throw new Error('EINVAL');
const XY = Buffer.allocUnsafe(256 * r);
const V = Buffer.allocUnsafe(128 * r * N);
const B = await pbkdf2.deriveAsync(passwd, salt, 1, p * 128 * r, 'sha256');
for (let i = 0; i < p; i++)
await smixAsync(B, i * 128 * r, r, N, V, XY);
return await pbkdf2.deriveAsync(passwd, B, 1, len, 'sha256');
} | [
"async",
"function",
"deriveAsync",
"(",
"passwd",
",",
"salt",
",",
"N",
",",
"r",
",",
"p",
",",
"len",
")",
"{",
"if",
"(",
"r",
"*",
"p",
">=",
"(",
"1",
"<<",
"30",
")",
")",
"throw",
"new",
"Error",
"(",
"'EFBIG'",
")",
";",
"if",
"(",
"(",
"N",
"&",
"(",
"N",
"-",
"1",
")",
")",
"!==",
"0",
"||",
"N",
"===",
"0",
")",
"throw",
"new",
"Error",
"(",
"'EINVAL'",
")",
";",
"if",
"(",
"N",
">",
"0xffffffff",
")",
"throw",
"new",
"Error",
"(",
"'EINVAL'",
")",
";",
"const",
"XY",
"=",
"Buffer",
".",
"allocUnsafe",
"(",
"256",
"*",
"r",
")",
";",
"const",
"V",
"=",
"Buffer",
".",
"allocUnsafe",
"(",
"128",
"*",
"r",
"*",
"N",
")",
";",
"const",
"B",
"=",
"await",
"pbkdf2",
".",
"deriveAsync",
"(",
"passwd",
",",
"salt",
",",
"1",
",",
"p",
"*",
"128",
"*",
"r",
",",
"'sha256'",
")",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"p",
";",
"i",
"++",
")",
"await",
"smixAsync",
"(",
"B",
",",
"i",
"*",
"128",
"*",
"r",
",",
"r",
",",
"N",
",",
"V",
",",
"XY",
")",
";",
"return",
"await",
"pbkdf2",
".",
"deriveAsync",
"(",
"passwd",
",",
"B",
",",
"1",
",",
"len",
",",
"'sha256'",
")",
";",
"}"
] | Asynchronous scrypt implementation.
@alias module:crypto/scrypt.deriveAsync
@function
@param {Buffer} passwd
@param {Buffer} salt
@param {Number} N
@param {Number} r
@param {Number} p
@param {Number} len
@returns {Promise} | [
"Asynchronous",
"scrypt",
"implementation",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/crypto/scrypt.js#L101-L120 | train |
goblindegook/gulp-font2css | src/index.js | guessFontStyle | function guessFontStyle(basename) {
return basename
.split('-')
.slice(1)
.map(item => item.toLowerCase())
.reduce((prev, item) => {
if (fontStyleKeywords.indexOf(item) >= 0) {
return `font-style:${item};`
}
return prev
}, '')
} | javascript | function guessFontStyle(basename) {
return basename
.split('-')
.slice(1)
.map(item => item.toLowerCase())
.reduce((prev, item) => {
if (fontStyleKeywords.indexOf(item) >= 0) {
return `font-style:${item};`
}
return prev
}, '')
} | [
"function",
"guessFontStyle",
"(",
"basename",
")",
"{",
"return",
"basename",
".",
"split",
"(",
"'-'",
")",
".",
"slice",
"(",
"1",
")",
".",
"map",
"(",
"item",
"=>",
"item",
".",
"toLowerCase",
"(",
")",
")",
".",
"reduce",
"(",
"(",
"prev",
",",
"item",
")",
"=>",
"{",
"if",
"(",
"fontStyleKeywords",
".",
"indexOf",
"(",
"item",
")",
">=",
"0",
")",
"{",
"return",
"`",
"${",
"item",
"}",
"`",
"}",
"return",
"prev",
"}",
",",
"''",
")",
"}"
] | Guess the `font-style` property from the font file name.
@param {String} basename Font base filename.
@return {String} `font-style` property and guessed value. | [
"Guess",
"the",
"font",
"-",
"style",
"property",
"from",
"the",
"font",
"file",
"name",
"."
] | 59ab77074a5d9b6f5b8b18ce2259e6ce4e12ef29 | https://github.com/goblindegook/gulp-font2css/blob/59ab77074a5d9b6f5b8b18ce2259e6ce4e12ef29/src/index.js#L25-L37 | train |
goblindegook/gulp-font2css | src/index.js | guessFontWeight | function guessFontWeight(basename) {
return basename
.split('-')
.slice(1)
.map(item => item.toLowerCase())
.reduce((prev, item) => {
if (item === 'normal') {
return prev
}
if (fontWeightNames[item]) {
return `font-weight:${fontWeightNames[item]};`
}
if (fontWeightKeywords.indexOf(item) >= 0) {
return `font-weight:${item};`
}
return prev
}, '')
} | javascript | function guessFontWeight(basename) {
return basename
.split('-')
.slice(1)
.map(item => item.toLowerCase())
.reduce((prev, item) => {
if (item === 'normal') {
return prev
}
if (fontWeightNames[item]) {
return `font-weight:${fontWeightNames[item]};`
}
if (fontWeightKeywords.indexOf(item) >= 0) {
return `font-weight:${item};`
}
return prev
}, '')
} | [
"function",
"guessFontWeight",
"(",
"basename",
")",
"{",
"return",
"basename",
".",
"split",
"(",
"'-'",
")",
".",
"slice",
"(",
"1",
")",
".",
"map",
"(",
"item",
"=>",
"item",
".",
"toLowerCase",
"(",
")",
")",
".",
"reduce",
"(",
"(",
"prev",
",",
"item",
")",
"=>",
"{",
"if",
"(",
"item",
"===",
"'normal'",
")",
"{",
"return",
"prev",
"}",
"if",
"(",
"fontWeightNames",
"[",
"item",
"]",
")",
"{",
"return",
"`",
"${",
"fontWeightNames",
"[",
"item",
"]",
"}",
"`",
"}",
"if",
"(",
"fontWeightKeywords",
".",
"indexOf",
"(",
"item",
")",
">=",
"0",
")",
"{",
"return",
"`",
"${",
"item",
"}",
"`",
"}",
"return",
"prev",
"}",
",",
"''",
")",
"}"
] | Guess the `font-weight` property from the font file name.
@param {String} basename Font base filename.
@return {String} `font-weight` property and guessed value. | [
"Guess",
"the",
"font",
"-",
"weight",
"property",
"from",
"the",
"font",
"file",
"name",
"."
] | 59ab77074a5d9b6f5b8b18ce2259e6ce4e12ef29 | https://github.com/goblindegook/gulp-font2css/blob/59ab77074a5d9b6f5b8b18ce2259e6ce4e12ef29/src/index.js#L44-L64 | train |
WorldMobileCoin/wmcc-core | src/mempool/mempool.js | Mempool | function Mempool(options) {
if (!(this instanceof Mempool))
return new Mempool(options);
AsyncObject.call(this);
this.options = new MempoolOptions(options);
this.network = this.options.network;
this.logger = this.options.logger.context('mempool');
this.workers = this.options.workers;
this.chain = this.options.chain;
this.fees = this.options.fees;
this.locker = this.chain.locker;
this.cache = new MempoolCache(this.options);
this.size = 0;
this.freeCount = 0;
this.lastTime = 0;
this.lastFlush = 0;
this.tip = this.network.genesis.hash;
this.waiting = new Map();
this.orphans = new Map();
this.map = new Map();
this.spents = new Map();
this.rejects = new RollingFilter(120000, 0.000001);
this.coinIndex = new CoinIndex();
this.txIndex = new TXIndex();
} | javascript | function Mempool(options) {
if (!(this instanceof Mempool))
return new Mempool(options);
AsyncObject.call(this);
this.options = new MempoolOptions(options);
this.network = this.options.network;
this.logger = this.options.logger.context('mempool');
this.workers = this.options.workers;
this.chain = this.options.chain;
this.fees = this.options.fees;
this.locker = this.chain.locker;
this.cache = new MempoolCache(this.options);
this.size = 0;
this.freeCount = 0;
this.lastTime = 0;
this.lastFlush = 0;
this.tip = this.network.genesis.hash;
this.waiting = new Map();
this.orphans = new Map();
this.map = new Map();
this.spents = new Map();
this.rejects = new RollingFilter(120000, 0.000001);
this.coinIndex = new CoinIndex();
this.txIndex = new TXIndex();
} | [
"function",
"Mempool",
"(",
"options",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Mempool",
")",
")",
"return",
"new",
"Mempool",
"(",
"options",
")",
";",
"AsyncObject",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"options",
"=",
"new",
"MempoolOptions",
"(",
"options",
")",
";",
"this",
".",
"network",
"=",
"this",
".",
"options",
".",
"network",
";",
"this",
".",
"logger",
"=",
"this",
".",
"options",
".",
"logger",
".",
"context",
"(",
"'mempool'",
")",
";",
"this",
".",
"workers",
"=",
"this",
".",
"options",
".",
"workers",
";",
"this",
".",
"chain",
"=",
"this",
".",
"options",
".",
"chain",
";",
"this",
".",
"fees",
"=",
"this",
".",
"options",
".",
"fees",
";",
"this",
".",
"locker",
"=",
"this",
".",
"chain",
".",
"locker",
";",
"this",
".",
"cache",
"=",
"new",
"MempoolCache",
"(",
"this",
".",
"options",
")",
";",
"this",
".",
"size",
"=",
"0",
";",
"this",
".",
"freeCount",
"=",
"0",
";",
"this",
".",
"lastTime",
"=",
"0",
";",
"this",
".",
"lastFlush",
"=",
"0",
";",
"this",
".",
"tip",
"=",
"this",
".",
"network",
".",
"genesis",
".",
"hash",
";",
"this",
".",
"waiting",
"=",
"new",
"Map",
"(",
")",
";",
"this",
".",
"orphans",
"=",
"new",
"Map",
"(",
")",
";",
"this",
".",
"map",
"=",
"new",
"Map",
"(",
")",
";",
"this",
".",
"spents",
"=",
"new",
"Map",
"(",
")",
";",
"this",
".",
"rejects",
"=",
"new",
"RollingFilter",
"(",
"120000",
",",
"0.000001",
")",
";",
"this",
".",
"coinIndex",
"=",
"new",
"CoinIndex",
"(",
")",
";",
"this",
".",
"txIndex",
"=",
"new",
"TXIndex",
"(",
")",
";",
"}"
] | Represents a mempool.
@alias module:mempool.Mempool
@constructor
@param {Object} options
@param {String?} options.name - Database name.
@param {String?} options.location - Database file location.
@param {String?} options.db - Database backend (`"memory"` by default).
@param {Boolean?} options.limitFree
@param {Number?} options.limitFreeRelay
@param {Number?} options.maxSize - Max pool size (default ~300mb).
@param {Boolean?} options.relayPriority
@param {Boolean?} options.requireStandard
@param {Boolean?} options.rejectAbsurdFees
@param {Boolean?} options.relay
@property {Boolean} loaded
@property {Object} db
@property {Number} size
@property {Lock} locker
@property {Number} freeCount
@property {Number} lastTime
@property {Number} maxSize
@property {Rate} minRelayFee
@emits Mempool#open
@emits Mempool#error
@emits Mempool#tx
@emits Mempool#add tx
@emits Mempool#remove tx | [
"Represents",
"a",
"mempool",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/mempool/mempool.js#L69-L101 | train |
WorldMobileCoin/wmcc-core | src/primitives/outpoint.js | Outpoint | function Outpoint(hash, index) {
if (!(this instanceof Outpoint))
return new Outpoint(hash, index);
this.hash = encoding.NULL_HASH;
this.index = 0xffffffff;
if (hash != null) {
assert(typeof hash === 'string', 'Hash must be a string.');
assert(util.isU32(index), 'Index must be a uint32.');
this.hash = hash;
this.index = index;
}
} | javascript | function Outpoint(hash, index) {
if (!(this instanceof Outpoint))
return new Outpoint(hash, index);
this.hash = encoding.NULL_HASH;
this.index = 0xffffffff;
if (hash != null) {
assert(typeof hash === 'string', 'Hash must be a string.');
assert(util.isU32(index), 'Index must be a uint32.');
this.hash = hash;
this.index = index;
}
} | [
"function",
"Outpoint",
"(",
"hash",
",",
"index",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Outpoint",
")",
")",
"return",
"new",
"Outpoint",
"(",
"hash",
",",
"index",
")",
";",
"this",
".",
"hash",
"=",
"encoding",
".",
"NULL_HASH",
";",
"this",
".",
"index",
"=",
"0xffffffff",
";",
"if",
"(",
"hash",
"!=",
"null",
")",
"{",
"assert",
"(",
"typeof",
"hash",
"===",
"'string'",
",",
"'Hash must be a string.'",
")",
";",
"assert",
"(",
"util",
".",
"isU32",
"(",
"index",
")",
",",
"'Index must be a uint32.'",
")",
";",
"this",
".",
"hash",
"=",
"hash",
";",
"this",
".",
"index",
"=",
"index",
";",
"}",
"}"
] | Represents a COutPoint.
@alias module:primitives.Outpoint
@constructor
@param {Hash?} hash
@param {Number?} index
@property {Hash} hash
@property {Number} index | [
"Represents",
"a",
"COutPoint",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/primitives/outpoint.js#L29-L42 | train |
ucd-cws/calvin-network-tools | nodejs/cmds/build.js | addBoundsToArray | function addBoundsToArray(bounds, array) {
if( !bounds ) return;
var bound;
for( var j = 0; j < bounds.length; j++ ) {
bound = bounds[j];
if( bound.type === 'UBM' || bound.type === 'LBM' ) {
array.push(bound);
}
}
} | javascript | function addBoundsToArray(bounds, array) {
if( !bounds ) return;
var bound;
for( var j = 0; j < bounds.length; j++ ) {
bound = bounds[j];
if( bound.type === 'UBM' || bound.type === 'LBM' ) {
array.push(bound);
}
}
} | [
"function",
"addBoundsToArray",
"(",
"bounds",
",",
"array",
")",
"{",
"if",
"(",
"!",
"bounds",
")",
"return",
";",
"var",
"bound",
";",
"for",
"(",
"var",
"j",
"=",
"0",
";",
"j",
"<",
"bounds",
".",
"length",
";",
"j",
"++",
")",
"{",
"bound",
"=",
"bounds",
"[",
"j",
"]",
";",
"if",
"(",
"bound",
".",
"type",
"===",
"'UBM'",
"||",
"bound",
".",
"type",
"===",
"'LBM'",
")",
"{",
"array",
".",
"push",
"(",
"bound",
")",
";",
"}",
"}",
"}"
] | helper for readUBMandLBM | [
"helper",
"for",
"readUBMandLBM"
] | 9c276972394878dfb6927b56303fca4c4a2bf8f5 | https://github.com/ucd-cws/calvin-network-tools/blob/9c276972394878dfb6927b56303fca4c4a2bf8f5/nodejs/cmds/build.js#L127-L137 | train |
WorldMobileCoin/wmcc-core | src/utils/ip.js | Address | function Address(host, port, type, hostname, raw) {
this.host = host || '0.0.0.0';
this.port = port || 0;
this.type = type || IP.types.IPV4;
this.hostname = hostname || '0.0.0.0:0';
this.raw = raw || ZERO_IP;
} | javascript | function Address(host, port, type, hostname, raw) {
this.host = host || '0.0.0.0';
this.port = port || 0;
this.type = type || IP.types.IPV4;
this.hostname = hostname || '0.0.0.0:0';
this.raw = raw || ZERO_IP;
} | [
"function",
"Address",
"(",
"host",
",",
"port",
",",
"type",
",",
"hostname",
",",
"raw",
")",
"{",
"this",
".",
"host",
"=",
"host",
"||",
"'0.0.0.0'",
";",
"this",
".",
"port",
"=",
"port",
"||",
"0",
";",
"this",
".",
"type",
"=",
"type",
"||",
"IP",
".",
"types",
".",
"IPV4",
";",
"this",
".",
"hostname",
"=",
"hostname",
"||",
"'0.0.0.0:0'",
";",
"this",
".",
"raw",
"=",
"raw",
"||",
"ZERO_IP",
";",
"}"
] | Represents a parsed address.
@constructor
@alias module:utils/ip.Address
@param {String} host
@param {Number} port
@param {Number} type
@param {String} hostname
@param {Buffer|null} raw
@property {String} host
@property {Number} port
@property {Number} type
@property {String} hostname
@property {Buffer} raw | [
"Represents",
"a",
"parsed",
"address",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/utils/ip.js#L1059-L1065 | train |
WorldMobileCoin/wmcc-core | src/utils/staticwriter.js | StaticWriter | function StaticWriter(size) {
if (!(this instanceof StaticWriter))
return new StaticWriter(size);
this.data = size ? Buffer.allocUnsafe(size) : EMPTY;
this.offset = 0;
} | javascript | function StaticWriter(size) {
if (!(this instanceof StaticWriter))
return new StaticWriter(size);
this.data = size ? Buffer.allocUnsafe(size) : EMPTY;
this.offset = 0;
} | [
"function",
"StaticWriter",
"(",
"size",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"StaticWriter",
")",
")",
"return",
"new",
"StaticWriter",
"(",
"size",
")",
";",
"this",
".",
"data",
"=",
"size",
"?",
"Buffer",
".",
"allocUnsafe",
"(",
"size",
")",
":",
"EMPTY",
";",
"this",
".",
"offset",
"=",
"0",
";",
"}"
] | Statically allocated buffer writer.
@alias module:utils.StaticWriter
@constructor
@param {Number} size | [
"Statically",
"allocated",
"buffer",
"writer",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/utils/staticwriter.js#L29-L35 | train |
jedmao/blink | js/lib/helpers/string.js | camelize | function camelize(s) {
return s.replace(STRING_CAMELIZE, function (match, separator, chr) {
return chr.toUpperCase();
}).replace(/^([A-Z])/, function (match) {
return match.toLowerCase();
});
} | javascript | function camelize(s) {
return s.replace(STRING_CAMELIZE, function (match, separator, chr) {
return chr.toUpperCase();
}).replace(/^([A-Z])/, function (match) {
return match.toLowerCase();
});
} | [
"function",
"camelize",
"(",
"s",
")",
"{",
"return",
"s",
".",
"replace",
"(",
"STRING_CAMELIZE",
",",
"function",
"(",
"match",
",",
"separator",
",",
"chr",
")",
"{",
"return",
"chr",
".",
"toUpperCase",
"(",
")",
";",
"}",
")",
".",
"replace",
"(",
"/",
"^([A-Z])",
"/",
",",
"function",
"(",
"match",
")",
"{",
"return",
"match",
".",
"toLowerCase",
"(",
")",
";",
"}",
")",
";",
"}"
] | Returns the LowerCamelCase form of a string. | [
"Returns",
"the",
"LowerCamelCase",
"form",
"of",
"a",
"string",
"."
] | f80fb591d33ee0cf063b6d6afae897e69ffcf407 | https://github.com/jedmao/blink/blob/f80fb591d33ee0cf063b6d6afae897e69ffcf407/js/lib/helpers/string.js#L14-L20 | train |
chjj/node-telnet2 | repl.js | setRawMode | function setRawMode (mode) {
if (mode) {
this.do.suppress_go_ahead()
this.will.suppress_go_ahead()
this.will.echo()
} else {
this.dont.suppress_go_ahead()
this.wont.suppress_go_ahead()
this.wont.echo()
}
} | javascript | function setRawMode (mode) {
if (mode) {
this.do.suppress_go_ahead()
this.will.suppress_go_ahead()
this.will.echo()
} else {
this.dont.suppress_go_ahead()
this.wont.suppress_go_ahead()
this.wont.echo()
}
} | [
"function",
"setRawMode",
"(",
"mode",
")",
"{",
"if",
"(",
"mode",
")",
"{",
"this",
".",
"do",
".",
"suppress_go_ahead",
"(",
")",
"this",
".",
"will",
".",
"suppress_go_ahead",
"(",
")",
"this",
".",
"will",
".",
"echo",
"(",
")",
"}",
"else",
"{",
"this",
".",
"dont",
".",
"suppress_go_ahead",
"(",
")",
"this",
".",
"wont",
".",
"suppress_go_ahead",
"(",
")",
"this",
".",
"wont",
".",
"echo",
"(",
")",
"}",
"}"
] | The equivalent of "raw mode" via telnet option commands.
Set this function on a telnet `client` instance. | [
"The",
"equivalent",
"of",
"raw",
"mode",
"via",
"telnet",
"option",
"commands",
".",
"Set",
"this",
"function",
"on",
"a",
"telnet",
"client",
"instance",
"."
] | 62b15d1ecd37f339b49e81d414acf43155b3b1da | https://github.com/chjj/node-telnet2/blob/62b15d1ecd37f339b49e81d414acf43155b3b1da/repl.js#L79-L89 | train |
bigpipe/bigpipe.js | collection.js | each | function each(collection, iterator, context) {
var i = 0;
if ('array' === type(collection)) {
for (; i < collection.length; i++) {
if (false === iterator.call(context || iterator, collection[i], i, collection)) {
return; // If false is returned by the callback we need to bail out.
}
}
} else {
for (i in collection) {
if (hasOwn.call(collection, i)) {
if (false === iterator.call(context || iterator, collection[i], i, collection)) {
return; // If false is returned by the callback we need to bail out.
}
}
}
}
} | javascript | function each(collection, iterator, context) {
var i = 0;
if ('array' === type(collection)) {
for (; i < collection.length; i++) {
if (false === iterator.call(context || iterator, collection[i], i, collection)) {
return; // If false is returned by the callback we need to bail out.
}
}
} else {
for (i in collection) {
if (hasOwn.call(collection, i)) {
if (false === iterator.call(context || iterator, collection[i], i, collection)) {
return; // If false is returned by the callback we need to bail out.
}
}
}
}
} | [
"function",
"each",
"(",
"collection",
",",
"iterator",
",",
"context",
")",
"{",
"var",
"i",
"=",
"0",
";",
"if",
"(",
"'array'",
"===",
"type",
"(",
"collection",
")",
")",
"{",
"for",
"(",
";",
"i",
"<",
"collection",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"false",
"===",
"iterator",
".",
"call",
"(",
"context",
"||",
"iterator",
",",
"collection",
"[",
"i",
"]",
",",
"i",
",",
"collection",
")",
")",
"{",
"return",
";",
"}",
"}",
"}",
"else",
"{",
"for",
"(",
"i",
"in",
"collection",
")",
"{",
"if",
"(",
"hasOwn",
".",
"call",
"(",
"collection",
",",
"i",
")",
")",
"{",
"if",
"(",
"false",
"===",
"iterator",
".",
"call",
"(",
"context",
"||",
"iterator",
",",
"collection",
"[",
"i",
"]",
",",
"i",
",",
"collection",
")",
")",
"{",
"return",
";",
"}",
"}",
"}",
"}",
"}"
] | Iterate over a collection.
@param {Mixed} collection The object we want to iterate over.
@param {Function} iterator The function that's called for each iteration.
@param {Mixed} context The context of the function.
@api public | [
"Iterate",
"over",
"a",
"collection",
"."
] | 80fe2630d363ed2b69f85d28792a9095a4167e3b | https://github.com/bigpipe/bigpipe.js/blob/80fe2630d363ed2b69f85d28792a9095a4167e3b/collection.js#L25-L43 | train |
bigpipe/bigpipe.js | collection.js | size | function size(collection) {
var x, i = 0;
if ('object' === type(collection)) {
for (x in collection) i++;
return i;
}
return +collection.length;
} | javascript | function size(collection) {
var x, i = 0;
if ('object' === type(collection)) {
for (x in collection) i++;
return i;
}
return +collection.length;
} | [
"function",
"size",
"(",
"collection",
")",
"{",
"var",
"x",
",",
"i",
"=",
"0",
";",
"if",
"(",
"'object'",
"===",
"type",
"(",
"collection",
")",
")",
"{",
"for",
"(",
"x",
"in",
"collection",
")",
"i",
"++",
";",
"return",
"i",
";",
"}",
"return",
"+",
"collection",
".",
"length",
";",
"}"
] | Determine the size of a collection.
@param {Mixed} collection The object we want to know the size of.
@returns {Number} The size of the collection.
@api public | [
"Determine",
"the",
"size",
"of",
"a",
"collection",
"."
] | 80fe2630d363ed2b69f85d28792a9095a4167e3b | https://github.com/bigpipe/bigpipe.js/blob/80fe2630d363ed2b69f85d28792a9095a4167e3b/collection.js#L67-L76 | train |
bigpipe/bigpipe.js | collection.js | array | function array(obj) {
if ('array' === type(obj)) return obj;
if ('arguments' === type(obj)) return Array.prototype.slice.call(obj, 0);
return obj // Only transform objects in to an array when they exist.
? [obj]
: [];
} | javascript | function array(obj) {
if ('array' === type(obj)) return obj;
if ('arguments' === type(obj)) return Array.prototype.slice.call(obj, 0);
return obj // Only transform objects in to an array when they exist.
? [obj]
: [];
} | [
"function",
"array",
"(",
"obj",
")",
"{",
"if",
"(",
"'array'",
"===",
"type",
"(",
"obj",
")",
")",
"return",
"obj",
";",
"if",
"(",
"'arguments'",
"===",
"type",
"(",
"obj",
")",
")",
"return",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"obj",
",",
"0",
")",
";",
"return",
"obj",
"?",
"[",
"obj",
"]",
":",
"[",
"]",
";",
"}"
] | Wrap the given object in an array if it's not an array already.
@param {Mixed} obj The thing we might need to wrap.
@returns {Array} We promise!
@api public | [
"Wrap",
"the",
"given",
"object",
"in",
"an",
"array",
"if",
"it",
"s",
"not",
"an",
"array",
"already",
"."
] | 80fe2630d363ed2b69f85d28792a9095a4167e3b | https://github.com/bigpipe/bigpipe.js/blob/80fe2630d363ed2b69f85d28792a9095a4167e3b/collection.js#L85-L92 | train |
bigpipe/bigpipe.js | collection.js | copy | function copy() {
var result = {}
, depth = 2
, seen = [];
(function worker() {
each(array(arguments), function each(obj) {
for (var prop in obj) {
if (hasOwn.call(obj, prop) && !~index(seen, obj[prop])) {
if (type(obj[prop]) !== 'object' || !depth) {
result[prop] = obj[prop];
seen.push(obj[prop]);
} else {
depth--;
worker(result[prop], obj[prop]);
}
}
}
});
}).apply(null, arguments);
return result;
} | javascript | function copy() {
var result = {}
, depth = 2
, seen = [];
(function worker() {
each(array(arguments), function each(obj) {
for (var prop in obj) {
if (hasOwn.call(obj, prop) && !~index(seen, obj[prop])) {
if (type(obj[prop]) !== 'object' || !depth) {
result[prop] = obj[prop];
seen.push(obj[prop]);
} else {
depth--;
worker(result[prop], obj[prop]);
}
}
}
});
}).apply(null, arguments);
return result;
} | [
"function",
"copy",
"(",
")",
"{",
"var",
"result",
"=",
"{",
"}",
",",
"depth",
"=",
"2",
",",
"seen",
"=",
"[",
"]",
";",
"(",
"function",
"worker",
"(",
")",
"{",
"each",
"(",
"array",
"(",
"arguments",
")",
",",
"function",
"each",
"(",
"obj",
")",
"{",
"for",
"(",
"var",
"prop",
"in",
"obj",
")",
"{",
"if",
"(",
"hasOwn",
".",
"call",
"(",
"obj",
",",
"prop",
")",
"&&",
"!",
"~",
"index",
"(",
"seen",
",",
"obj",
"[",
"prop",
"]",
")",
")",
"{",
"if",
"(",
"type",
"(",
"obj",
"[",
"prop",
"]",
")",
"!==",
"'object'",
"||",
"!",
"depth",
")",
"{",
"result",
"[",
"prop",
"]",
"=",
"obj",
"[",
"prop",
"]",
";",
"seen",
".",
"push",
"(",
"obj",
"[",
"prop",
"]",
")",
";",
"}",
"else",
"{",
"depth",
"--",
";",
"worker",
"(",
"result",
"[",
"prop",
"]",
",",
"obj",
"[",
"prop",
"]",
")",
";",
"}",
"}",
"}",
"}",
")",
";",
"}",
")",
".",
"apply",
"(",
"null",
",",
"arguments",
")",
";",
"return",
"result",
";",
"}"
] | Merge all given objects in to one objects.
@returns {Object}
@api public | [
"Merge",
"all",
"given",
"objects",
"in",
"to",
"one",
"objects",
"."
] | 80fe2630d363ed2b69f85d28792a9095a4167e3b | https://github.com/bigpipe/bigpipe.js/blob/80fe2630d363ed2b69f85d28792a9095a4167e3b/collection.js#L122-L144 | train |
Karnith/machinepack-sailsgulpify | machines/sails-gulpify.js | function (userInput){
var firstTimeRun = userInput.toLowerCase();
if(firstTimeRun === 'yes'){
createGulpFile({
gulpFileSrcPath: '../templates/gulpfile.js',
outputDir: '../../../gulpfile.js'
}).exec({
error: function (err){
console.error('an error occurred- error details:',err);
return exits.error();
},
invalid: function (){ exits.invalid() },
success: function() {
createGulpTasks({
gulpFolderSrcPath: '../templates/tasks-gulp',
outputFolderDir: '../../../tasks-gulp'
}).exec({
error: function (err){
console.error('an error occurred- error details:',err);
return exits.error();
},
invalid: function (){ exits.invalid() },
success: function() {
createGulpEngine({
gulpFolderSrcPath: '../lib/gulp',
outputDir: '../../sails/lib/hooks/gulp'
//outputDir: '../../../api/hooks/gulp'
}).exec({
error: function (err){
console.error('an error occurred- error details:',err);
return exits.error();
},
invalid: function (){ exits.invalid() },
success: function() {
// return exits.success();
toggleSailsrc({
sailsrcSrc: '../json/gulp.sailsrc',
outputDir: '../../../.sailsrc'
}).exec({
error: function (err){
console.error('an error occurred- error details:',err);
return exits.error();
},
invalid: function (){ exits.invalid() },
success: function() {
// return exits.success();
installGulpDependencies({
}).exec({
error: function (err){
console.error('an error occurred- error details:',err);
return exits.error();
},
invalid: function (){ exits.invalid() },
success: function() {
return exits.success();
}
});
}
});
}
});
}
});
}
});
}
else if(firstTimeRun === 'no') {
createGulpEngine({
gulpFolderSrcPath: '../lib/gulp',
outputDir: '../../sails/lib/hooks/gulp'
//outputDir: '../../../api/hooks/gulp'
}).exec({
error: function (err){
console.error('an error occurred- error details:',err);
return exits.error();
},
invalid: function (){ exits.invalid() },
success: function() {
return exits.success();
}
});
}
} | javascript | function (userInput){
var firstTimeRun = userInput.toLowerCase();
if(firstTimeRun === 'yes'){
createGulpFile({
gulpFileSrcPath: '../templates/gulpfile.js',
outputDir: '../../../gulpfile.js'
}).exec({
error: function (err){
console.error('an error occurred- error details:',err);
return exits.error();
},
invalid: function (){ exits.invalid() },
success: function() {
createGulpTasks({
gulpFolderSrcPath: '../templates/tasks-gulp',
outputFolderDir: '../../../tasks-gulp'
}).exec({
error: function (err){
console.error('an error occurred- error details:',err);
return exits.error();
},
invalid: function (){ exits.invalid() },
success: function() {
createGulpEngine({
gulpFolderSrcPath: '../lib/gulp',
outputDir: '../../sails/lib/hooks/gulp'
//outputDir: '../../../api/hooks/gulp'
}).exec({
error: function (err){
console.error('an error occurred- error details:',err);
return exits.error();
},
invalid: function (){ exits.invalid() },
success: function() {
// return exits.success();
toggleSailsrc({
sailsrcSrc: '../json/gulp.sailsrc',
outputDir: '../../../.sailsrc'
}).exec({
error: function (err){
console.error('an error occurred- error details:',err);
return exits.error();
},
invalid: function (){ exits.invalid() },
success: function() {
// return exits.success();
installGulpDependencies({
}).exec({
error: function (err){
console.error('an error occurred- error details:',err);
return exits.error();
},
invalid: function (){ exits.invalid() },
success: function() {
return exits.success();
}
});
}
});
}
});
}
});
}
});
}
else if(firstTimeRun === 'no') {
createGulpEngine({
gulpFolderSrcPath: '../lib/gulp',
outputDir: '../../sails/lib/hooks/gulp'
//outputDir: '../../../api/hooks/gulp'
}).exec({
error: function (err){
console.error('an error occurred- error details:',err);
return exits.error();
},
invalid: function (){ exits.invalid() },
success: function() {
return exits.success();
}
});
}
} | [
"function",
"(",
"userInput",
")",
"{",
"var",
"firstTimeRun",
"=",
"userInput",
".",
"toLowerCase",
"(",
")",
";",
"if",
"(",
"firstTimeRun",
"===",
"'yes'",
")",
"{",
"createGulpFile",
"(",
"{",
"gulpFileSrcPath",
":",
"'../templates/gulpfile.js'",
",",
"outputDir",
":",
"'../../../gulpfile.js'",
"}",
")",
".",
"exec",
"(",
"{",
"error",
":",
"function",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"'an error occurred- error details:'",
",",
"err",
")",
";",
"return",
"exits",
".",
"error",
"(",
")",
";",
"}",
",",
"invalid",
":",
"function",
"(",
")",
"{",
"exits",
".",
"invalid",
"(",
")",
"}",
",",
"success",
":",
"function",
"(",
")",
"{",
"createGulpTasks",
"(",
"{",
"gulpFolderSrcPath",
":",
"'../templates/tasks-gulp'",
",",
"outputFolderDir",
":",
"'../../../tasks-gulp'",
"}",
")",
".",
"exec",
"(",
"{",
"error",
":",
"function",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"'an error occurred- error details:'",
",",
"err",
")",
";",
"return",
"exits",
".",
"error",
"(",
")",
";",
"}",
",",
"invalid",
":",
"function",
"(",
")",
"{",
"exits",
".",
"invalid",
"(",
")",
"}",
",",
"success",
":",
"function",
"(",
")",
"{",
"createGulpEngine",
"(",
"{",
"gulpFolderSrcPath",
":",
"'../lib/gulp'",
",",
"outputDir",
":",
"'../../sails/lib/hooks/gulp'",
"}",
")",
".",
"exec",
"(",
"{",
"error",
":",
"function",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"'an error occurred- error details:'",
",",
"err",
")",
";",
"return",
"exits",
".",
"error",
"(",
")",
";",
"}",
",",
"invalid",
":",
"function",
"(",
")",
"{",
"exits",
".",
"invalid",
"(",
")",
"}",
",",
"success",
":",
"function",
"(",
")",
"{",
"toggleSailsrc",
"(",
"{",
"sailsrcSrc",
":",
"'../json/gulp.sailsrc'",
",",
"outputDir",
":",
"'../../../.sailsrc'",
"}",
")",
".",
"exec",
"(",
"{",
"error",
":",
"function",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"'an error occurred- error details:'",
",",
"err",
")",
";",
"return",
"exits",
".",
"error",
"(",
")",
";",
"}",
",",
"invalid",
":",
"function",
"(",
")",
"{",
"exits",
".",
"invalid",
"(",
")",
"}",
",",
"success",
":",
"function",
"(",
")",
"{",
"installGulpDependencies",
"(",
"{",
"}",
")",
".",
"exec",
"(",
"{",
"error",
":",
"function",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"'an error occurred- error details:'",
",",
"err",
")",
";",
"return",
"exits",
".",
"error",
"(",
")",
";",
"}",
",",
"invalid",
":",
"function",
"(",
")",
"{",
"exits",
".",
"invalid",
"(",
")",
"}",
",",
"success",
":",
"function",
"(",
")",
"{",
"return",
"exits",
".",
"success",
"(",
")",
";",
"}",
"}",
")",
";",
"}",
"}",
")",
";",
"}",
"}",
")",
";",
"}",
"}",
")",
";",
"}",
"}",
")",
";",
"}",
"else",
"if",
"(",
"firstTimeRun",
"===",
"'no'",
")",
"{",
"createGulpEngine",
"(",
"{",
"gulpFolderSrcPath",
":",
"'../lib/gulp'",
",",
"outputDir",
":",
"'../../sails/lib/hooks/gulp'",
"}",
")",
".",
"exec",
"(",
"{",
"error",
":",
"function",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"'an error occurred- error details:'",
",",
"err",
")",
";",
"return",
"exits",
".",
"error",
"(",
")",
";",
"}",
",",
"invalid",
":",
"function",
"(",
")",
"{",
"exits",
".",
"invalid",
"(",
")",
"}",
",",
"success",
":",
"function",
"(",
")",
"{",
"return",
"exits",
".",
"success",
"(",
")",
";",
"}",
"}",
")",
";",
"}",
"}"
] | OK- got user input. | [
"OK",
"-",
"got",
"user",
"input",
"."
] | 38424f98d59cac4240e676159bd25e3bc82ad8ac | https://github.com/Karnith/machinepack-sailsgulpify/blob/38424f98d59cac4240e676159bd25e3bc82ad8ac/machines/sails-gulpify.js#L51-L133 | train |
|
ramonvictor/gulp-protractor-qa | index.js | readFiles | function readFiles() {
/* jshint validthis:true */
var self = this;
async.waterfall([
function(callback) {
storeFileContent.init(self.options.testSrc, callback);
},
function(data, callback) {
self.testFiles = data;
storeFileContent.init(self.options.viewSrc, callback);
},
function(data, callback) {
self.viewFiles = data;
callback(null, 'success');
}
], function() {
findElementSelectors.call(self);
});
} | javascript | function readFiles() {
/* jshint validthis:true */
var self = this;
async.waterfall([
function(callback) {
storeFileContent.init(self.options.testSrc, callback);
},
function(data, callback) {
self.testFiles = data;
storeFileContent.init(self.options.viewSrc, callback);
},
function(data, callback) {
self.viewFiles = data;
callback(null, 'success');
}
], function() {
findElementSelectors.call(self);
});
} | [
"function",
"readFiles",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"async",
".",
"waterfall",
"(",
"[",
"function",
"(",
"callback",
")",
"{",
"storeFileContent",
".",
"init",
"(",
"self",
".",
"options",
".",
"testSrc",
",",
"callback",
")",
";",
"}",
",",
"function",
"(",
"data",
",",
"callback",
")",
"{",
"self",
".",
"testFiles",
"=",
"data",
";",
"storeFileContent",
".",
"init",
"(",
"self",
".",
"options",
".",
"viewSrc",
",",
"callback",
")",
";",
"}",
",",
"function",
"(",
"data",
",",
"callback",
")",
"{",
"self",
".",
"viewFiles",
"=",
"data",
";",
"callback",
"(",
"null",
",",
"'success'",
")",
";",
"}",
"]",
",",
"function",
"(",
")",
"{",
"findElementSelectors",
".",
"call",
"(",
"self",
")",
";",
"}",
")",
";",
"}"
] | Read `testSrc` and `viewSrc` files content. | [
"Read",
"testSrc",
"and",
"viewSrc",
"files",
"content",
"."
] | b5a462649bb9cbdcd9d852d865bb05f120cff84d | https://github.com/ramonvictor/gulp-protractor-qa/blob/b5a462649bb9cbdcd9d852d865bb05f120cff84d/index.js#L53-L72 | train |
lemire/TypedFastBitSet.js | TypedFastBitSet.js | TypedFastBitSet | function TypedFastBitSet(iterable) {
this.count = 0 | 0;
this.words = new Uint32Array(8);
if (isIterable(iterable)) {
for (var key of iterable) {
this.add(key);
}
}
} | javascript | function TypedFastBitSet(iterable) {
this.count = 0 | 0;
this.words = new Uint32Array(8);
if (isIterable(iterable)) {
for (var key of iterable) {
this.add(key);
}
}
} | [
"function",
"TypedFastBitSet",
"(",
"iterable",
")",
"{",
"this",
".",
"count",
"=",
"0",
"|",
"0",
";",
"this",
".",
"words",
"=",
"new",
"Uint32Array",
"(",
"8",
")",
";",
"if",
"(",
"isIterable",
"(",
"iterable",
")",
")",
"{",
"for",
"(",
"var",
"key",
"of",
"iterable",
")",
"{",
"this",
".",
"add",
"(",
"key",
")",
";",
"}",
"}",
"}"
] | you can provide an iterable an exception is thrown if typed arrays are not supported | [
"you",
"can",
"provide",
"an",
"iterable",
"an",
"exception",
"is",
"thrown",
"if",
"typed",
"arrays",
"are",
"not",
"supported"
] | 7f325b54ab9384aa590c2a85d97e46f3ffa5884b | https://github.com/lemire/TypedFastBitSet.js/blob/7f325b54ab9384aa590c2a85d97e46f3ffa5884b/TypedFastBitSet.js#L47-L55 | train |
WorldMobileCoin/wmcc-core | src/script/script.js | Script | function Script(options) {
if (!(this instanceof Script))
return new Script(options);
this.raw = EMPTY_BUFFER;
this.code = [];
if (options)
this.fromOptions(options);
} | javascript | function Script(options) {
if (!(this instanceof Script))
return new Script(options);
this.raw = EMPTY_BUFFER;
this.code = [];
if (options)
this.fromOptions(options);
} | [
"function",
"Script",
"(",
"options",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Script",
")",
")",
"return",
"new",
"Script",
"(",
"options",
")",
";",
"this",
".",
"raw",
"=",
"EMPTY_BUFFER",
";",
"this",
".",
"code",
"=",
"[",
"]",
";",
"if",
"(",
"options",
")",
"this",
".",
"fromOptions",
"(",
"options",
")",
";",
"}"
] | Represents a input or output script.
@alias module:script.Script
@constructor
@param {Buffer|Array|Object|NakedScript} code - Array
of script code or a serialized script Buffer.
@property {Array} code - Parsed script code.
@property {Buffer?} raw - Serialized script.
@property {Number} length - Number of parsed opcodes. | [
"Represents",
"a",
"input",
"or",
"output",
"script",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/script/script.js#L48-L57 | train |
WorldMobileCoin/wmcc-core | src/script/script.js | validateKey | function validateKey(key, flags, version) {
assert(Buffer.isBuffer(key));
assert(typeof flags === 'number');
assert(typeof version === 'number');
if (flags & Script.flags.VERIFY_STRICTENC) {
if (!common.isKeyEncoding(key))
throw new ScriptError('PUBKEYTYPE');
}
if (version === 1) {
if (flags & Script.flags.VERIFY_WITNESS_PUBKEYTYPE) {
if (!common.isCompressedEncoding(key))
throw new ScriptError('WITNESS_PUBKEYTYPE');
}
}
return true;
} | javascript | function validateKey(key, flags, version) {
assert(Buffer.isBuffer(key));
assert(typeof flags === 'number');
assert(typeof version === 'number');
if (flags & Script.flags.VERIFY_STRICTENC) {
if (!common.isKeyEncoding(key))
throw new ScriptError('PUBKEYTYPE');
}
if (version === 1) {
if (flags & Script.flags.VERIFY_WITNESS_PUBKEYTYPE) {
if (!common.isCompressedEncoding(key))
throw new ScriptError('WITNESS_PUBKEYTYPE');
}
}
return true;
} | [
"function",
"validateKey",
"(",
"key",
",",
"flags",
",",
"version",
")",
"{",
"assert",
"(",
"Buffer",
".",
"isBuffer",
"(",
"key",
")",
")",
";",
"assert",
"(",
"typeof",
"flags",
"===",
"'number'",
")",
";",
"assert",
"(",
"typeof",
"version",
"===",
"'number'",
")",
";",
"if",
"(",
"flags",
"&",
"Script",
".",
"flags",
".",
"VERIFY_STRICTENC",
")",
"{",
"if",
"(",
"!",
"common",
".",
"isKeyEncoding",
"(",
"key",
")",
")",
"throw",
"new",
"ScriptError",
"(",
"'PUBKEYTYPE'",
")",
";",
"}",
"if",
"(",
"version",
"===",
"1",
")",
"{",
"if",
"(",
"flags",
"&",
"Script",
".",
"flags",
".",
"VERIFY_WITNESS_PUBKEYTYPE",
")",
"{",
"if",
"(",
"!",
"common",
".",
"isCompressedEncoding",
"(",
"key",
")",
")",
"throw",
"new",
"ScriptError",
"(",
"'WITNESS_PUBKEYTYPE'",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Test whether the data element is a valid key if VERIFY_STRICTENC is enabled.
@param {Buffer} key
@param {VerifyFlags?} flags
@returns {Boolean}
@throws {ScriptError} | [
"Test",
"whether",
"the",
"data",
"element",
"is",
"a",
"valid",
"key",
"if",
"VERIFY_STRICTENC",
"is",
"enabled",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/script/script.js#L3558-L3576 | train |
WorldMobileCoin/wmcc-core | src/script/script.js | validateSignature | function validateSignature(sig, flags) {
assert(Buffer.isBuffer(sig));
assert(typeof flags === 'number');
// Allow empty sigs
if (sig.length === 0)
return true;
if ((flags & Script.flags.VERIFY_DERSIG)
|| (flags & Script.flags.VERIFY_LOW_S)
|| (flags & Script.flags.VERIFY_STRICTENC)) {
if (!common.isSignatureEncoding(sig))
throw new ScriptError('SIG_DER');
}
if (flags & Script.flags.VERIFY_LOW_S) {
if (!common.isLowDER(sig))
throw new ScriptError('SIG_HIGH_S');
}
if (flags & Script.flags.VERIFY_STRICTENC) {
if (!common.isHashType(sig))
throw new ScriptError('SIG_HASHTYPE');
}
return true;
} | javascript | function validateSignature(sig, flags) {
assert(Buffer.isBuffer(sig));
assert(typeof flags === 'number');
// Allow empty sigs
if (sig.length === 0)
return true;
if ((flags & Script.flags.VERIFY_DERSIG)
|| (flags & Script.flags.VERIFY_LOW_S)
|| (flags & Script.flags.VERIFY_STRICTENC)) {
if (!common.isSignatureEncoding(sig))
throw new ScriptError('SIG_DER');
}
if (flags & Script.flags.VERIFY_LOW_S) {
if (!common.isLowDER(sig))
throw new ScriptError('SIG_HIGH_S');
}
if (flags & Script.flags.VERIFY_STRICTENC) {
if (!common.isHashType(sig))
throw new ScriptError('SIG_HASHTYPE');
}
return true;
} | [
"function",
"validateSignature",
"(",
"sig",
",",
"flags",
")",
"{",
"assert",
"(",
"Buffer",
".",
"isBuffer",
"(",
"sig",
")",
")",
";",
"assert",
"(",
"typeof",
"flags",
"===",
"'number'",
")",
";",
"if",
"(",
"sig",
".",
"length",
"===",
"0",
")",
"return",
"true",
";",
"if",
"(",
"(",
"flags",
"&",
"Script",
".",
"flags",
".",
"VERIFY_DERSIG",
")",
"||",
"(",
"flags",
"&",
"Script",
".",
"flags",
".",
"VERIFY_LOW_S",
")",
"||",
"(",
"flags",
"&",
"Script",
".",
"flags",
".",
"VERIFY_STRICTENC",
")",
")",
"{",
"if",
"(",
"!",
"common",
".",
"isSignatureEncoding",
"(",
"sig",
")",
")",
"throw",
"new",
"ScriptError",
"(",
"'SIG_DER'",
")",
";",
"}",
"if",
"(",
"flags",
"&",
"Script",
".",
"flags",
".",
"VERIFY_LOW_S",
")",
"{",
"if",
"(",
"!",
"common",
".",
"isLowDER",
"(",
"sig",
")",
")",
"throw",
"new",
"ScriptError",
"(",
"'SIG_HIGH_S'",
")",
";",
"}",
"if",
"(",
"flags",
"&",
"Script",
".",
"flags",
".",
"VERIFY_STRICTENC",
")",
"{",
"if",
"(",
"!",
"common",
".",
"isHashType",
"(",
"sig",
")",
")",
"throw",
"new",
"ScriptError",
"(",
"'SIG_HASHTYPE'",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Test whether the data element is a valid signature based
on the encoding, S value, and sighash type. Requires
VERIFY_DERSIG|VERIFY_LOW_S|VERIFY_STRICTENC, VERIFY_LOW_S
and VERIFY_STRING_ENC to be enabled respectively. Note that
this will allow zero-length signatures.
@param {Buffer} sig
@param {VerifyFlags?} flags
@returns {Boolean}
@throws {ScriptError} | [
"Test",
"whether",
"the",
"data",
"element",
"is",
"a",
"valid",
"signature",
"based",
"on",
"the",
"encoding",
"S",
"value",
"and",
"sighash",
"type",
".",
"Requires",
"VERIFY_DERSIG|VERIFY_LOW_S|VERIFY_STRICTENC",
"VERIFY_LOW_S",
"and",
"VERIFY_STRING_ENC",
"to",
"be",
"enabled",
"respectively",
".",
"Note",
"that",
"this",
"will",
"allow",
"zero",
"-",
"length",
"signatures",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/script/script.js#L3590-L3616 | train |
WorldMobileCoin/wmcc-core | src/script/script.js | checksig | function checksig(msg, sig, key) {
return secp256k1.verify(msg, sig.slice(0, -1), key);
} | javascript | function checksig(msg, sig, key) {
return secp256k1.verify(msg, sig.slice(0, -1), key);
} | [
"function",
"checksig",
"(",
"msg",
",",
"sig",
",",
"key",
")",
"{",
"return",
"secp256k1",
".",
"verify",
"(",
"msg",
",",
"sig",
".",
"slice",
"(",
"0",
",",
"-",
"1",
")",
",",
"key",
")",
";",
"}"
] | Verify a signature, taking into account sighash type.
@param {Buffer} msg - Signature hash.
@param {Buffer} sig
@param {Buffer} key
@returns {Boolean} | [
"Verify",
"a",
"signature",
"taking",
"into",
"account",
"sighash",
"type",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/script/script.js#L3626-L3628 | train |
WorldMobileCoin/wmcc-core | src/workers/master.js | Master | function Master() {
if (!(this instanceof Master))
return new Master();
EventEmitter.call(this);
this.parent = new Parent();
this.framer = new Framer();
this.parser = new Parser();
this.listening = false;
this.color = false;
this.init();
} | javascript | function Master() {
if (!(this instanceof Master))
return new Master();
EventEmitter.call(this);
this.parent = new Parent();
this.framer = new Framer();
this.parser = new Parser();
this.listening = false;
this.color = false;
this.init();
} | [
"function",
"Master",
"(",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Master",
")",
")",
"return",
"new",
"Master",
"(",
")",
";",
"EventEmitter",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"parent",
"=",
"new",
"Parent",
"(",
")",
";",
"this",
".",
"framer",
"=",
"new",
"Framer",
"(",
")",
";",
"this",
".",
"parser",
"=",
"new",
"Parser",
"(",
")",
";",
"this",
".",
"listening",
"=",
"false",
";",
"this",
".",
"color",
"=",
"false",
";",
"this",
".",
"init",
"(",
")",
";",
"}"
] | Represents the master process.
@alias module:workers.Master
@constructor | [
"Represents",
"the",
"master",
"process",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/workers/master.js#L30-L43 | train |
WorldMobileCoin/wmcc-core | src/primitives/block.js | Block | function Block(options) {
if (!(this instanceof Block))
return new Block(options);
AbstractBlock.call(this);
this.txs = [];
this._raw = null;
this._size = -1;
this._witness = -1;
if (options)
this.fromOptions(options);
} | javascript | function Block(options) {
if (!(this instanceof Block))
return new Block(options);
AbstractBlock.call(this);
this.txs = [];
this._raw = null;
this._size = -1;
this._witness = -1;
if (options)
this.fromOptions(options);
} | [
"function",
"Block",
"(",
"options",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Block",
")",
")",
"return",
"new",
"Block",
"(",
"options",
")",
";",
"AbstractBlock",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"txs",
"=",
"[",
"]",
";",
"this",
".",
"_raw",
"=",
"null",
";",
"this",
".",
"_size",
"=",
"-",
"1",
";",
"this",
".",
"_witness",
"=",
"-",
"1",
";",
"if",
"(",
"options",
")",
"this",
".",
"fromOptions",
"(",
"options",
")",
";",
"}"
] | Represents a full block.
@alias module:primitives.Block
@constructor
@extends AbstractBlock
@param {NakedBlock} options | [
"Represents",
"a",
"full",
"block",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/primitives/block.js#L36-L50 | train |
GitbookIO/tokenize-english | lib/index.js | isNameAbbreviation | function isNameAbbreviation(wordCount, words) {
if (words.length > 0) {
if (wordCount < 5 && words[0].length < 6 && isCapitalized(words[0])) {
return true;
}
var capitalized = words.filter(function(str) {
return /[A-Z]/.test(str.charAt(0));
});
return capitalized.length >= 3;
}
return false;
} | javascript | function isNameAbbreviation(wordCount, words) {
if (words.length > 0) {
if (wordCount < 5 && words[0].length < 6 && isCapitalized(words[0])) {
return true;
}
var capitalized = words.filter(function(str) {
return /[A-Z]/.test(str.charAt(0));
});
return capitalized.length >= 3;
}
return false;
} | [
"function",
"isNameAbbreviation",
"(",
"wordCount",
",",
"words",
")",
"{",
"if",
"(",
"words",
".",
"length",
">",
"0",
")",
"{",
"if",
"(",
"wordCount",
"<",
"5",
"&&",
"words",
"[",
"0",
"]",
".",
"length",
"<",
"6",
"&&",
"isCapitalized",
"(",
"words",
"[",
"0",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"var",
"capitalized",
"=",
"words",
".",
"filter",
"(",
"function",
"(",
"str",
")",
"{",
"return",
"/",
"[A-Z]",
"/",
".",
"test",
"(",
"str",
".",
"charAt",
"(",
"0",
")",
")",
";",
"}",
")",
";",
"return",
"capitalized",
".",
"length",
">=",
"3",
";",
"}",
"return",
"false",
";",
"}"
] | Uses current word count in sentence and next few words to check if it is more likely an abbreviation + name or new sentence. | [
"Uses",
"current",
"word",
"count",
"in",
"sentence",
"and",
"next",
"few",
"words",
"to",
"check",
"if",
"it",
"is",
"more",
"likely",
"an",
"abbreviation",
"+",
"name",
"or",
"new",
"sentence",
"."
] | ea78d188e73b6a9161f876c434e24c02cebbfa3e | https://github.com/GitbookIO/tokenize-english/blob/ea78d188e73b6a9161f876c434e24c02cebbfa3e/lib/index.js#L58-L72 | train |
WorldMobileCoin/wmcc-core | src/utils/asyncobject.js | AsyncObject | function AsyncObject() {
assert(this instanceof AsyncObject);
EventEmitter.call(this);
this._asyncLock = new Lock();
this._hooks = Object.create(null);
this.loading = false;
this.closing = false;
this.loaded = false;
} | javascript | function AsyncObject() {
assert(this instanceof AsyncObject);
EventEmitter.call(this);
this._asyncLock = new Lock();
this._hooks = Object.create(null);
this.loading = false;
this.closing = false;
this.loaded = false;
} | [
"function",
"AsyncObject",
"(",
")",
"{",
"assert",
"(",
"this",
"instanceof",
"AsyncObject",
")",
";",
"EventEmitter",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"_asyncLock",
"=",
"new",
"Lock",
"(",
")",
";",
"this",
".",
"_hooks",
"=",
"Object",
".",
"create",
"(",
"null",
")",
";",
"this",
".",
"loading",
"=",
"false",
";",
"this",
".",
"closing",
"=",
"false",
";",
"this",
".",
"loaded",
"=",
"false",
";",
"}"
] | An abstract object that handles state and
provides recallable open and close methods.
@alias module:utils.AsyncObject
@constructor
@property {Boolean} loading
@property {Boolean} closing
@property {Boolean} loaded | [
"An",
"abstract",
"object",
"that",
"handles",
"state",
"and",
"provides",
"recallable",
"open",
"and",
"close",
"methods",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/utils/asyncobject.js#L27-L38 | train |
WorldMobileCoin/wmcc-core | src/crypto/aes-browser.js | AESKey | function AESKey(key, bits) {
if (!(this instanceof AESKey))
return new AESKey(key, bits);
this.rounds = null;
this.userKey = key;
this.bits = bits;
switch (this.bits) {
case 128:
this.rounds = 10;
break;
case 192:
this.rounds = 12;
break;
case 256:
this.rounds = 14;
break;
default:
throw new Error('Bad key size.');
}
assert(Buffer.isBuffer(key));
assert(key.length === this.bits / 8);
this.decryptKey = null;
this.encryptKey = null;
} | javascript | function AESKey(key, bits) {
if (!(this instanceof AESKey))
return new AESKey(key, bits);
this.rounds = null;
this.userKey = key;
this.bits = bits;
switch (this.bits) {
case 128:
this.rounds = 10;
break;
case 192:
this.rounds = 12;
break;
case 256:
this.rounds = 14;
break;
default:
throw new Error('Bad key size.');
}
assert(Buffer.isBuffer(key));
assert(key.length === this.bits / 8);
this.decryptKey = null;
this.encryptKey = null;
} | [
"function",
"AESKey",
"(",
"key",
",",
"bits",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"AESKey",
")",
")",
"return",
"new",
"AESKey",
"(",
"key",
",",
"bits",
")",
";",
"this",
".",
"rounds",
"=",
"null",
";",
"this",
".",
"userKey",
"=",
"key",
";",
"this",
".",
"bits",
"=",
"bits",
";",
"switch",
"(",
"this",
".",
"bits",
")",
"{",
"case",
"128",
":",
"this",
".",
"rounds",
"=",
"10",
";",
"break",
";",
"case",
"192",
":",
"this",
".",
"rounds",
"=",
"12",
";",
"break",
";",
"case",
"256",
":",
"this",
".",
"rounds",
"=",
"14",
";",
"break",
";",
"default",
":",
"throw",
"new",
"Error",
"(",
"'Bad key size.'",
")",
";",
"}",
"assert",
"(",
"Buffer",
".",
"isBuffer",
"(",
"key",
")",
")",
";",
"assert",
"(",
"key",
".",
"length",
"===",
"this",
".",
"bits",
"/",
"8",
")",
";",
"this",
".",
"decryptKey",
"=",
"null",
";",
"this",
".",
"encryptKey",
"=",
"null",
";",
"}"
] | An AES key object for encrypting
and decrypting blocks.
@constructor
@ignore
@param {Buffer} key
@param {Number} bits | [
"An",
"AES",
"key",
"object",
"for",
"encrypting",
"and",
"decrypting",
"blocks",
"."
] | 29c3759a175341cedae6b744c53eda628c669317 | https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/crypto/aes-browser.js#L612-L639 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.