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
jhermsmeier/node-flightstats
lib/flightstats.js
function( options, callback ) { var self = this var url = '/ratings/rest/v1/json/flight/' + options.carrier + '/' + options.flightNumber var extensions = [] if( Array.isArray( options.extendedOptions ) ) { extensions = extensions.concat( options.extendedOptions ) } return this._clientRequest({ url: url, extendedOptions: extensions, qs: { departureAirport: options.departureAirport, codeType: options.codeType, } }, function( error, data ) { callback.call( self, error, data ) }) }
javascript
function( options, callback ) { var self = this var url = '/ratings/rest/v1/json/flight/' + options.carrier + '/' + options.flightNumber var extensions = [] if( Array.isArray( options.extendedOptions ) ) { extensions = extensions.concat( options.extendedOptions ) } return this._clientRequest({ url: url, extendedOptions: extensions, qs: { departureAirport: options.departureAirport, codeType: options.codeType, } }, function( error, data ) { callback.call( self, error, data ) }) }
[ "function", "(", "options", ",", "callback", ")", "{", "var", "self", "=", "this", "var", "url", "=", "'/ratings/rest/v1/json/flight/'", "+", "options", ".", "carrier", "+", "'/'", "+", "options", ".", "flightNumber", "var", "extensions", "=", "[", "]", "if", "(", "Array", ".", "isArray", "(", "options", ".", "extendedOptions", ")", ")", "{", "extensions", "=", "extensions", ".", "concat", "(", "options", ".", "extendedOptions", ")", "}", "return", "this", ".", "_clientRequest", "(", "{", "url", ":", "url", ",", "extendedOptions", ":", "extensions", ",", "qs", ":", "{", "departureAirport", ":", "options", ".", "departureAirport", ",", "codeType", ":", "options", ".", "codeType", ",", "}", "}", ",", "function", "(", "error", ",", "data", ")", "{", "callback", ".", "call", "(", "self", ",", "error", ",", "data", ")", "}", ")", "}" ]
Get ratings for a specified flight @param {Object} options @param {String} options.carrier @param {String|Number} options.flightNumber @param {Array<String>} [options.extendedOptions] @param {Function} callback @return {Request}
[ "Get", "ratings", "for", "a", "specified", "flight" ]
023d46e11db4f4ba45ed414b1dc23084b1c9749d
https://github.com/jhermsmeier/node-flightstats/blob/023d46e11db4f4ba45ed414b1dc23084b1c9749d/lib/flightstats.js#L612-L634
train
jhermsmeier/node-flightstats
lib/flightstats.js
function( options, callback ) { debug( 'route', options ) var self = this var year = options.date.getFullYear() var month = options.date.getMonth() + 1 var day = options.date.getDate() var direction = /^dep/i.test( options.direction ) ? 'dep' : 'arr' var url = 'flightstatus/rest/v2/json/route/status/' + options.departureAirport + '/' + options.arrivalAirport + '/' + direction + '/' + year + '/' + month + '/' + day var extensions = [ 'useInlinedReferences' ] if( Array.isArray( options.extendedOptions ) ) { extensions = extensions.concat( options.extendedOptions ) } return this._clientRequest({ url: url, extendedOptions: extensions, qs: { maxFlights: options.maxFlights, codeType: options.codeType, numHours: options.numHours, utc: options.utc, hourOfDay: options.hourOfDay, } }, function( error, data ) { callback.call( self, error, data ) }) }
javascript
function( options, callback ) { debug( 'route', options ) var self = this var year = options.date.getFullYear() var month = options.date.getMonth() + 1 var day = options.date.getDate() var direction = /^dep/i.test( options.direction ) ? 'dep' : 'arr' var url = 'flightstatus/rest/v2/json/route/status/' + options.departureAirport + '/' + options.arrivalAirport + '/' + direction + '/' + year + '/' + month + '/' + day var extensions = [ 'useInlinedReferences' ] if( Array.isArray( options.extendedOptions ) ) { extensions = extensions.concat( options.extendedOptions ) } return this._clientRequest({ url: url, extendedOptions: extensions, qs: { maxFlights: options.maxFlights, codeType: options.codeType, numHours: options.numHours, utc: options.utc, hourOfDay: options.hourOfDay, } }, function( error, data ) { callback.call( self, error, data ) }) }
[ "function", "(", "options", ",", "callback", ")", "{", "debug", "(", "'route'", ",", "options", ")", "var", "self", "=", "this", "var", "year", "=", "options", ".", "date", ".", "getFullYear", "(", ")", "var", "month", "=", "options", ".", "date", ".", "getMonth", "(", ")", "+", "1", "var", "day", "=", "options", ".", "date", ".", "getDate", "(", ")", "var", "direction", "=", "/", "^dep", "/", "i", ".", "test", "(", "options", ".", "direction", ")", "?", "'dep'", ":", "'arr'", "var", "url", "=", "'flightstatus/rest/v2/json/route/status/'", "+", "options", ".", "departureAirport", "+", "'/'", "+", "options", ".", "arrivalAirport", "+", "'/'", "+", "direction", "+", "'/'", "+", "year", "+", "'/'", "+", "month", "+", "'/'", "+", "day", "var", "extensions", "=", "[", "'useInlinedReferences'", "]", "if", "(", "Array", ".", "isArray", "(", "options", ".", "extendedOptions", ")", ")", "{", "extensions", "=", "extensions", ".", "concat", "(", "options", ".", "extendedOptions", ")", "}", "return", "this", ".", "_clientRequest", "(", "{", "url", ":", "url", ",", "extendedOptions", ":", "extensions", ",", "qs", ":", "{", "maxFlights", ":", "options", ".", "maxFlights", ",", "codeType", ":", "options", ".", "codeType", ",", "numHours", ":", "options", ".", "numHours", ",", "utc", ":", "options", ".", "utc", ",", "hourOfDay", ":", "options", ".", "hourOfDay", ",", "}", "}", ",", "function", "(", "error", ",", "data", ")", "{", "callback", ".", "call", "(", "self", ",", "error", ",", "data", ")", "}", ")", "}" ]
Get routes between two airports @param {Object} options @param {Date} options.date @param {String} options.departureAirport @param {String} options.arrivalAirport @param {String} options.codeType @param {Number} options.maxFlights @param {Number} options.numHours @param {Number} options.hourOfDay @param {Boolean} options.utc @param {Array<String>} [options.extendedOptions] @param {Function} callback @return {Request}
[ "Get", "routes", "between", "two", "airports" ]
023d46e11db4f4ba45ed414b1dc23084b1c9749d
https://github.com/jhermsmeier/node-flightstats/blob/023d46e11db4f4ba45ed414b1dc23084b1c9749d/lib/flightstats.js#L752-L789
train
ocadotechnology/quantumjs
quantum-dom/lib/index.js
randomId
function randomId () { const res = new Array(32) const alphabet = 'ABCDEF0123456789' for (let i = 0; i < 32; i++) { res[i] = alphabet[Math.floor(Math.random() * 16)] } return res.join('') }
javascript
function randomId () { const res = new Array(32) const alphabet = 'ABCDEF0123456789' for (let i = 0; i < 32; i++) { res[i] = alphabet[Math.floor(Math.random() * 16)] } return res.join('') }
[ "function", "randomId", "(", ")", "{", "const", "res", "=", "new", "Array", "(", "32", ")", "const", "alphabet", "=", "'ABCDEF0123456789'", "for", "(", "let", "i", "=", "0", ";", "i", "<", "32", ";", "i", "++", ")", "{", "res", "[", "i", "]", "=", "alphabet", "[", "Math", ".", "floor", "(", "Math", ".", "random", "(", ")", "*", "16", ")", "]", "}", "return", "res", ".", "join", "(", "''", ")", "}" ]
creates a random id
[ "creates", "a", "random", "id" ]
5bc684b750472296f186a816529272c36218db04
https://github.com/ocadotechnology/quantumjs/blob/5bc684b750472296f186a816529272c36218db04/quantum-dom/lib/index.js#L33-L40
train
ocadotechnology/quantumjs
examples/all-modules/src/transforms/custom-transforms.js
signIn
function signIn (selection) { return dom.create('div').class('sign-in') .add(dom.create('input').class('username-input')) .add(dom.create('input').class('password-input')) .add(dom.create('button').class('sign-in-button').text('Sign in')) }
javascript
function signIn (selection) { return dom.create('div').class('sign-in') .add(dom.create('input').class('username-input')) .add(dom.create('input').class('password-input')) .add(dom.create('button').class('sign-in-button').text('Sign in')) }
[ "function", "signIn", "(", "selection", ")", "{", "return", "dom", ".", "create", "(", "'div'", ")", ".", "class", "(", "'sign-in'", ")", ".", "add", "(", "dom", ".", "create", "(", "'input'", ")", ".", "class", "(", "'username-input'", ")", ")", ".", "add", "(", "dom", ".", "create", "(", "'input'", ")", ".", "class", "(", "'password-input'", ")", ")", ".", "add", "(", "dom", ".", "create", "(", "'button'", ")", ".", "class", "(", "'sign-in-button'", ")", ".", "text", "(", "'Sign in'", ")", ")", "}" ]
creates a sign in block for the @signIn entity
[ "creates", "a", "sign", "in", "block", "for", "the" ]
5bc684b750472296f186a816529272c36218db04
https://github.com/ocadotechnology/quantumjs/blob/5bc684b750472296f186a816529272c36218db04/examples/all-modules/src/transforms/custom-transforms.js#L4-L9
train
ocadotechnology/quantumjs
quantum-core/lib/select.js
isEntity
function isEntity (d) { return isText(d.type) && Array.isArray(d.params) && Array.isArray(d.content) }
javascript
function isEntity (d) { return isText(d.type) && Array.isArray(d.params) && Array.isArray(d.content) }
[ "function", "isEntity", "(", "d", ")", "{", "return", "isText", "(", "d", ".", "type", ")", "&&", "Array", ".", "isArray", "(", "d", ".", "params", ")", "&&", "Array", ".", "isArray", "(", "d", ".", "content", ")", "}" ]
duck type check for an entity
[ "duck", "type", "check", "for", "an", "entity" ]
5bc684b750472296f186a816529272c36218db04
https://github.com/ocadotechnology/quantumjs/blob/5bc684b750472296f186a816529272c36218db04/quantum-core/lib/select.js#L17-L19
train
Banno/polymer-lint
spec/support/helpers/inspect.js
inspect
function inspect(stringsOrOpts, ...values) { if (Array.isArray(stringsOrOpts)) { return DEFAULT_INSPECT(stringsOrOpts, ...values); } return inspector(stringsOrOpts); }
javascript
function inspect(stringsOrOpts, ...values) { if (Array.isArray(stringsOrOpts)) { return DEFAULT_INSPECT(stringsOrOpts, ...values); } return inspector(stringsOrOpts); }
[ "function", "inspect", "(", "stringsOrOpts", ",", "...", "values", ")", "{", "if", "(", "Array", ".", "isArray", "(", "stringsOrOpts", ")", ")", "{", "return", "DEFAULT_INSPECT", "(", "stringsOrOpts", ",", "...", "values", ")", ";", "}", "return", "inspector", "(", "stringsOrOpts", ")", ";", "}" ]
helpers.inspect A tagged template function that automatically calls `util.inspect` on interpolated values in template string literals. If called with an options object, `helpers.inspect` will return a tagged template function that passes the options to `util.inspect`. @example const foo = 'xyz'; const bar = { a: { b: { c: 'def' } } }; // Without helpers.inspect console.log(`foo is ${foo} and bar is ${bar}`); // => foo is xyz and bar is [object Object] // With helpers.inspect console.log( helpers.inspect`foo is ${foo} and bar is ${bar}` ); // => foo is 'xyz' and bar is { a: { b: { c: 'def' } } } // With options console.log( helpers.inspect({ depth: 0 })`foo is ${foo} and bar is ${bar}` ); // => foo is 'xyz' and bar is { a: [Object] } @param {string[]|Object} stringsOrOpts @param {...*} values @return {string}
[ "helpers", ".", "inspect" ]
cf4ffdc63837280080b67f496d038d33a3975b6f
https://github.com/Banno/polymer-lint/blob/cf4ffdc63837280080b67f496d038d33a3975b6f/spec/support/helpers/inspect.js#L54-L59
train
Banno/polymer-lint
spec/lib/util/filterErrorsSpec.js
noisyRule
function noisyRule(context, parser, onError) { parser.on('startTag', (name, attrs, selfClosing, location) => { onError({ rule: name, message: getAttribute(attrs, 'message') || '', location, }); }); }
javascript
function noisyRule(context, parser, onError) { parser.on('startTag', (name, attrs, selfClosing, location) => { onError({ rule: name, message: getAttribute(attrs, 'message') || '', location, }); }); }
[ "function", "noisyRule", "(", "context", ",", "parser", ",", "onError", ")", "{", "parser", ".", "on", "(", "'startTag'", ",", "(", "name", ",", "attrs", ",", "selfClosing", ",", "location", ")", "=>", "{", "onError", "(", "{", "rule", ":", "name", ",", "message", ":", "getAttribute", "(", "attrs", ",", "'message'", ")", "||", "''", ",", "location", ",", "}", ")", ";", "}", ")", ";", "}" ]
This is a rule that reports an error for every startTag, with the ruleName equal to the startTag's name.
[ "This", "is", "a", "rule", "that", "reports", "an", "error", "for", "every", "startTag", "with", "the", "ruleName", "equal", "to", "the", "startTag", "s", "name", "." ]
cf4ffdc63837280080b67f496d038d33a3975b6f
https://github.com/Banno/polymer-lint/blob/cf4ffdc63837280080b67f496d038d33a3975b6f/spec/lib/util/filterErrorsSpec.js#L9-L17
train
Banno/polymer-lint
lib/CLI.js
execute
function execute(argv) { const opts = Options.parse(argv); if (opts.version) { /* eslint-disable global-require */ console.log(`v${ require('../package.json').version }`); return Promise.resolve(0); } if (opts.help || !opts._.length) { console.log(Options.generateHelp()); return Promise.resolve(0); } return lint(resolvePatterns(opts), opts); }
javascript
function execute(argv) { const opts = Options.parse(argv); if (opts.version) { /* eslint-disable global-require */ console.log(`v${ require('../package.json').version }`); return Promise.resolve(0); } if (opts.help || !opts._.length) { console.log(Options.generateHelp()); return Promise.resolve(0); } return lint(resolvePatterns(opts), opts); }
[ "function", "execute", "(", "argv", ")", "{", "const", "opts", "=", "Options", ".", "parse", "(", "argv", ")", ";", "if", "(", "opts", ".", "version", ")", "{", "console", ".", "log", "(", "`", "${", "require", "(", "'../package.json'", ")", ".", "version", "}", "`", ")", ";", "return", "Promise", ".", "resolve", "(", "0", ")", ";", "}", "if", "(", "opts", ".", "help", "||", "!", "opts", ".", "_", ".", "length", ")", "{", "console", ".", "log", "(", "Options", ".", "generateHelp", "(", ")", ")", ";", "return", "Promise", ".", "resolve", "(", "0", ")", ";", "}", "return", "lint", "(", "resolvePatterns", "(", "opts", ")", ",", "opts", ")", ";", "}" ]
Parse the command line arguments and run the linter @memberof module:lib/CLI @param {string[]} argv - Command line arguments @return {number|Promise<number>} A Promise that resolves with a numeric exit code
[ "Parse", "the", "command", "line", "arguments", "and", "run", "the", "linter" ]
cf4ffdc63837280080b67f496d038d33a3975b6f
https://github.com/Banno/polymer-lint/blob/cf4ffdc63837280080b67f496d038d33a3975b6f/lib/CLI.js#L30-L45
train
misoproject/storyboard
dist/miso.storyboard.deps.0.1.0.js
compareAscending
function compareAscending(a, b) { var ai = a.index, bi = b.index; a = a.criteria; b = b.criteria; // ensure a stable sort in V8 and other engines // http://code.google.com/p/v8/issues/detail?id=90 if (a !== b) { if (a > b || typeof a == 'undefined') { return 1; } if (a < b || typeof b == 'undefined') { return -1; } } return ai < bi ? -1 : 1; }
javascript
function compareAscending(a, b) { var ai = a.index, bi = b.index; a = a.criteria; b = b.criteria; // ensure a stable sort in V8 and other engines // http://code.google.com/p/v8/issues/detail?id=90 if (a !== b) { if (a > b || typeof a == 'undefined') { return 1; } if (a < b || typeof b == 'undefined') { return -1; } } return ai < bi ? -1 : 1; }
[ "function", "compareAscending", "(", "a", ",", "b", ")", "{", "var", "ai", "=", "a", ".", "index", ",", "bi", "=", "b", ".", "index", ";", "a", "=", "a", ".", "criteria", ";", "b", "=", "b", ".", "criteria", ";", "if", "(", "a", "!==", "b", ")", "{", "if", "(", "a", ">", "b", "||", "typeof", "a", "==", "'undefined'", ")", "{", "return", "1", ";", "}", "if", "(", "a", "<", "b", "||", "typeof", "b", "==", "'undefined'", ")", "{", "return", "-", "1", ";", "}", "}", "return", "ai", "<", "bi", "?", "-", "1", ":", "1", ";", "}" ]
Used by `sortBy` to compare transformed `collection` values, stable sorting them in ascending order. @private @param {Object} a The object to compare to `b`. @param {Object} b The object to compare to `a`. @returns {Number} Returns the sort order indicator of `1` or `-1`.
[ "Used", "by", "sortBy", "to", "compare", "transformed", "collection", "values", "stable", "sorting", "them", "in", "ascending", "order", "." ]
96d6cdfe756e0e4f2df7c9a55c414fe93a4c38ec
https://github.com/misoproject/storyboard/blob/96d6cdfe756e0e4f2df7c9a55c414fe93a4c38ec/dist/miso.storyboard.deps.0.1.0.js#L423-L441
train
misoproject/storyboard
dist/miso.storyboard.deps.0.1.0.js
createBound
function createBound(func, thisArg, partialArgs, indicator) { var isFunc = isFunction(func), isPartial = !partialArgs, key = thisArg; // juggle arguments if (isPartial) { var rightIndicator = indicator; partialArgs = thisArg; } else if (!isFunc) { if (!indicator) { throw new TypeError; } thisArg = func; } function bound() { // `Function#bind` spec // http://es5.github.com/#x15.3.4.5 var args = arguments, thisBinding = isPartial ? this : thisArg; if (!isFunc) { func = thisArg[key]; } if (partialArgs.length) { args = args.length ? (args = nativeSlice.call(args), rightIndicator ? args.concat(partialArgs) : partialArgs.concat(args)) : partialArgs; } if (this instanceof bound) { // ensure `new bound` is an instance of `func` noop.prototype = func.prototype; thisBinding = new noop; noop.prototype = null; // mimic the constructor's `return` behavior // http://es5.github.com/#x13.2.2 var result = func.apply(thisBinding, args); return isObject(result) ? result : thisBinding; } return func.apply(thisBinding, args); } return bound; }
javascript
function createBound(func, thisArg, partialArgs, indicator) { var isFunc = isFunction(func), isPartial = !partialArgs, key = thisArg; // juggle arguments if (isPartial) { var rightIndicator = indicator; partialArgs = thisArg; } else if (!isFunc) { if (!indicator) { throw new TypeError; } thisArg = func; } function bound() { // `Function#bind` spec // http://es5.github.com/#x15.3.4.5 var args = arguments, thisBinding = isPartial ? this : thisArg; if (!isFunc) { func = thisArg[key]; } if (partialArgs.length) { args = args.length ? (args = nativeSlice.call(args), rightIndicator ? args.concat(partialArgs) : partialArgs.concat(args)) : partialArgs; } if (this instanceof bound) { // ensure `new bound` is an instance of `func` noop.prototype = func.prototype; thisBinding = new noop; noop.prototype = null; // mimic the constructor's `return` behavior // http://es5.github.com/#x13.2.2 var result = func.apply(thisBinding, args); return isObject(result) ? result : thisBinding; } return func.apply(thisBinding, args); } return bound; }
[ "function", "createBound", "(", "func", ",", "thisArg", ",", "partialArgs", ",", "indicator", ")", "{", "var", "isFunc", "=", "isFunction", "(", "func", ")", ",", "isPartial", "=", "!", "partialArgs", ",", "key", "=", "thisArg", ";", "if", "(", "isPartial", ")", "{", "var", "rightIndicator", "=", "indicator", ";", "partialArgs", "=", "thisArg", ";", "}", "else", "if", "(", "!", "isFunc", ")", "{", "if", "(", "!", "indicator", ")", "{", "throw", "new", "TypeError", ";", "}", "thisArg", "=", "func", ";", "}", "function", "bound", "(", ")", "{", "var", "args", "=", "arguments", ",", "thisBinding", "=", "isPartial", "?", "this", ":", "thisArg", ";", "if", "(", "!", "isFunc", ")", "{", "func", "=", "thisArg", "[", "key", "]", ";", "}", "if", "(", "partialArgs", ".", "length", ")", "{", "args", "=", "args", ".", "length", "?", "(", "args", "=", "nativeSlice", ".", "call", "(", "args", ")", ",", "rightIndicator", "?", "args", ".", "concat", "(", "partialArgs", ")", ":", "partialArgs", ".", "concat", "(", "args", ")", ")", ":", "partialArgs", ";", "}", "if", "(", "this", "instanceof", "bound", ")", "{", "noop", ".", "prototype", "=", "func", ".", "prototype", ";", "thisBinding", "=", "new", "noop", ";", "noop", ".", "prototype", "=", "null", ";", "var", "result", "=", "func", ".", "apply", "(", "thisBinding", ",", "args", ")", ";", "return", "isObject", "(", "result", ")", "?", "result", ":", "thisBinding", ";", "}", "return", "func", ".", "apply", "(", "thisBinding", ",", "args", ")", ";", "}", "return", "bound", ";", "}" ]
Creates a function that, when called, invokes `func` with the `this` binding of `thisArg` and prepends any `partialArgs` to the arguments passed to the bound function. @private @param {Function|String} func The function to bind or the method name. @param {Mixed} [thisArg] The `this` binding of `func`. @param {Array} partialArgs An array of arguments to be partially applied. @param {Object} [idicator] Used to indicate binding by key or partially applying arguments from the right. @returns {Function} Returns the new bound function.
[ "Creates", "a", "function", "that", "when", "called", "invokes", "func", "with", "the", "this", "binding", "of", "thisArg", "and", "prepends", "any", "partialArgs", "to", "the", "arguments", "passed", "to", "the", "bound", "function", "." ]
96d6cdfe756e0e4f2df7c9a55c414fe93a4c38ec
https://github.com/misoproject/storyboard/blob/96d6cdfe756e0e4f2df7c9a55c414fe93a4c38ec/dist/miso.storyboard.deps.0.1.0.js#L456-L501
train
misoproject/storyboard
dist/miso.storyboard.deps.0.1.0.js
findKey
function findKey(object, callback, thisArg) { var result; callback = lodash.createCallback(callback, thisArg); forOwn(object, function(value, key, object) { if (callback(value, key, object)) { result = key; return false; } }); return result; }
javascript
function findKey(object, callback, thisArg) { var result; callback = lodash.createCallback(callback, thisArg); forOwn(object, function(value, key, object) { if (callback(value, key, object)) { result = key; return false; } }); return result; }
[ "function", "findKey", "(", "object", ",", "callback", ",", "thisArg", ")", "{", "var", "result", ";", "callback", "=", "lodash", ".", "createCallback", "(", "callback", ",", "thisArg", ")", ";", "forOwn", "(", "object", ",", "function", "(", "value", ",", "key", ",", "object", ")", "{", "if", "(", "callback", "(", "value", ",", "key", ",", "object", ")", ")", "{", "result", "=", "key", ";", "return", "false", ";", "}", "}", ")", ";", "return", "result", ";", "}" ]
This method is similar to `_.find`, except that it returns the key of the element that passes the callback check, instead of the element itself. @static @memberOf _ @category Objects @param {Object} object The object to search. @param {Function|Object|String} [callback=identity] The function called per iteration. If a property name or object is passed, it will be used to create a "_.pluck" or "_.where" style callback, respectively. @param {Mixed} [thisArg] The `this` binding of `callback`. @returns {Mixed} Returns the key of the found element, else `undefined`. @example _.findKey({ 'a': 1, 'b': 2, 'c': 3, 'd': 4 }, function(num) { return num % 2 == 0; }); // => 'b'
[ "This", "method", "is", "similar", "to", "_", ".", "find", "except", "that", "it", "returns", "the", "key", "of", "the", "element", "that", "passes", "the", "callback", "check", "instead", "of", "the", "element", "itself", "." ]
96d6cdfe756e0e4f2df7c9a55c414fe93a4c38ec
https://github.com/misoproject/storyboard/blob/96d6cdfe756e0e4f2df7c9a55c414fe93a4c38ec/dist/miso.storyboard.deps.0.1.0.js#L1027-L1037
train
misoproject/storyboard
dist/miso.storyboard.deps.0.1.0.js
reduceRight
function reduceRight(collection, callback, accumulator, thisArg) { var iterable = collection, length = collection ? collection.length : 0, noaccum = arguments.length < 3; if (typeof length != 'number') { var props = keys(collection); length = props.length; } callback = lodash.createCallback(callback, thisArg, 4); forEach(collection, function(value, index, collection) { index = props ? props[--length] : --length; accumulator = noaccum ? (noaccum = false, iterable[index]) : callback(accumulator, iterable[index], index, collection); }); return accumulator; }
javascript
function reduceRight(collection, callback, accumulator, thisArg) { var iterable = collection, length = collection ? collection.length : 0, noaccum = arguments.length < 3; if (typeof length != 'number') { var props = keys(collection); length = props.length; } callback = lodash.createCallback(callback, thisArg, 4); forEach(collection, function(value, index, collection) { index = props ? props[--length] : --length; accumulator = noaccum ? (noaccum = false, iterable[index]) : callback(accumulator, iterable[index], index, collection); }); return accumulator; }
[ "function", "reduceRight", "(", "collection", ",", "callback", ",", "accumulator", ",", "thisArg", ")", "{", "var", "iterable", "=", "collection", ",", "length", "=", "collection", "?", "collection", ".", "length", ":", "0", ",", "noaccum", "=", "arguments", ".", "length", "<", "3", ";", "if", "(", "typeof", "length", "!=", "'number'", ")", "{", "var", "props", "=", "keys", "(", "collection", ")", ";", "length", "=", "props", ".", "length", ";", "}", "callback", "=", "lodash", ".", "createCallback", "(", "callback", ",", "thisArg", ",", "4", ")", ";", "forEach", "(", "collection", ",", "function", "(", "value", ",", "index", ",", "collection", ")", "{", "index", "=", "props", "?", "props", "[", "--", "length", "]", ":", "--", "length", ";", "accumulator", "=", "noaccum", "?", "(", "noaccum", "=", "false", ",", "iterable", "[", "index", "]", ")", ":", "callback", "(", "accumulator", ",", "iterable", "[", "index", "]", ",", "index", ",", "collection", ")", ";", "}", ")", ";", "return", "accumulator", ";", "}" ]
This method is similar to `_.reduce`, except that it iterates over a `collection` from right to left. @static @memberOf _ @alias foldr @category Collections @param {Array|Object|String} collection The collection to iterate over. @param {Function} [callback=identity] The function called per iteration. @param {Mixed} [accumulator] Initial value of the accumulator. @param {Mixed} [thisArg] The `this` binding of `callback`. @returns {Mixed} Returns the accumulated value. @example var list = [[0, 1], [2, 3], [4, 5]]; var flat = _.reduceRight(list, function(a, b) { return a.concat(b); }, []); // => [4, 5, 2, 3, 0, 1]
[ "This", "method", "is", "similar", "to", "_", ".", "reduce", "except", "that", "it", "iterates", "over", "a", "collection", "from", "right", "to", "left", "." ]
96d6cdfe756e0e4f2df7c9a55c414fe93a4c38ec
https://github.com/misoproject/storyboard/blob/96d6cdfe756e0e4f2df7c9a55c414fe93a4c38ec/dist/miso.storyboard.deps.0.1.0.js#L2731-L2748
train
misoproject/storyboard
dist/miso.storyboard.deps.0.1.0.js
findIndex
function findIndex(array, callback, thisArg) { var index = -1, length = array ? array.length : 0; callback = lodash.createCallback(callback, thisArg); while (++index < length) { if (callback(array[index], index, array)) { return index; } } return -1; }
javascript
function findIndex(array, callback, thisArg) { var index = -1, length = array ? array.length : 0; callback = lodash.createCallback(callback, thisArg); while (++index < length) { if (callback(array[index], index, array)) { return index; } } return -1; }
[ "function", "findIndex", "(", "array", ",", "callback", ",", "thisArg", ")", "{", "var", "index", "=", "-", "1", ",", "length", "=", "array", "?", "array", ".", "length", ":", "0", ";", "callback", "=", "lodash", ".", "createCallback", "(", "callback", ",", "thisArg", ")", ";", "while", "(", "++", "index", "<", "length", ")", "{", "if", "(", "callback", "(", "array", "[", "index", "]", ",", "index", ",", "array", ")", ")", "{", "return", "index", ";", "}", "}", "return", "-", "1", ";", "}" ]
This method is similar to `_.find`, except that it returns the index of the element that passes the callback check, instead of the element itself. @static @memberOf _ @category Arrays @param {Array} array The array to search. @param {Function|Object|String} [callback=identity] The function called per iteration. If a property name or object is passed, it will be used to create a "_.pluck" or "_.where" style callback, respectively. @param {Mixed} [thisArg] The `this` binding of `callback`. @returns {Mixed} Returns the index of the found element, else `-1`. @example _.findIndex(['apple', 'banana', 'beet'], function(food) { return /^b/.test(food); }); // => 1
[ "This", "method", "is", "similar", "to", "_", ".", "find", "except", "that", "it", "returns", "the", "index", "of", "the", "element", "that", "passes", "the", "callback", "check", "instead", "of", "the", "element", "itself", "." ]
96d6cdfe756e0e4f2df7c9a55c414fe93a4c38ec
https://github.com/misoproject/storyboard/blob/96d6cdfe756e0e4f2df7c9a55c414fe93a4c38ec/dist/miso.storyboard.deps.0.1.0.js#L3095-L3106
train
misoproject/storyboard
dist/miso.storyboard.deps.0.1.0.js
unzip
function unzip(array) { var index = -1, length = array ? array.length : 0, tupleLength = length ? max(pluck(array, 'length')) : 0, result = Array(tupleLength); while (++index < length) { var tupleIndex = -1, tuple = array[index]; while (++tupleIndex < tupleLength) { (result[tupleIndex] || (result[tupleIndex] = Array(length)))[index] = tuple[tupleIndex]; } } return result; }
javascript
function unzip(array) { var index = -1, length = array ? array.length : 0, tupleLength = length ? max(pluck(array, 'length')) : 0, result = Array(tupleLength); while (++index < length) { var tupleIndex = -1, tuple = array[index]; while (++tupleIndex < tupleLength) { (result[tupleIndex] || (result[tupleIndex] = Array(length)))[index] = tuple[tupleIndex]; } } return result; }
[ "function", "unzip", "(", "array", ")", "{", "var", "index", "=", "-", "1", ",", "length", "=", "array", "?", "array", ".", "length", ":", "0", ",", "tupleLength", "=", "length", "?", "max", "(", "pluck", "(", "array", ",", "'length'", ")", ")", ":", "0", ",", "result", "=", "Array", "(", "tupleLength", ")", ";", "while", "(", "++", "index", "<", "length", ")", "{", "var", "tupleIndex", "=", "-", "1", ",", "tuple", "=", "array", "[", "index", "]", ";", "while", "(", "++", "tupleIndex", "<", "tupleLength", ")", "{", "(", "result", "[", "tupleIndex", "]", "||", "(", "result", "[", "tupleIndex", "]", "=", "Array", "(", "length", ")", ")", ")", "[", "index", "]", "=", "tuple", "[", "tupleIndex", "]", ";", "}", "}", "return", "result", ";", "}" ]
The inverse of `_.zip`, this method splits groups of elements into arrays composed of elements from each group at their corresponding indexes. @static @memberOf _ @category Arrays @param {Array} array The array to process. @returns {Array} Returns a new array of the composed arrays. @example _.unzip([['moe', 30, true], ['larry', 40, false]]); // => [['moe', 'larry'], [30, 40], [true, false]];
[ "The", "inverse", "of", "_", ".", "zip", "this", "method", "splits", "groups", "of", "elements", "into", "arrays", "composed", "of", "elements", "from", "each", "group", "at", "their", "corresponding", "indexes", "." ]
96d6cdfe756e0e4f2df7c9a55c414fe93a4c38ec
https://github.com/misoproject/storyboard/blob/96d6cdfe756e0e4f2df7c9a55c414fe93a4c38ec/dist/miso.storyboard.deps.0.1.0.js#L3845-L3860
train
misoproject/storyboard
dist/miso.storyboard.deps.0.1.0.js
bind
function bind(func, thisArg) { // use `Function#bind` if it exists and is fast // (in V8 `Function#bind` is slower except when partially applied) return support.fastBind || (nativeBind && arguments.length > 2) ? nativeBind.call.apply(nativeBind, arguments) : createBound(func, thisArg, nativeSlice.call(arguments, 2)); }
javascript
function bind(func, thisArg) { // use `Function#bind` if it exists and is fast // (in V8 `Function#bind` is slower except when partially applied) return support.fastBind || (nativeBind && arguments.length > 2) ? nativeBind.call.apply(nativeBind, arguments) : createBound(func, thisArg, nativeSlice.call(arguments, 2)); }
[ "function", "bind", "(", "func", ",", "thisArg", ")", "{", "return", "support", ".", "fastBind", "||", "(", "nativeBind", "&&", "arguments", ".", "length", ">", "2", ")", "?", "nativeBind", ".", "call", ".", "apply", "(", "nativeBind", ",", "arguments", ")", ":", "createBound", "(", "func", ",", "thisArg", ",", "nativeSlice", ".", "call", "(", "arguments", ",", "2", ")", ")", ";", "}" ]
Creates a function that, when called, invokes `func` with the `this` binding of `thisArg` and prepends any additional `bind` arguments to those passed to the bound function. @static @memberOf _ @category Functions @param {Function} func The function to bind. @param {Mixed} [thisArg] The `this` binding of `func`. @param {Mixed} [arg1, arg2, ...] Arguments to be partially applied. @returns {Function} Returns the new bound function. @example var func = function(greeting) { return greeting + ' ' + this.name; }; func = _.bind(func, { 'name': 'moe' }, 'hi'); func(); // => 'hi moe'
[ "Creates", "a", "function", "that", "when", "called", "invokes", "func", "with", "the", "this", "binding", "of", "thisArg", "and", "prepends", "any", "additional", "bind", "arguments", "to", "those", "passed", "to", "the", "bound", "function", "." ]
96d6cdfe756e0e4f2df7c9a55c414fe93a4c38ec
https://github.com/misoproject/storyboard/blob/96d6cdfe756e0e4f2df7c9a55c414fe93a4c38ec/dist/miso.storyboard.deps.0.1.0.js#L3999-L4005
train
misoproject/storyboard
dist/miso.storyboard.deps.0.1.0.js
bindAll
function bindAll(object) { var funcs = arguments.length > 1 ? concat.apply(arrayRef, nativeSlice.call(arguments, 1)) : functions(object), index = -1, length = funcs.length; while (++index < length) { var key = funcs[index]; object[key] = bind(object[key], object); } return object; }
javascript
function bindAll(object) { var funcs = arguments.length > 1 ? concat.apply(arrayRef, nativeSlice.call(arguments, 1)) : functions(object), index = -1, length = funcs.length; while (++index < length) { var key = funcs[index]; object[key] = bind(object[key], object); } return object; }
[ "function", "bindAll", "(", "object", ")", "{", "var", "funcs", "=", "arguments", ".", "length", ">", "1", "?", "concat", ".", "apply", "(", "arrayRef", ",", "nativeSlice", ".", "call", "(", "arguments", ",", "1", ")", ")", ":", "functions", "(", "object", ")", ",", "index", "=", "-", "1", ",", "length", "=", "funcs", ".", "length", ";", "while", "(", "++", "index", "<", "length", ")", "{", "var", "key", "=", "funcs", "[", "index", "]", ";", "object", "[", "key", "]", "=", "bind", "(", "object", "[", "key", "]", ",", "object", ")", ";", "}", "return", "object", ";", "}" ]
Binds methods on `object` to `object`, overwriting the existing method. Method names may be specified as individual arguments or as arrays of method names. If no method names are provided, all the function properties of `object` will be bound. @static @memberOf _ @category Functions @param {Object} object The object to bind and assign the bound methods to. @param {String} [methodName1, methodName2, ...] Method names on the object to bind. @returns {Object} Returns `object`. @example var view = { 'label': 'docs', 'onClick': function() { alert('clicked ' + this.label); } }; _.bindAll(view); jQuery('#docs').on('click', view.onClick); // => alerts 'clicked docs', when the button is clicked
[ "Binds", "methods", "on", "object", "to", "object", "overwriting", "the", "existing", "method", ".", "Method", "names", "may", "be", "specified", "as", "individual", "arguments", "or", "as", "arrays", "of", "method", "names", ".", "If", "no", "method", "names", "are", "provided", "all", "the", "function", "properties", "of", "object", "will", "be", "bound", "." ]
96d6cdfe756e0e4f2df7c9a55c414fe93a4c38ec
https://github.com/misoproject/storyboard/blob/96d6cdfe756e0e4f2df7c9a55c414fe93a4c38ec/dist/miso.storyboard.deps.0.1.0.js#L4030-L4040
train
misoproject/storyboard
dist/miso.storyboard.deps.0.1.0.js
defer
function defer(func) { var args = nativeSlice.call(arguments, 1); return setTimeout(function() { func.apply(undefined, args); }, 1); }
javascript
function defer(func) { var args = nativeSlice.call(arguments, 1); return setTimeout(function() { func.apply(undefined, args); }, 1); }
[ "function", "defer", "(", "func", ")", "{", "var", "args", "=", "nativeSlice", ".", "call", "(", "arguments", ",", "1", ")", ";", "return", "setTimeout", "(", "function", "(", ")", "{", "func", ".", "apply", "(", "undefined", ",", "args", ")", ";", "}", ",", "1", ")", ";", "}" ]
Defers executing the `func` function until the current call stack has cleared. Additional arguments will be passed to `func` when it is invoked. @static @memberOf _ @category Functions @param {Function} func The function to defer. @param {Mixed} [arg1, arg2, ...] Arguments to invoke the function with. @returns {Number} Returns the timer id. @example _.defer(function() { alert('deferred'); }); // returns from the function before `alert` is called
[ "Defers", "executing", "the", "func", "function", "until", "the", "current", "call", "stack", "has", "cleared", ".", "Additional", "arguments", "will", "be", "passed", "to", "func", "when", "it", "is", "invoked", "." ]
96d6cdfe756e0e4f2df7c9a55c414fe93a4c38ec
https://github.com/misoproject/storyboard/blob/96d6cdfe756e0e4f2df7c9a55c414fe93a4c38ec/dist/miso.storyboard.deps.0.1.0.js#L4285-L4288
train
misoproject/storyboard
dist/miso.storyboard.deps.0.1.0.js
memoize
function memoize(func, resolver) { var cache = {}; return function() { var key = keyPrefix + (resolver ? resolver.apply(this, arguments) : arguments[0]); return hasOwnProperty.call(cache, key) ? cache[key] : (cache[key] = func.apply(this, arguments)); }; }
javascript
function memoize(func, resolver) { var cache = {}; return function() { var key = keyPrefix + (resolver ? resolver.apply(this, arguments) : arguments[0]); return hasOwnProperty.call(cache, key) ? cache[key] : (cache[key] = func.apply(this, arguments)); }; }
[ "function", "memoize", "(", "func", ",", "resolver", ")", "{", "var", "cache", "=", "{", "}", ";", "return", "function", "(", ")", "{", "var", "key", "=", "keyPrefix", "+", "(", "resolver", "?", "resolver", ".", "apply", "(", "this", ",", "arguments", ")", ":", "arguments", "[", "0", "]", ")", ";", "return", "hasOwnProperty", ".", "call", "(", "cache", ",", "key", ")", "?", "cache", "[", "key", "]", ":", "(", "cache", "[", "key", "]", "=", "func", ".", "apply", "(", "this", ",", "arguments", ")", ")", ";", "}", ";", "}" ]
Creates a function that memoizes the result of `func`. If `resolver` is passed, it will be used to determine the cache key for storing the result based on the arguments passed to the memoized function. By default, the first argument passed to the memoized function is used as the cache key. The `func` is executed with the `this` binding of the memoized function. @static @memberOf _ @category Functions @param {Function} func The function to have its output memoized. @param {Function} [resolver] A function used to resolve the cache key. @returns {Function} Returns the new memoizing function. @example var fibonacci = _.memoize(function(n) { return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2); });
[ "Creates", "a", "function", "that", "memoizes", "the", "result", "of", "func", ".", "If", "resolver", "is", "passed", "it", "will", "be", "used", "to", "determine", "the", "cache", "key", "for", "storing", "the", "result", "based", "on", "the", "arguments", "passed", "to", "the", "memoized", "function", ".", "By", "default", "the", "first", "argument", "passed", "to", "the", "memoized", "function", "is", "used", "as", "the", "cache", "key", ".", "The", "func", "is", "executed", "with", "the", "this", "binding", "of", "the", "memoized", "function", "." ]
96d6cdfe756e0e4f2df7c9a55c414fe93a4c38ec
https://github.com/misoproject/storyboard/blob/96d6cdfe756e0e4f2df7c9a55c414fe93a4c38ec/dist/miso.storyboard.deps.0.1.0.js#L4335-L4343
train
misoproject/storyboard
dist/miso.storyboard.deps.0.1.0.js
wrap
function wrap(value, wrapper) { return function() { var args = [value]; push.apply(args, arguments); return wrapper.apply(this, args); }; }
javascript
function wrap(value, wrapper) { return function() { var args = [value]; push.apply(args, arguments); return wrapper.apply(this, args); }; }
[ "function", "wrap", "(", "value", ",", "wrapper", ")", "{", "return", "function", "(", ")", "{", "var", "args", "=", "[", "value", "]", ";", "push", ".", "apply", "(", "args", ",", "arguments", ")", ";", "return", "wrapper", ".", "apply", "(", "this", ",", "args", ")", ";", "}", ";", "}" ]
Creates a function that passes `value` to the `wrapper` function as its first argument. Additional arguments passed to the function are appended to those passed to the `wrapper` function. The `wrapper` is executed with the `this` binding of the created function. @static @memberOf _ @category Functions @param {Mixed} value The value to wrap. @param {Function} wrapper The wrapper function. @returns {Function} Returns the new function. @example var hello = function(name) { return 'hello ' + name; }; hello = _.wrap(hello, function(func) { return 'before, ' + func('moe') + ', after'; }); hello(); // => 'before, hello moe, after'
[ "Creates", "a", "function", "that", "passes", "value", "to", "the", "wrapper", "function", "as", "its", "first", "argument", ".", "Additional", "arguments", "passed", "to", "the", "function", "are", "appended", "to", "those", "passed", "to", "the", "wrapper", "function", ".", "The", "wrapper", "is", "executed", "with", "the", "this", "binding", "of", "the", "created", "function", "." ]
96d6cdfe756e0e4f2df7c9a55c414fe93a4c38ec
https://github.com/misoproject/storyboard/blob/96d6cdfe756e0e4f2df7c9a55c414fe93a4c38ec/dist/miso.storyboard.deps.0.1.0.js#L4526-L4532
train
misoproject/storyboard
dist/miso.storyboard.deps.0.1.0.js
function( obj ) { _each( slice.call( arguments, 1), function( source ) { var prop; for ( prop in source ) { if ( source[prop] !== void 0 ) { obj[ prop ] = source[ prop ]; } } }); return obj; }
javascript
function( obj ) { _each( slice.call( arguments, 1), function( source ) { var prop; for ( prop in source ) { if ( source[prop] !== void 0 ) { obj[ prop ] = source[ prop ]; } } }); return obj; }
[ "function", "(", "obj", ")", "{", "_each", "(", "slice", ".", "call", "(", "arguments", ",", "1", ")", ",", "function", "(", "source", ")", "{", "var", "prop", ";", "for", "(", "prop", "in", "source", ")", "{", "if", "(", "source", "[", "prop", "]", "!==", "void", "0", ")", "{", "obj", "[", "prop", "]", "=", "source", "[", "prop", "]", ";", "}", "}", "}", ")", ";", "return", "obj", ";", "}" ]
_.extend
[ "_", ".", "extend" ]
96d6cdfe756e0e4f2df7c9a55c414fe93a4c38ec
https://github.com/misoproject/storyboard/blob/96d6cdfe756e0e4f2df7c9a55c414fe93a4c38ec/dist/miso.storyboard.deps.0.1.0.js#L5318-L5330
train
sendanor/json-schema-orm
src/build.js
string_starts_with
function string_starts_with(str, what) { return (str.substr(0, what.length) === what) ? true : false; }
javascript
function string_starts_with(str, what) { return (str.substr(0, what.length) === what) ? true : false; }
[ "function", "string_starts_with", "(", "str", ",", "what", ")", "{", "return", "(", "str", ".", "substr", "(", "0", ",", "what", ".", "length", ")", "===", "what", ")", "?", "true", ":", "false", ";", "}" ]
Returns true if `str` starts with same string as `what`
[ "Returns", "true", "if", "str", "starts", "with", "same", "string", "as", "what" ]
c6d52b3cbefc904e89cab5ad3c4ecfa26aaf4ea6
https://github.com/sendanor/json-schema-orm/blob/c6d52b3cbefc904e89cab5ad3c4ecfa26aaf4ea6/src/build.js#L35-L37
train
sendanor/json-schema-orm
src/build.js
create_constructor
function create_constructor(type_name) { if(Object.prototype.hasOwnProperty.call(constructors, type_name)) { return constructors[type_name]; } if(!( Object.prototype.hasOwnProperty.call(_schema.definitions, type_name) && is.def(_schema.definitions[type_name]) )) { throw new TypeError("No definition for " + type_name); } var definition = _schema.definitions[type_name]; // ParentType is either SchemaObject or another definition var ParentType = SchemaObject; if( is.obj(definition) && is.def(definition.$ref) && string_starts_with(definition.$ref, '#/definitions/') ) { ParentType = create_constructor( definition.$ref.split('/').slice(2).join('/') ); } // FIXME: If a type has $refs, we should create a copy of schema which defines all those $refs. // Currently just copies schema and changes it to point our definition. Not ideal solution. var copy_definition = JSON.parse(JSON.stringify(_schema)); copy_definition.oneOf = [{"$ref": '#/definitions/'+type_name }]; /* This is our real constructor which will be called in `new Function()` */ function _constructor(self, opts) { var tmp; // Check opts validity var validity = SchemaObject.validate(opts, copy_definition); if(!validity.valid) { throw new TypeError("bad argument: " + util.inspect(validity) ); } // Call parent constructors ParentType.call(self, opts); // Call custom constructors //util.debug( util.inspect( _user_defined_constructors )); if(Object.prototype.hasOwnProperty.call(_user_defined_constructors, type_name)) { tmp = _user_defined_constructors[type_name].call(self, opts); if(is.def(tmp)) { SchemaObject.prototype._setValueOf.call(self, tmp); } //util.debug( util.inspect( tmp ) ); } // Setup getters and setters if schema has properties //util.debug( "\ndefinition = \n----\n" + util.inspect( definition ) + "\n----\n\n" ); if(definition && definition.properties) { Object.getOwnPropertyNames(definition.properties).forEach(function(key) { self.__defineGetter__(key, function(){ return self.valueOf()[key]; }); self.__defineSetter__(key, function(val){ // FIXME: Implement value validation and do not use `.valueOf()`! self.valueOf()[key] = val; }); }); } } var func_name = escape_func_name(type_name); // JavaScript does not support better way to change function names... var code = [ 'function '+func_name+' (opts) {', ' if(!(this instanceof '+func_name+')) {', ' return new '+func_name+'(opts);', ' };', ' _constructor.call(this, this, opts);', '};' ]; var Type = (new Function('_constructor', 'return '+code.join('\n')))(_constructor); util.inherits(Type, ParentType); /* Returns source code for type */ //Type.toSource = function() { // return '(new Function(\'' + [''+_constructor, ''+Type].join('\n') + '))();'; //}; constructors[type_name] = Type; // User-defined methods function post_user_defines(context) { if(Object.prototype.hasOwnProperty.call(_user_defined_methods, type_name)) { _user_defined_methods[type_name].call(context, Type, context); } } post_user_defines({'constructors':constructors, 'schema':_schema}); return constructors[type_name]; }
javascript
function create_constructor(type_name) { if(Object.prototype.hasOwnProperty.call(constructors, type_name)) { return constructors[type_name]; } if(!( Object.prototype.hasOwnProperty.call(_schema.definitions, type_name) && is.def(_schema.definitions[type_name]) )) { throw new TypeError("No definition for " + type_name); } var definition = _schema.definitions[type_name]; // ParentType is either SchemaObject or another definition var ParentType = SchemaObject; if( is.obj(definition) && is.def(definition.$ref) && string_starts_with(definition.$ref, '#/definitions/') ) { ParentType = create_constructor( definition.$ref.split('/').slice(2).join('/') ); } // FIXME: If a type has $refs, we should create a copy of schema which defines all those $refs. // Currently just copies schema and changes it to point our definition. Not ideal solution. var copy_definition = JSON.parse(JSON.stringify(_schema)); copy_definition.oneOf = [{"$ref": '#/definitions/'+type_name }]; /* This is our real constructor which will be called in `new Function()` */ function _constructor(self, opts) { var tmp; // Check opts validity var validity = SchemaObject.validate(opts, copy_definition); if(!validity.valid) { throw new TypeError("bad argument: " + util.inspect(validity) ); } // Call parent constructors ParentType.call(self, opts); // Call custom constructors //util.debug( util.inspect( _user_defined_constructors )); if(Object.prototype.hasOwnProperty.call(_user_defined_constructors, type_name)) { tmp = _user_defined_constructors[type_name].call(self, opts); if(is.def(tmp)) { SchemaObject.prototype._setValueOf.call(self, tmp); } //util.debug( util.inspect( tmp ) ); } // Setup getters and setters if schema has properties //util.debug( "\ndefinition = \n----\n" + util.inspect( definition ) + "\n----\n\n" ); if(definition && definition.properties) { Object.getOwnPropertyNames(definition.properties).forEach(function(key) { self.__defineGetter__(key, function(){ return self.valueOf()[key]; }); self.__defineSetter__(key, function(val){ // FIXME: Implement value validation and do not use `.valueOf()`! self.valueOf()[key] = val; }); }); } } var func_name = escape_func_name(type_name); // JavaScript does not support better way to change function names... var code = [ 'function '+func_name+' (opts) {', ' if(!(this instanceof '+func_name+')) {', ' return new '+func_name+'(opts);', ' };', ' _constructor.call(this, this, opts);', '};' ]; var Type = (new Function('_constructor', 'return '+code.join('\n')))(_constructor); util.inherits(Type, ParentType); /* Returns source code for type */ //Type.toSource = function() { // return '(new Function(\'' + [''+_constructor, ''+Type].join('\n') + '))();'; //}; constructors[type_name] = Type; // User-defined methods function post_user_defines(context) { if(Object.prototype.hasOwnProperty.call(_user_defined_methods, type_name)) { _user_defined_methods[type_name].call(context, Type, context); } } post_user_defines({'constructors':constructors, 'schema':_schema}); return constructors[type_name]; }
[ "function", "create_constructor", "(", "type_name", ")", "{", "if", "(", "Object", ".", "prototype", ".", "hasOwnProperty", ".", "call", "(", "constructors", ",", "type_name", ")", ")", "{", "return", "constructors", "[", "type_name", "]", ";", "}", "if", "(", "!", "(", "Object", ".", "prototype", ".", "hasOwnProperty", ".", "call", "(", "_schema", ".", "definitions", ",", "type_name", ")", "&&", "is", ".", "def", "(", "_schema", ".", "definitions", "[", "type_name", "]", ")", ")", ")", "{", "throw", "new", "TypeError", "(", "\"No definition for \"", "+", "type_name", ")", ";", "}", "var", "definition", "=", "_schema", ".", "definitions", "[", "type_name", "]", ";", "var", "ParentType", "=", "SchemaObject", ";", "if", "(", "is", ".", "obj", "(", "definition", ")", "&&", "is", ".", "def", "(", "definition", ".", "$ref", ")", "&&", "string_starts_with", "(", "definition", ".", "$ref", ",", "'#/definitions/'", ")", ")", "{", "ParentType", "=", "create_constructor", "(", "definition", ".", "$ref", ".", "split", "(", "'/'", ")", ".", "slice", "(", "2", ")", ".", "join", "(", "'/'", ")", ")", ";", "}", "var", "copy_definition", "=", "JSON", ".", "parse", "(", "JSON", ".", "stringify", "(", "_schema", ")", ")", ";", "copy_definition", ".", "oneOf", "=", "[", "{", "\"$ref\"", ":", "'#/definitions/'", "+", "type_name", "}", "]", ";", "function", "_constructor", "(", "self", ",", "opts", ")", "{", "var", "tmp", ";", "var", "validity", "=", "SchemaObject", ".", "validate", "(", "opts", ",", "copy_definition", ")", ";", "if", "(", "!", "validity", ".", "valid", ")", "{", "throw", "new", "TypeError", "(", "\"bad argument: \"", "+", "util", ".", "inspect", "(", "validity", ")", ")", ";", "}", "ParentType", ".", "call", "(", "self", ",", "opts", ")", ";", "if", "(", "Object", ".", "prototype", ".", "hasOwnProperty", ".", "call", "(", "_user_defined_constructors", ",", "type_name", ")", ")", "{", "tmp", "=", "_user_defined_constructors", "[", "type_name", "]", ".", "call", "(", "self", ",", "opts", ")", ";", "if", "(", "is", ".", "def", "(", "tmp", ")", ")", "{", "SchemaObject", ".", "prototype", ".", "_setValueOf", ".", "call", "(", "self", ",", "tmp", ")", ";", "}", "}", "if", "(", "definition", "&&", "definition", ".", "properties", ")", "{", "Object", ".", "getOwnPropertyNames", "(", "definition", ".", "properties", ")", ".", "forEach", "(", "function", "(", "key", ")", "{", "self", ".", "__defineGetter__", "(", "key", ",", "function", "(", ")", "{", "return", "self", ".", "valueOf", "(", ")", "[", "key", "]", ";", "}", ")", ";", "self", ".", "__defineSetter__", "(", "key", ",", "function", "(", "val", ")", "{", "self", ".", "valueOf", "(", ")", "[", "key", "]", "=", "val", ";", "}", ")", ";", "}", ")", ";", "}", "}", "var", "func_name", "=", "escape_func_name", "(", "type_name", ")", ";", "var", "code", "=", "[", "'function '", "+", "func_name", "+", "' (opts) {'", ",", "'\tif(!(this instanceof '", "+", "func_name", "+", "')) {'", ",", "'\t\treturn new '", "+", "func_name", "+", "'(opts);'", ",", "'\t};'", ",", "'\t_constructor.call(this, this, opts);'", ",", "'};'", "]", ";", "var", "Type", "=", "(", "new", "Function", "(", "'_constructor'", ",", "'return '", "+", "code", ".", "join", "(", "'\\n'", ")", ")", ")", "\\n", ";", "(", "_constructor", ")", "util", ".", "inherits", "(", "Type", ",", "ParentType", ")", ";", "constructors", "[", "type_name", "]", "=", "Type", ";", "function", "post_user_defines", "(", "context", ")", "{", "if", "(", "Object", ".", "prototype", ".", "hasOwnProperty", ".", "call", "(", "_user_defined_methods", ",", "type_name", ")", ")", "{", "_user_defined_methods", "[", "type_name", "]", ".", "call", "(", "context", ",", "Type", ",", "context", ")", ";", "}", "}", "post_user_defines", "(", "{", "'constructors'", ":", "constructors", ",", "'schema'", ":", "_schema", "}", ")", ";", "}" ]
Creates a new constructor unless it's created already
[ "Creates", "a", "new", "constructor", "unless", "it", "s", "created", "already" ]
c6d52b3cbefc904e89cab5ad3c4ecfa26aaf4ea6
https://github.com/sendanor/json-schema-orm/blob/c6d52b3cbefc904e89cab5ad3c4ecfa26aaf4ea6/src/build.js#L40-L132
train
sendanor/json-schema-orm
src/build.js
post_user_defines
function post_user_defines(context) { if(Object.prototype.hasOwnProperty.call(_user_defined_methods, type_name)) { _user_defined_methods[type_name].call(context, Type, context); } }
javascript
function post_user_defines(context) { if(Object.prototype.hasOwnProperty.call(_user_defined_methods, type_name)) { _user_defined_methods[type_name].call(context, Type, context); } }
[ "function", "post_user_defines", "(", "context", ")", "{", "if", "(", "Object", ".", "prototype", ".", "hasOwnProperty", ".", "call", "(", "_user_defined_methods", ",", "type_name", ")", ")", "{", "_user_defined_methods", "[", "type_name", "]", ".", "call", "(", "context", ",", "Type", ",", "context", ")", ";", "}", "}" ]
User-defined methods
[ "User", "-", "defined", "methods" ]
c6d52b3cbefc904e89cab5ad3c4ecfa26aaf4ea6
https://github.com/sendanor/json-schema-orm/blob/c6d52b3cbefc904e89cab5ad3c4ecfa26aaf4ea6/src/build.js#L123-L127
train
cwrc/CWRC-PublicEntityDialogs
src/index.js
setEnabledSources
function setEnabledSources(config) { for (let source in config) { setSourceEnabled(source, config[source]); } haveSourcesBeenSelected = true; }
javascript
function setEnabledSources(config) { for (let source in config) { setSourceEnabled(source, config[source]); } haveSourcesBeenSelected = true; }
[ "function", "setEnabledSources", "(", "config", ")", "{", "for", "(", "let", "source", "in", "config", ")", "{", "setSourceEnabled", "(", "source", ",", "config", "[", "source", "]", ")", ";", "}", "haveSourcesBeenSelected", "=", "true", ";", "}" ]
expects an object whose keys are source names and whose values are boolean
[ "expects", "an", "object", "whose", "keys", "are", "source", "names", "and", "whose", "values", "are", "boolean" ]
4d828b8f184f8c86f5abbc92cc8e4909ee22b7b4
https://github.com/cwrc/CWRC-PublicEntityDialogs/blob/4d828b8f184f8c86f5abbc92cc8e4909ee22b7b4/src/index.js#L312-L317
train
sehrope/node-pg-spice
index.js
convertParamValues
function convertParamValues(parsedSql, values) { var ret = []; _.each(parsedSql.params, function(param) { if( !_.has(values, param.name) ) { throw new Error("No value found for parameter: " + param.name); } ret.push(values[param.name]); }); return ret; }
javascript
function convertParamValues(parsedSql, values) { var ret = []; _.each(parsedSql.params, function(param) { if( !_.has(values, param.name) ) { throw new Error("No value found for parameter: " + param.name); } ret.push(values[param.name]); }); return ret; }
[ "function", "convertParamValues", "(", "parsedSql", ",", "values", ")", "{", "var", "ret", "=", "[", "]", ";", "_", ".", "each", "(", "parsedSql", ".", "params", ",", "function", "(", "param", ")", "{", "if", "(", "!", "_", ".", "has", "(", "values", ",", "param", ".", "name", ")", ")", "{", "throw", "new", "Error", "(", "\"No value found for parameter: \"", "+", "param", ".", "name", ")", ";", "}", "ret", ".", "push", "(", "values", "[", "param", ".", "name", "]", ")", ";", "}", ")", ";", "return", "ret", ";", "}" ]
Converts parameter values from object to an array. Parameter value indexes come from the parsedSql object and a given parameter may appear in multiple positions.
[ "Converts", "parameter", "values", "from", "object", "to", "an", "array", ".", "Parameter", "value", "indexes", "come", "from", "the", "parsedSql", "object", "and", "a", "given", "parameter", "may", "appear", "in", "multiple", "positions", "." ]
943bac3aa0db5c4ac1aa5bc8abb0549950292a63
https://github.com/sehrope/node-pg-spice/blob/943bac3aa0db5c4ac1aa5bc8abb0549950292a63/index.js#L262-L271
train
openmason/cloudd
lib/dag.js
function(links) { this.dependencies = _buildDependencies(links); this.tasks = graph.tsort(this.dependencies).reverse(); this.index = 0; }
javascript
function(links) { this.dependencies = _buildDependencies(links); this.tasks = graph.tsort(this.dependencies).reverse(); this.index = 0; }
[ "function", "(", "links", ")", "{", "this", ".", "dependencies", "=", "_buildDependencies", "(", "links", ")", ";", "this", ".", "tasks", "=", "graph", ".", "tsort", "(", "this", ".", "dependencies", ")", ".", "reverse", "(", ")", ";", "this", ".", "index", "=", "0", ";", "}" ]
DAG - routines related to DAG go here
[ "DAG", "-", "routines", "related", "to", "DAG", "go", "here" ]
207bad115a0a4148f35e238fd1121a30b8f0bd5a
https://github.com/openmason/cloudd/blob/207bad115a0a4148f35e238fd1121a30b8f0bd5a/lib/dag.js#L12-L16
train
mozilla/grunt-l10n-lint
lib/check-translation.js
function (tagName, tagAttributes) { if (this._done) { return; } this._openElementStack.push(tagName); try { this._errorIfUnexpectedTag(tagName); for (var attributeName in tagAttributes) { var attributeValue = tagAttributes[attributeName]; this._errorIfUnexpectedAttribute(tagName, attributeName); this._errorIfUnexpectedAttributeValue(tagName, attributeName, attributeValue); } } catch (err) { this._finish(err); } }
javascript
function (tagName, tagAttributes) { if (this._done) { return; } this._openElementStack.push(tagName); try { this._errorIfUnexpectedTag(tagName); for (var attributeName in tagAttributes) { var attributeValue = tagAttributes[attributeName]; this._errorIfUnexpectedAttribute(tagName, attributeName); this._errorIfUnexpectedAttributeValue(tagName, attributeName, attributeValue); } } catch (err) { this._finish(err); } }
[ "function", "(", "tagName", ",", "tagAttributes", ")", "{", "if", "(", "this", ".", "_done", ")", "{", "return", ";", "}", "this", ".", "_openElementStack", ".", "push", "(", "tagName", ")", ";", "try", "{", "this", ".", "_errorIfUnexpectedTag", "(", "tagName", ")", ";", "for", "(", "var", "attributeName", "in", "tagAttributes", ")", "{", "var", "attributeValue", "=", "tagAttributes", "[", "attributeName", "]", ";", "this", ".", "_errorIfUnexpectedAttribute", "(", "tagName", ",", "attributeName", ")", ";", "this", ".", "_errorIfUnexpectedAttributeValue", "(", "tagName", ",", "attributeName", ",", "attributeValue", ")", ";", "}", "}", "catch", "(", "err", ")", "{", "this", ".", "_finish", "(", "err", ")", ";", "}", "}" ]
Check all tags, attributes, and attriute values against the allowed list in expectedTagsData.
[ "Check", "all", "tags", "attributes", "and", "attriute", "values", "against", "the", "allowed", "list", "in", "expectedTagsData", "." ]
287f5cd3b3a6af4fabc524ce4a6086ce8fd17a89
https://github.com/mozilla/grunt-l10n-lint/blob/287f5cd3b3a6af4fabc524ce4a6086ce8fd17a89/lib/check-translation.js#L212-L231
train
WorldMobileCoin/wmcc-core
src/utils/lru.js
LRUItem
function LRUItem(key, value) { this.key = key; this.value = value; this.next = null; this.prev = null; }
javascript
function LRUItem(key, value) { this.key = key; this.value = value; this.next = null; this.prev = null; }
[ "function", "LRUItem", "(", "key", ",", "value", ")", "{", "this", ".", "key", "=", "key", ";", "this", ".", "value", "=", "value", ";", "this", ".", "next", "=", "null", ";", "this", ".", "prev", "=", "null", ";", "}" ]
Represents an LRU item. @alias module:utils.LRUItem @constructor @private @param {String} key @param {Object} value
[ "Represents", "an", "LRU", "item", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/utils/lru.js#L424-L429
train
WorldMobileCoin/wmcc-core
src/script/scripterror.js
ScriptError
function ScriptError(code, op, ip) { if (!(this instanceof ScriptError)) return new ScriptError(code, op, ip); Error.call(this); this.type = 'ScriptError'; this.code = code; this.message = code; this.op = -1; this.ip = -1; if (typeof op === 'string') { this.message = op; } else if (op) { this.message = `${code} (op=${op.toSymbol()}, ip=${ip})`; this.op = op.value; this.ip = ip; } if (Error.captureStackTrace) Error.captureStackTrace(this, ScriptError); }
javascript
function ScriptError(code, op, ip) { if (!(this instanceof ScriptError)) return new ScriptError(code, op, ip); Error.call(this); this.type = 'ScriptError'; this.code = code; this.message = code; this.op = -1; this.ip = -1; if (typeof op === 'string') { this.message = op; } else if (op) { this.message = `${code} (op=${op.toSymbol()}, ip=${ip})`; this.op = op.value; this.ip = ip; } if (Error.captureStackTrace) Error.captureStackTrace(this, ScriptError); }
[ "function", "ScriptError", "(", "code", ",", "op", ",", "ip", ")", "{", "if", "(", "!", "(", "this", "instanceof", "ScriptError", ")", ")", "return", "new", "ScriptError", "(", "code", ",", "op", ",", "ip", ")", ";", "Error", ".", "call", "(", "this", ")", ";", "this", ".", "type", "=", "'ScriptError'", ";", "this", ".", "code", "=", "code", ";", "this", ".", "message", "=", "code", ";", "this", ".", "op", "=", "-", "1", ";", "this", ".", "ip", "=", "-", "1", ";", "if", "(", "typeof", "op", "===", "'string'", ")", "{", "this", ".", "message", "=", "op", ";", "}", "else", "if", "(", "op", ")", "{", "this", ".", "message", "=", "`", "${", "code", "}", "${", "op", ".", "toSymbol", "(", ")", "}", "${", "ip", "}", "`", ";", "this", ".", "op", "=", "op", ".", "value", ";", "this", ".", "ip", "=", "ip", ";", "}", "if", "(", "Error", ".", "captureStackTrace", ")", "Error", ".", "captureStackTrace", "(", "this", ",", "ScriptError", ")", ";", "}" ]
An error thrown from the scripting system, potentially pertaining to Script execution. @alias module:script.ScriptError @constructor @extends Error @param {String} code - Error code. @param {Opcode} op - Opcode. @param {Number?} ip - Instruction pointer. @property {String} message - Error message. @property {String} code - Original code passed in. @property {Number} op - Opcode. @property {Number} ip - Instruction pointer.
[ "An", "error", "thrown", "from", "the", "scripting", "system", "potentially", "pertaining", "to", "Script", "execution", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/script/scripterror.js#L28-L50
train
WorldMobileCoin/wmcc-core
src/protocol/network.js
Network
function Network(options) { if (!(this instanceof Network)) return new Network(options); assert(!Network[options.type], 'Cannot create two networks.'); this.type = options.type; this.seeds = options.seeds; this.magic = options.magic; this.port = options.port; this.checkpointMap = options.checkpointMap; this.lastCheckpoint = options.lastCheckpoint; this.checkpoints = []; this.halvingInterval = options.halvingInterval; this.genesis = options.genesis; this.genesisBlock = options.genesisBlock; this.pow = options.pow; this.block = options.block; this.bip30 = options.bip30; this.activationThreshold = options.activationThreshold; this.minerWindow = options.minerWindow; this.deployments = options.deployments; this.deploys = options.deploys; this.unknownBits = ~consensus.VERSION_TOP_MASK; this.keyPrefix = options.keyPrefix; this.addressPrefix = options.addressPrefix; this.requireStandard = options.requireStandard; this.rpcPort = options.rpcPort; this.minRelay = options.minRelay; this.feeRate = options.feeRate; this.maxFeeRate = options.maxFeeRate; this.selfConnect = options.selfConnect; this.requestMempool = options.requestMempool; this.time = new TimeData(); this._init(); }
javascript
function Network(options) { if (!(this instanceof Network)) return new Network(options); assert(!Network[options.type], 'Cannot create two networks.'); this.type = options.type; this.seeds = options.seeds; this.magic = options.magic; this.port = options.port; this.checkpointMap = options.checkpointMap; this.lastCheckpoint = options.lastCheckpoint; this.checkpoints = []; this.halvingInterval = options.halvingInterval; this.genesis = options.genesis; this.genesisBlock = options.genesisBlock; this.pow = options.pow; this.block = options.block; this.bip30 = options.bip30; this.activationThreshold = options.activationThreshold; this.minerWindow = options.minerWindow; this.deployments = options.deployments; this.deploys = options.deploys; this.unknownBits = ~consensus.VERSION_TOP_MASK; this.keyPrefix = options.keyPrefix; this.addressPrefix = options.addressPrefix; this.requireStandard = options.requireStandard; this.rpcPort = options.rpcPort; this.minRelay = options.minRelay; this.feeRate = options.feeRate; this.maxFeeRate = options.maxFeeRate; this.selfConnect = options.selfConnect; this.requestMempool = options.requestMempool; this.time = new TimeData(); this._init(); }
[ "function", "Network", "(", "options", ")", "{", "if", "(", "!", "(", "this", "instanceof", "Network", ")", ")", "return", "new", "Network", "(", "options", ")", ";", "assert", "(", "!", "Network", "[", "options", ".", "type", "]", ",", "'Cannot create two networks.'", ")", ";", "this", ".", "type", "=", "options", ".", "type", ";", "this", ".", "seeds", "=", "options", ".", "seeds", ";", "this", ".", "magic", "=", "options", ".", "magic", ";", "this", ".", "port", "=", "options", ".", "port", ";", "this", ".", "checkpointMap", "=", "options", ".", "checkpointMap", ";", "this", ".", "lastCheckpoint", "=", "options", ".", "lastCheckpoint", ";", "this", ".", "checkpoints", "=", "[", "]", ";", "this", ".", "halvingInterval", "=", "options", ".", "halvingInterval", ";", "this", ".", "genesis", "=", "options", ".", "genesis", ";", "this", ".", "genesisBlock", "=", "options", ".", "genesisBlock", ";", "this", ".", "pow", "=", "options", ".", "pow", ";", "this", ".", "block", "=", "options", ".", "block", ";", "this", ".", "bip30", "=", "options", ".", "bip30", ";", "this", ".", "activationThreshold", "=", "options", ".", "activationThreshold", ";", "this", ".", "minerWindow", "=", "options", ".", "minerWindow", ";", "this", ".", "deployments", "=", "options", ".", "deployments", ";", "this", ".", "deploys", "=", "options", ".", "deploys", ";", "this", ".", "unknownBits", "=", "~", "consensus", ".", "VERSION_TOP_MASK", ";", "this", ".", "keyPrefix", "=", "options", ".", "keyPrefix", ";", "this", ".", "addressPrefix", "=", "options", ".", "addressPrefix", ";", "this", ".", "requireStandard", "=", "options", ".", "requireStandard", ";", "this", ".", "rpcPort", "=", "options", ".", "rpcPort", ";", "this", ".", "minRelay", "=", "options", ".", "minRelay", ";", "this", ".", "feeRate", "=", "options", ".", "feeRate", ";", "this", ".", "maxFeeRate", "=", "options", ".", "maxFeeRate", ";", "this", ".", "selfConnect", "=", "options", ".", "selfConnect", ";", "this", ".", "requestMempool", "=", "options", ".", "requestMempool", ";", "this", ".", "time", "=", "new", "TimeData", "(", ")", ";", "this", ".", "_init", "(", ")", ";", "}" ]
Represents a network. @alias module:protocol.Network @constructor @param {Object|NetworkType} options - See {@link module:network}.
[ "Represents", "a", "network", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/protocol/network.js#L27-L63
train
lukebond/json-override
json-override.js
overwriteKeys
function overwriteKeys(baseObject, overrideObject, createNew) { if (!baseObject) { baseObject = {}; } if (createNew) { baseObject = JSON.parse(JSON.stringify(baseObject)); } Object.keys(overrideObject).forEach(function(key) { if (isObjectAndNotArray(baseObject[key]) && isObjectAndNotArray(overrideObject[key])) { overwriteKeys(baseObject[key], overrideObject[key]); } else { baseObject[key] = overrideObject[key]; } }); return baseObject; }
javascript
function overwriteKeys(baseObject, overrideObject, createNew) { if (!baseObject) { baseObject = {}; } if (createNew) { baseObject = JSON.parse(JSON.stringify(baseObject)); } Object.keys(overrideObject).forEach(function(key) { if (isObjectAndNotArray(baseObject[key]) && isObjectAndNotArray(overrideObject[key])) { overwriteKeys(baseObject[key], overrideObject[key]); } else { baseObject[key] = overrideObject[key]; } }); return baseObject; }
[ "function", "overwriteKeys", "(", "baseObject", ",", "overrideObject", ",", "createNew", ")", "{", "if", "(", "!", "baseObject", ")", "{", "baseObject", "=", "{", "}", ";", "}", "if", "(", "createNew", ")", "{", "baseObject", "=", "JSON", ".", "parse", "(", "JSON", ".", "stringify", "(", "baseObject", ")", ")", ";", "}", "Object", ".", "keys", "(", "overrideObject", ")", ".", "forEach", "(", "function", "(", "key", ")", "{", "if", "(", "isObjectAndNotArray", "(", "baseObject", "[", "key", "]", ")", "&&", "isObjectAndNotArray", "(", "overrideObject", "[", "key", "]", ")", ")", "{", "overwriteKeys", "(", "baseObject", "[", "key", "]", ",", "overrideObject", "[", "key", "]", ")", ";", "}", "else", "{", "baseObject", "[", "key", "]", "=", "overrideObject", "[", "key", "]", ";", "}", "}", ")", ";", "return", "baseObject", ";", "}" ]
'createNew' defaults to false
[ "createNew", "defaults", "to", "false" ]
2a3403765de6350a231e7ec41788f71008ca8a17
https://github.com/lukebond/json-override/blob/2a3403765de6350a231e7ec41788f71008ca8a17/json-override.js#L6-L22
train
gsdriver/blackjack-strategy
src/Suggestion.js
ShouldPlayerStand
function ShouldPlayerStand(playerCards, dealerCard, handValue, handCount, options) { var shouldStand = false; if (handValue.soft) { // Don't stand until you hit 18 if (handValue.total > 18) { shouldStand = true; } else if (handValue.total == 18) { // Stand against dealer 2-8, and against a dealer Ace in single deck if they dealer will stand on soft 17 shouldStand = ((dealerCard >= 2) && (dealerCard <= 8)) || ((dealerCard == 1) && (options.numberOfDecks == 1) && !options.hitSoft17); } } else { // Stand on 17 or above if (handValue.total > 16) { shouldStand = true; } else if (handValue.total > 12) { // 13-16 you should stand against dealer 2-6 shouldStand = (dealerCard >= 2) && (dealerCard <= 6); } else if (handValue.total == 12) { // Stand on dealer 4-6 shouldStand = (dealerCard >= 4) && (dealerCard <= 6); } // Advanced option - in single deck a pair of 7s should stand against a dealer 10 if ((options.strategyComplexity != "simple") && (handValue.total == 14) && (playerCards[0] == 7) && (dealerCard == 10) && (options.numberOfDecks == 1)) { shouldStand = true; } } return shouldStand; }
javascript
function ShouldPlayerStand(playerCards, dealerCard, handValue, handCount, options) { var shouldStand = false; if (handValue.soft) { // Don't stand until you hit 18 if (handValue.total > 18) { shouldStand = true; } else if (handValue.total == 18) { // Stand against dealer 2-8, and against a dealer Ace in single deck if they dealer will stand on soft 17 shouldStand = ((dealerCard >= 2) && (dealerCard <= 8)) || ((dealerCard == 1) && (options.numberOfDecks == 1) && !options.hitSoft17); } } else { // Stand on 17 or above if (handValue.total > 16) { shouldStand = true; } else if (handValue.total > 12) { // 13-16 you should stand against dealer 2-6 shouldStand = (dealerCard >= 2) && (dealerCard <= 6); } else if (handValue.total == 12) { // Stand on dealer 4-6 shouldStand = (dealerCard >= 4) && (dealerCard <= 6); } // Advanced option - in single deck a pair of 7s should stand against a dealer 10 if ((options.strategyComplexity != "simple") && (handValue.total == 14) && (playerCards[0] == 7) && (dealerCard == 10) && (options.numberOfDecks == 1)) { shouldStand = true; } } return shouldStand; }
[ "function", "ShouldPlayerStand", "(", "playerCards", ",", "dealerCard", ",", "handValue", ",", "handCount", ",", "options", ")", "{", "var", "shouldStand", "=", "false", ";", "if", "(", "handValue", ".", "soft", ")", "{", "if", "(", "handValue", ".", "total", ">", "18", ")", "{", "shouldStand", "=", "true", ";", "}", "else", "if", "(", "handValue", ".", "total", "==", "18", ")", "{", "shouldStand", "=", "(", "(", "dealerCard", ">=", "2", ")", "&&", "(", "dealerCard", "<=", "8", ")", ")", "||", "(", "(", "dealerCard", "==", "1", ")", "&&", "(", "options", ".", "numberOfDecks", "==", "1", ")", "&&", "!", "options", ".", "hitSoft17", ")", ";", "}", "}", "else", "{", "if", "(", "handValue", ".", "total", ">", "16", ")", "{", "shouldStand", "=", "true", ";", "}", "else", "if", "(", "handValue", ".", "total", ">", "12", ")", "{", "shouldStand", "=", "(", "dealerCard", ">=", "2", ")", "&&", "(", "dealerCard", "<=", "6", ")", ";", "}", "else", "if", "(", "handValue", ".", "total", "==", "12", ")", "{", "shouldStand", "=", "(", "dealerCard", ">=", "4", ")", "&&", "(", "dealerCard", "<=", "6", ")", ";", "}", "if", "(", "(", "options", ".", "strategyComplexity", "!=", "\"simple\"", ")", "&&", "(", "handValue", ".", "total", "==", "14", ")", "&&", "(", "playerCards", "[", "0", "]", "==", "7", ")", "&&", "(", "dealerCard", "==", "10", ")", "&&", "(", "options", ".", "numberOfDecks", "==", "1", ")", ")", "{", "shouldStand", "=", "true", ";", "}", "}", "return", "shouldStand", ";", "}" ]
Stand Strategy Note that we've already checkd other actions such as double, split, and surrender So at this point we're only assessing whether you should stand as opposed to hitting
[ "Stand", "Strategy", "Note", "that", "we", "ve", "already", "checkd", "other", "actions", "such", "as", "double", "split", "and", "surrender", "So", "at", "this", "point", "we", "re", "only", "assessing", "whether", "you", "should", "stand", "as", "opposed", "to", "hitting" ]
dfcb976ab9bb33c74c24c9bacf369e8ffb6506f3
https://github.com/gsdriver/blackjack-strategy/blob/dfcb976ab9bb33c74c24c9bacf369e8ffb6506f3/src/Suggestion.js#L524-L568
train
WorldMobileCoin/wmcc-core
src/net/pool.js
Pool
function Pool(options) { if (!(this instanceof Pool)) return new Pool(options); AsyncObject.call(this); this.options = new PoolOptions(options); this.network = this.options.network; this.logger = this.options.logger.context('net'); this.chain = this.options.chain; this.mempool = this.options.mempool; this.server = this.options.createServer(); this.nonces = this.options.nonces; this.locker = new Lock(true); this.connected = false; this.disconnecting = false; this.syncing = false; this.spvFilter = null; this.txFilter = null; this.blockMap = new Set(); this.txMap = new Set(); this.compactBlocks = new Set(); this.invMap = new Map(); this.pendingFilter = null; this.pendingRefill = null; this.checkpoints = false; this.headerChain = new List(); this.headerNext = null; this.headerTip = null; this.peers = new PeerList(); this.authdb = new BIP150.AuthDB(this.options); this.hosts = new HostList(this.options); this.id = 0; if (this.options.spv) this.spvFilter = Bloom.fromRate(20000, 0.001, Bloom.flags.ALL); if (!this.options.mempool) this.txFilter = new RollingFilter(50000, 0.000001); this._init(); }
javascript
function Pool(options) { if (!(this instanceof Pool)) return new Pool(options); AsyncObject.call(this); this.options = new PoolOptions(options); this.network = this.options.network; this.logger = this.options.logger.context('net'); this.chain = this.options.chain; this.mempool = this.options.mempool; this.server = this.options.createServer(); this.nonces = this.options.nonces; this.locker = new Lock(true); this.connected = false; this.disconnecting = false; this.syncing = false; this.spvFilter = null; this.txFilter = null; this.blockMap = new Set(); this.txMap = new Set(); this.compactBlocks = new Set(); this.invMap = new Map(); this.pendingFilter = null; this.pendingRefill = null; this.checkpoints = false; this.headerChain = new List(); this.headerNext = null; this.headerTip = null; this.peers = new PeerList(); this.authdb = new BIP150.AuthDB(this.options); this.hosts = new HostList(this.options); this.id = 0; if (this.options.spv) this.spvFilter = Bloom.fromRate(20000, 0.001, Bloom.flags.ALL); if (!this.options.mempool) this.txFilter = new RollingFilter(50000, 0.000001); this._init(); }
[ "function", "Pool", "(", "options", ")", "{", "if", "(", "!", "(", "this", "instanceof", "Pool", ")", ")", "return", "new", "Pool", "(", "options", ")", ";", "AsyncObject", ".", "call", "(", "this", ")", ";", "this", ".", "options", "=", "new", "PoolOptions", "(", "options", ")", ";", "this", ".", "network", "=", "this", ".", "options", ".", "network", ";", "this", ".", "logger", "=", "this", ".", "options", ".", "logger", ".", "context", "(", "'net'", ")", ";", "this", ".", "chain", "=", "this", ".", "options", ".", "chain", ";", "this", ".", "mempool", "=", "this", ".", "options", ".", "mempool", ";", "this", ".", "server", "=", "this", ".", "options", ".", "createServer", "(", ")", ";", "this", ".", "nonces", "=", "this", ".", "options", ".", "nonces", ";", "this", ".", "locker", "=", "new", "Lock", "(", "true", ")", ";", "this", ".", "connected", "=", "false", ";", "this", ".", "disconnecting", "=", "false", ";", "this", ".", "syncing", "=", "false", ";", "this", ".", "spvFilter", "=", "null", ";", "this", ".", "txFilter", "=", "null", ";", "this", ".", "blockMap", "=", "new", "Set", "(", ")", ";", "this", ".", "txMap", "=", "new", "Set", "(", ")", ";", "this", ".", "compactBlocks", "=", "new", "Set", "(", ")", ";", "this", ".", "invMap", "=", "new", "Map", "(", ")", ";", "this", ".", "pendingFilter", "=", "null", ";", "this", ".", "pendingRefill", "=", "null", ";", "this", ".", "checkpoints", "=", "false", ";", "this", ".", "headerChain", "=", "new", "List", "(", ")", ";", "this", ".", "headerNext", "=", "null", ";", "this", ".", "headerTip", "=", "null", ";", "this", ".", "peers", "=", "new", "PeerList", "(", ")", ";", "this", ".", "authdb", "=", "new", "BIP150", ".", "AuthDB", "(", "this", ".", "options", ")", ";", "this", ".", "hosts", "=", "new", "HostList", "(", "this", ".", "options", ")", ";", "this", ".", "id", "=", "0", ";", "if", "(", "this", ".", "options", ".", "spv", ")", "this", ".", "spvFilter", "=", "Bloom", ".", "fromRate", "(", "20000", ",", "0.001", ",", "Bloom", ".", "flags", ".", "ALL", ")", ";", "if", "(", "!", "this", ".", "options", ".", "mempool", ")", "this", ".", "txFilter", "=", "new", "RollingFilter", "(", "50000", ",", "0.000001", ")", ";", "this", ".", "_init", "(", ")", ";", "}" ]
A pool of peers for handling all network activity. @alias module:net.Pool @constructor @param {Object} options @param {Chain} options.chain @param {Mempool?} options.mempool @param {Number?} [options.maxOutbound=8] - Maximum number of peers. @param {Boolean?} options.spv - Do an SPV sync. @param {Boolean?} options.noRelay - Whether to ask for relayed transactions. @param {Number?} [options.feeRate] - Fee filter rate. @param {Number?} [options.invTimeout=60000] - Timeout for broadcasted objects. @param {Boolean?} options.listen - Whether to spin up a server socket and listen for peers. @param {Boolean?} options.selfish - A selfish pool. Will not serve blocks, headers, hashes, utxos, or transactions to peers. @param {Boolean?} options.broadcast - Whether to automatically broadcast transactions accepted to our mempool. @param {String[]} options.seeds @param {Function?} options.createSocket - Custom function to create a socket. Must accept (port, host) and return a node-like socket. @param {Function?} options.createServer - Custom function to create a server. Must return a node-like server. @emits Pool#block @emits Pool#tx @emits Pool#peer @emits Pool#open @emits Pool#close @emits Pool#error @emits Pool#reject
[ "A", "pool", "of", "peers", "for", "handling", "all", "network", "activity", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/net/pool.js#L79-L124
train
WorldMobileCoin/wmcc-core
src/primitives/txmeta.js
TXMeta
function TXMeta(options) { if (!(this instanceof TXMeta)) return new TXMeta(options); this.tx = new TX(); this.mtime = util.now(); this.height = -1; this.block = null; this.time = 0; this.index = -1; if (options) this.fromOptions(options); }
javascript
function TXMeta(options) { if (!(this instanceof TXMeta)) return new TXMeta(options); this.tx = new TX(); this.mtime = util.now(); this.height = -1; this.block = null; this.time = 0; this.index = -1; if (options) this.fromOptions(options); }
[ "function", "TXMeta", "(", "options", ")", "{", "if", "(", "!", "(", "this", "instanceof", "TXMeta", ")", ")", "return", "new", "TXMeta", "(", "options", ")", ";", "this", ".", "tx", "=", "new", "TX", "(", ")", ";", "this", ".", "mtime", "=", "util", ".", "now", "(", ")", ";", "this", ".", "height", "=", "-", "1", ";", "this", ".", "block", "=", "null", ";", "this", ".", "time", "=", "0", ";", "this", ".", "index", "=", "-", "1", ";", "if", "(", "options", ")", "this", ".", "fromOptions", "(", "options", ")", ";", "}" ]
An extended transaction object. @alias module:primitives.TXMeta @constructor @param {Object} options
[ "An", "extended", "transaction", "object", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/primitives/txmeta.js#L26-L39
train
WorldMobileCoin/wmcc-core
src/bip70/paymentack.js
PaymentACK
function PaymentACK(options) { if (!(this instanceof PaymentACK)) return new PaymentACK(options); this.payment = new Payment(); this.memo = null; if (options) this.fromOptions(options); }
javascript
function PaymentACK(options) { if (!(this instanceof PaymentACK)) return new PaymentACK(options); this.payment = new Payment(); this.memo = null; if (options) this.fromOptions(options); }
[ "function", "PaymentACK", "(", "options", ")", "{", "if", "(", "!", "(", "this", "instanceof", "PaymentACK", ")", ")", "return", "new", "PaymentACK", "(", "options", ")", ";", "this", ".", "payment", "=", "new", "Payment", "(", ")", ";", "this", ".", "memo", "=", "null", ";", "if", "(", "options", ")", "this", ".", "fromOptions", "(", "options", ")", ";", "}" ]
Represents a BIP70 payment ack. @alias module:bip70.PaymentACK @constructor @param {Object?} options @property {Payment} payment @property {String|null} memo
[ "Represents", "a", "BIP70", "payment", "ack", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/bip70/paymentack.js#L27-L36
train
WorldMobileCoin/wmcc-core
src/crypto/sha256.js
hash256
function hash256(data) { const out = Buffer.allocUnsafe(32); ctx.init(); ctx.update(data); ctx._finish(out); ctx.init(); ctx.update(out); ctx._finish(out); return out; }
javascript
function hash256(data) { const out = Buffer.allocUnsafe(32); ctx.init(); ctx.update(data); ctx._finish(out); ctx.init(); ctx.update(out); ctx._finish(out); return out; }
[ "function", "hash256", "(", "data", ")", "{", "const", "out", "=", "Buffer", ".", "allocUnsafe", "(", "32", ")", ";", "ctx", ".", "init", "(", ")", ";", "ctx", ".", "update", "(", "data", ")", ";", "ctx", ".", "_finish", "(", "out", ")", ";", "ctx", ".", "init", "(", ")", ";", "ctx", ".", "update", "(", "out", ")", ";", "ctx", ".", "_finish", "(", "out", ")", ";", "return", "out", ";", "}" ]
Hash buffer with double sha256. @alias module:crypto/sha256.hash256 @param {Buffer} data @returns {Buffer}
[ "Hash", "buffer", "with", "double", "sha256", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/crypto/sha256.js#L367-L376
train
WorldMobileCoin/wmcc-core
src/crypto/sha256.js
hmac
function hmac(data, key) { mctx.init(key); mctx.update(data); return mctx.finish(); }
javascript
function hmac(data, key) { mctx.init(key); mctx.update(data); return mctx.finish(); }
[ "function", "hmac", "(", "data", ",", "key", ")", "{", "mctx", ".", "init", "(", "key", ")", ";", "mctx", ".", "update", "(", "data", ")", ";", "return", "mctx", ".", "finish", "(", ")", ";", "}" ]
Create a sha256 HMAC from buffer and key. @alias module:crypto/sha256.hmac @param {Buffer} data @param {Buffer} key @returns {Buffer}
[ "Create", "a", "sha256", "HMAC", "from", "buffer", "and", "key", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/crypto/sha256.js#L386-L390
train
WorldMobileCoin/wmcc-core
src/utils/bech32.js
polymod
function polymod(pre) { const b = pre >>> 25; return ((pre & 0x1ffffff) << 5) ^ (-((b >> 0) & 1) & 0x3b6a57b2) ^ (-((b >> 1) & 1) & 0x26508e6d) ^ (-((b >> 2) & 1) & 0x1ea119fa) ^ (-((b >> 3) & 1) & 0x3d4233dd) ^ (-((b >> 4) & 1) & 0x2a1462b3); }
javascript
function polymod(pre) { const b = pre >>> 25; return ((pre & 0x1ffffff) << 5) ^ (-((b >> 0) & 1) & 0x3b6a57b2) ^ (-((b >> 1) & 1) & 0x26508e6d) ^ (-((b >> 2) & 1) & 0x1ea119fa) ^ (-((b >> 3) & 1) & 0x3d4233dd) ^ (-((b >> 4) & 1) & 0x2a1462b3); }
[ "function", "polymod", "(", "pre", ")", "{", "const", "b", "=", "pre", ">>>", "25", ";", "return", "(", "(", "pre", "&", "0x1ffffff", ")", "<<", "5", ")", "^", "(", "-", "(", "(", "b", ">>", "0", ")", "&", "1", ")", "&", "0x3b6a57b2", ")", "^", "(", "-", "(", "(", "b", ">>", "1", ")", "&", "1", ")", "&", "0x26508e6d", ")", "^", "(", "-", "(", "(", "b", ">>", "2", ")", "&", "1", ")", "&", "0x1ea119fa", ")", "^", "(", "-", "(", "(", "b", ">>", "3", ")", "&", "1", ")", "&", "0x3d4233dd", ")", "^", "(", "-", "(", "(", "b", ">>", "4", ")", "&", "1", ")", "&", "0x2a1462b3", ")", ";", "}" ]
Update checksum. @ignore @param {Number} chk @returns {Number}
[ "Update", "checksum", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/utils/bech32.js#L62-L70
train
WorldMobileCoin/wmcc-core
src/utils/bech32.js
serialize
function serialize(hrp, data) { let chk = 1; let i; for (i = 0; i < hrp.length; i++) { const ch = hrp.charCodeAt(i); if ((ch >> 5) === 0) throw new Error('Invalid bech32 character.'); chk = polymod(chk) ^ (ch >> 5); } if (i + 7 + data.length > 90) throw new Error('Invalid bech32 data length.'); chk = polymod(chk); let str = ''; for (let i = 0; i < hrp.length; i++) { const ch = hrp.charCodeAt(i); chk = polymod(chk) ^ (ch & 0x1f); str += hrp[i]; } str += '1'; for (let i = 0; i < data.length; i++) { const ch = data[i]; if ((ch >> 5) !== 0) throw new Error('Invalid bech32 value.'); chk = polymod(chk) ^ ch; str += CHARSET[ch]; } for (let i = 0; i < 6; i++) chk = polymod(chk); chk ^= 1; for (let i = 0; i < 6; i++) str += CHARSET[(chk >>> ((5 - i) * 5)) & 0x1f]; return str; }
javascript
function serialize(hrp, data) { let chk = 1; let i; for (i = 0; i < hrp.length; i++) { const ch = hrp.charCodeAt(i); if ((ch >> 5) === 0) throw new Error('Invalid bech32 character.'); chk = polymod(chk) ^ (ch >> 5); } if (i + 7 + data.length > 90) throw new Error('Invalid bech32 data length.'); chk = polymod(chk); let str = ''; for (let i = 0; i < hrp.length; i++) { const ch = hrp.charCodeAt(i); chk = polymod(chk) ^ (ch & 0x1f); str += hrp[i]; } str += '1'; for (let i = 0; i < data.length; i++) { const ch = data[i]; if ((ch >> 5) !== 0) throw new Error('Invalid bech32 value.'); chk = polymod(chk) ^ ch; str += CHARSET[ch]; } for (let i = 0; i < 6; i++) chk = polymod(chk); chk ^= 1; for (let i = 0; i < 6; i++) str += CHARSET[(chk >>> ((5 - i) * 5)) & 0x1f]; return str; }
[ "function", "serialize", "(", "hrp", ",", "data", ")", "{", "let", "chk", "=", "1", ";", "let", "i", ";", "for", "(", "i", "=", "0", ";", "i", "<", "hrp", ".", "length", ";", "i", "++", ")", "{", "const", "ch", "=", "hrp", ".", "charCodeAt", "(", "i", ")", ";", "if", "(", "(", "ch", ">>", "5", ")", "===", "0", ")", "throw", "new", "Error", "(", "'Invalid bech32 character.'", ")", ";", "chk", "=", "polymod", "(", "chk", ")", "^", "(", "ch", ">>", "5", ")", ";", "}", "if", "(", "i", "+", "7", "+", "data", ".", "length", ">", "90", ")", "throw", "new", "Error", "(", "'Invalid bech32 data length.'", ")", ";", "chk", "=", "polymod", "(", "chk", ")", ";", "let", "str", "=", "''", ";", "for", "(", "let", "i", "=", "0", ";", "i", "<", "hrp", ".", "length", ";", "i", "++", ")", "{", "const", "ch", "=", "hrp", ".", "charCodeAt", "(", "i", ")", ";", "chk", "=", "polymod", "(", "chk", ")", "^", "(", "ch", "&", "0x1f", ")", ";", "str", "+=", "hrp", "[", "i", "]", ";", "}", "str", "+=", "'1'", ";", "for", "(", "let", "i", "=", "0", ";", "i", "<", "data", ".", "length", ";", "i", "++", ")", "{", "const", "ch", "=", "data", "[", "i", "]", ";", "if", "(", "(", "ch", ">>", "5", ")", "!==", "0", ")", "throw", "new", "Error", "(", "'Invalid bech32 value.'", ")", ";", "chk", "=", "polymod", "(", "chk", ")", "^", "ch", ";", "str", "+=", "CHARSET", "[", "ch", "]", ";", "}", "for", "(", "let", "i", "=", "0", ";", "i", "<", "6", ";", "i", "++", ")", "chk", "=", "polymod", "(", "chk", ")", ";", "chk", "^=", "1", ";", "for", "(", "let", "i", "=", "0", ";", "i", "<", "6", ";", "i", "++", ")", "str", "+=", "CHARSET", "[", "(", "chk", ">>>", "(", "(", "5", "-", "i", ")", "*", "5", ")", ")", "&", "0x1f", "]", ";", "return", "str", ";", "}" ]
Encode hrp and data as a bech32 string. @ignore @param {String} hrp @param {Buffer} data @returns {String}
[ "Encode", "hrp", "and", "data", "as", "a", "bech32", "string", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/utils/bech32.js#L80-L127
train
WorldMobileCoin/wmcc-core
src/utils/bech32.js
deserialize
function deserialize(str) { let dlen = 0; if (str.length < 8 || str.length > 90) throw new Error('Invalid bech32 string length.'); while (dlen < str.length && str[(str.length - 1) - dlen] !== '1') dlen++; const hlen = str.length - (1 + dlen); if (hlen < 1 || dlen < 6) throw new Error('Invalid bech32 data length.'); dlen -= 6; const data = Buffer.allocUnsafe(dlen); let chk = 1; let lower = false; let upper = false; let hrp = ''; for (let i = 0; i < hlen; i++) { let ch = str.charCodeAt(i); if (ch < 0x21 || ch > 0x7e) throw new Error('Invalid bech32 character.'); if (ch >= 0x61 && ch <= 0x7a) { lower = true; } else if (ch >= 0x41 && ch <= 0x5a) { upper = true; ch = (ch - 0x41) + 0x61; } hrp += String.fromCharCode(ch); chk = polymod(chk) ^ (ch >> 5); } chk = polymod(chk); let i; for (i = 0; i < hlen; i++) chk = polymod(chk) ^ (str.charCodeAt(i) & 0x1f); i++; while (i < str.length) { const ch = str.charCodeAt(i); const v = (ch & 0x80) ? -1 : TABLE[ch]; if (ch >= 0x61 && ch <= 0x7a) lower = true; else if (ch >= 0x41 && ch <= 0x5a) upper = true; if (v === -1) throw new Error('Invalid bech32 character.'); chk = polymod(chk) ^ v; if (i + 6 < str.length) data[i - (1 + hlen)] = v; i++; } if (lower && upper) throw new Error('Invalid bech32 casing.'); if (chk !== 1) throw new Error('Invalid bech32 checksum.'); return [hrp, data.slice(0, dlen)]; }
javascript
function deserialize(str) { let dlen = 0; if (str.length < 8 || str.length > 90) throw new Error('Invalid bech32 string length.'); while (dlen < str.length && str[(str.length - 1) - dlen] !== '1') dlen++; const hlen = str.length - (1 + dlen); if (hlen < 1 || dlen < 6) throw new Error('Invalid bech32 data length.'); dlen -= 6; const data = Buffer.allocUnsafe(dlen); let chk = 1; let lower = false; let upper = false; let hrp = ''; for (let i = 0; i < hlen; i++) { let ch = str.charCodeAt(i); if (ch < 0x21 || ch > 0x7e) throw new Error('Invalid bech32 character.'); if (ch >= 0x61 && ch <= 0x7a) { lower = true; } else if (ch >= 0x41 && ch <= 0x5a) { upper = true; ch = (ch - 0x41) + 0x61; } hrp += String.fromCharCode(ch); chk = polymod(chk) ^ (ch >> 5); } chk = polymod(chk); let i; for (i = 0; i < hlen; i++) chk = polymod(chk) ^ (str.charCodeAt(i) & 0x1f); i++; while (i < str.length) { const ch = str.charCodeAt(i); const v = (ch & 0x80) ? -1 : TABLE[ch]; if (ch >= 0x61 && ch <= 0x7a) lower = true; else if (ch >= 0x41 && ch <= 0x5a) upper = true; if (v === -1) throw new Error('Invalid bech32 character.'); chk = polymod(chk) ^ v; if (i + 6 < str.length) data[i - (1 + hlen)] = v; i++; } if (lower && upper) throw new Error('Invalid bech32 casing.'); if (chk !== 1) throw new Error('Invalid bech32 checksum.'); return [hrp, data.slice(0, dlen)]; }
[ "function", "deserialize", "(", "str", ")", "{", "let", "dlen", "=", "0", ";", "if", "(", "str", ".", "length", "<", "8", "||", "str", ".", "length", ">", "90", ")", "throw", "new", "Error", "(", "'Invalid bech32 string length.'", ")", ";", "while", "(", "dlen", "<", "str", ".", "length", "&&", "str", "[", "(", "str", ".", "length", "-", "1", ")", "-", "dlen", "]", "!==", "'1'", ")", "dlen", "++", ";", "const", "hlen", "=", "str", ".", "length", "-", "(", "1", "+", "dlen", ")", ";", "if", "(", "hlen", "<", "1", "||", "dlen", "<", "6", ")", "throw", "new", "Error", "(", "'Invalid bech32 data length.'", ")", ";", "dlen", "-=", "6", ";", "const", "data", "=", "Buffer", ".", "allocUnsafe", "(", "dlen", ")", ";", "let", "chk", "=", "1", ";", "let", "lower", "=", "false", ";", "let", "upper", "=", "false", ";", "let", "hrp", "=", "''", ";", "for", "(", "let", "i", "=", "0", ";", "i", "<", "hlen", ";", "i", "++", ")", "{", "let", "ch", "=", "str", ".", "charCodeAt", "(", "i", ")", ";", "if", "(", "ch", "<", "0x21", "||", "ch", ">", "0x7e", ")", "throw", "new", "Error", "(", "'Invalid bech32 character.'", ")", ";", "if", "(", "ch", ">=", "0x61", "&&", "ch", "<=", "0x7a", ")", "{", "lower", "=", "true", ";", "}", "else", "if", "(", "ch", ">=", "0x41", "&&", "ch", "<=", "0x5a", ")", "{", "upper", "=", "true", ";", "ch", "=", "(", "ch", "-", "0x41", ")", "+", "0x61", ";", "}", "hrp", "+=", "String", ".", "fromCharCode", "(", "ch", ")", ";", "chk", "=", "polymod", "(", "chk", ")", "^", "(", "ch", ">>", "5", ")", ";", "}", "chk", "=", "polymod", "(", "chk", ")", ";", "let", "i", ";", "for", "(", "i", "=", "0", ";", "i", "<", "hlen", ";", "i", "++", ")", "chk", "=", "polymod", "(", "chk", ")", "^", "(", "str", ".", "charCodeAt", "(", "i", ")", "&", "0x1f", ")", ";", "i", "++", ";", "while", "(", "i", "<", "str", ".", "length", ")", "{", "const", "ch", "=", "str", ".", "charCodeAt", "(", "i", ")", ";", "const", "v", "=", "(", "ch", "&", "0x80", ")", "?", "-", "1", ":", "TABLE", "[", "ch", "]", ";", "if", "(", "ch", ">=", "0x61", "&&", "ch", "<=", "0x7a", ")", "lower", "=", "true", ";", "else", "if", "(", "ch", ">=", "0x41", "&&", "ch", "<=", "0x5a", ")", "upper", "=", "true", ";", "if", "(", "v", "===", "-", "1", ")", "throw", "new", "Error", "(", "'Invalid bech32 character.'", ")", ";", "chk", "=", "polymod", "(", "chk", ")", "^", "v", ";", "if", "(", "i", "+", "6", "<", "str", ".", "length", ")", "data", "[", "i", "-", "(", "1", "+", "hlen", ")", "]", "=", "v", ";", "i", "++", ";", "}", "if", "(", "lower", "&&", "upper", ")", "throw", "new", "Error", "(", "'Invalid bech32 casing.'", ")", ";", "if", "(", "chk", "!==", "1", ")", "throw", "new", "Error", "(", "'Invalid bech32 checksum.'", ")", ";", "return", "[", "hrp", ",", "data", ".", "slice", "(", "0", ",", "dlen", ")", "]", ";", "}" ]
Decode a bech32 string. @param {String} str @returns {Array} [hrp, data]
[ "Decode", "a", "bech32", "string", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/utils/bech32.js#L135-L210
train
WorldMobileCoin/wmcc-core
src/utils/bech32.js
convert
function convert(data, output, frombits, tobits, pad, off) { const maxv = (1 << tobits) - 1; let acc = 0; let bits = 0; let j = 0; if (pad !== -1) output[j++] = pad; for (let i = off; i < data.length; i++) { const value = data[i]; if ((value >> frombits) !== 0) throw new Error('Invalid bech32 bits.'); acc = (acc << frombits) | value; bits += frombits; while (bits >= tobits) { bits -= tobits; output[j++] = (acc >>> bits) & maxv; } } if (pad !== -1) { if (bits > 0) output[j++] = (acc << (tobits - bits)) & maxv; } else { if (bits >= frombits || ((acc << (tobits - bits)) & maxv)) throw new Error('Invalid bech32 bits.'); } return output.slice(0, j); }
javascript
function convert(data, output, frombits, tobits, pad, off) { const maxv = (1 << tobits) - 1; let acc = 0; let bits = 0; let j = 0; if (pad !== -1) output[j++] = pad; for (let i = off; i < data.length; i++) { const value = data[i]; if ((value >> frombits) !== 0) throw new Error('Invalid bech32 bits.'); acc = (acc << frombits) | value; bits += frombits; while (bits >= tobits) { bits -= tobits; output[j++] = (acc >>> bits) & maxv; } } if (pad !== -1) { if (bits > 0) output[j++] = (acc << (tobits - bits)) & maxv; } else { if (bits >= frombits || ((acc << (tobits - bits)) & maxv)) throw new Error('Invalid bech32 bits.'); } return output.slice(0, j); }
[ "function", "convert", "(", "data", ",", "output", ",", "frombits", ",", "tobits", ",", "pad", ",", "off", ")", "{", "const", "maxv", "=", "(", "1", "<<", "tobits", ")", "-", "1", ";", "let", "acc", "=", "0", ";", "let", "bits", "=", "0", ";", "let", "j", "=", "0", ";", "if", "(", "pad", "!==", "-", "1", ")", "output", "[", "j", "++", "]", "=", "pad", ";", "for", "(", "let", "i", "=", "off", ";", "i", "<", "data", ".", "length", ";", "i", "++", ")", "{", "const", "value", "=", "data", "[", "i", "]", ";", "if", "(", "(", "value", ">>", "frombits", ")", "!==", "0", ")", "throw", "new", "Error", "(", "'Invalid bech32 bits.'", ")", ";", "acc", "=", "(", "acc", "<<", "frombits", ")", "|", "value", ";", "bits", "+=", "frombits", ";", "while", "(", "bits", ">=", "tobits", ")", "{", "bits", "-=", "tobits", ";", "output", "[", "j", "++", "]", "=", "(", "acc", ">>>", "bits", ")", "&", "maxv", ";", "}", "}", "if", "(", "pad", "!==", "-", "1", ")", "{", "if", "(", "bits", ">", "0", ")", "output", "[", "j", "++", "]", "=", "(", "acc", "<<", "(", "tobits", "-", "bits", ")", ")", "&", "maxv", ";", "}", "else", "{", "if", "(", "bits", ">=", "frombits", "||", "(", "(", "acc", "<<", "(", "tobits", "-", "bits", ")", ")", "&", "maxv", ")", ")", "throw", "new", "Error", "(", "'Invalid bech32 bits.'", ")", ";", "}", "return", "output", ".", "slice", "(", "0", ",", "j", ")", ";", "}" ]
Convert serialized data to bits, suitable to be serialized as bech32. @param {Buffer} data @param {Buffer} output @param {Number} frombits @param {Number} tobits @param {Number} pad @param {Number} off @returns {Buffer}
[ "Convert", "serialized", "data", "to", "bits", "suitable", "to", "be", "serialized", "as", "bech32", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/utils/bech32.js#L224-L257
train
WorldMobileCoin/wmcc-core
src/utils/bech32.js
encode
function encode(hrp, version, hash) { const output = POOL65; if (version < 0 || version > 16) throw new Error('Invalid bech32 version.'); if (hash.length < 2 || hash.length > 40) throw new Error('Invalid bech32 data length.'); const data = convert(hash, output, 8, 5, version, 0); return serialize(hrp, data); }
javascript
function encode(hrp, version, hash) { const output = POOL65; if (version < 0 || version > 16) throw new Error('Invalid bech32 version.'); if (hash.length < 2 || hash.length > 40) throw new Error('Invalid bech32 data length.'); const data = convert(hash, output, 8, 5, version, 0); return serialize(hrp, data); }
[ "function", "encode", "(", "hrp", ",", "version", ",", "hash", ")", "{", "const", "output", "=", "POOL65", ";", "if", "(", "version", "<", "0", "||", "version", ">", "16", ")", "throw", "new", "Error", "(", "'Invalid bech32 version.'", ")", ";", "if", "(", "hash", ".", "length", "<", "2", "||", "hash", ".", "length", ">", "40", ")", "throw", "new", "Error", "(", "'Invalid bech32 data length.'", ")", ";", "const", "data", "=", "convert", "(", "hash", ",", "output", ",", "8", ",", "5", ",", "version", ",", "0", ")", ";", "return", "serialize", "(", "hrp", ",", "data", ")", ";", "}" ]
Serialize data to bech32 address. @param {String} hrp @param {Number} version @param {Buffer} hash @returns {String}
[ "Serialize", "data", "to", "bech32", "address", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/utils/bech32.js#L267-L279
train
WorldMobileCoin/wmcc-core
src/utils/bech32.js
decode
function decode(str) { const [hrp, data] = deserialize(str); if (data.length === 0 || data.length > 65) throw new Error('Invalid bech32 data length.'); if (data[0] > 16) throw new Error('Invalid bech32 version.'); const version = data[0]; const output = data; const hash = convert(data, output, 5, 8, -1, 1); if (hash.length < 2 || hash.length > 40) throw new Error('Invalid bech32 data length.'); return new AddrResult(hrp, version, hash); }
javascript
function decode(str) { const [hrp, data] = deserialize(str); if (data.length === 0 || data.length > 65) throw new Error('Invalid bech32 data length.'); if (data[0] > 16) throw new Error('Invalid bech32 version.'); const version = data[0]; const output = data; const hash = convert(data, output, 5, 8, -1, 1); if (hash.length < 2 || hash.length > 40) throw new Error('Invalid bech32 data length.'); return new AddrResult(hrp, version, hash); }
[ "function", "decode", "(", "str", ")", "{", "const", "[", "hrp", ",", "data", "]", "=", "deserialize", "(", "str", ")", ";", "if", "(", "data", ".", "length", "===", "0", "||", "data", ".", "length", ">", "65", ")", "throw", "new", "Error", "(", "'Invalid bech32 data length.'", ")", ";", "if", "(", "data", "[", "0", "]", ">", "16", ")", "throw", "new", "Error", "(", "'Invalid bech32 version.'", ")", ";", "const", "version", "=", "data", "[", "0", "]", ";", "const", "output", "=", "data", ";", "const", "hash", "=", "convert", "(", "data", ",", "output", ",", "5", ",", "8", ",", "-", "1", ",", "1", ")", ";", "if", "(", "hash", ".", "length", "<", "2", "||", "hash", ".", "length", ">", "40", ")", "throw", "new", "Error", "(", "'Invalid bech32 data length.'", ")", ";", "return", "new", "AddrResult", "(", "hrp", ",", "version", ",", "hash", ")", ";", "}" ]
Deserialize data from bech32 address. @param {String} str @returns {Object}
[ "Deserialize", "data", "from", "bech32", "address", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/utils/bech32.js#L290-L307
train
WorldMobileCoin/wmcc-core
src/primitives/netaddress.js
NetAddress
function NetAddress(options) { if (!(this instanceof NetAddress)) return new NetAddress(options); this.host = '0.0.0.0'; this.port = 0; this.services = 0; this.time = 0; this.hostname = '0.0.0.0:0'; this.raw = IP.ZERO_IP; if (options) this.fromOptions(options); }
javascript
function NetAddress(options) { if (!(this instanceof NetAddress)) return new NetAddress(options); this.host = '0.0.0.0'; this.port = 0; this.services = 0; this.time = 0; this.hostname = '0.0.0.0:0'; this.raw = IP.ZERO_IP; if (options) this.fromOptions(options); }
[ "function", "NetAddress", "(", "options", ")", "{", "if", "(", "!", "(", "this", "instanceof", "NetAddress", ")", ")", "return", "new", "NetAddress", "(", "options", ")", ";", "this", ".", "host", "=", "'0.0.0.0'", ";", "this", ".", "port", "=", "0", ";", "this", ".", "services", "=", "0", ";", "this", ".", "time", "=", "0", ";", "this", ".", "hostname", "=", "'0.0.0.0:0'", ";", "this", ".", "raw", "=", "IP", ".", "ZERO_IP", ";", "if", "(", "options", ")", "this", ".", "fromOptions", "(", "options", ")", ";", "}" ]
Represents a network address. @alias module:primitives.NetAddress @constructor @param {Object} options @param {Number?} options.time - Timestamp. @param {Number?} options.services - Service bits. @param {String?} options.host - IP address (IPv6 or IPv4). @param {Number?} options.port - Port. @property {Host} host @property {Number} port @property {Number} services @property {Number} time
[ "Represents", "a", "network", "address", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/primitives/netaddress.js#L36-L49
train
perfectapi/node-perfectapi
lib/worker.js
function(err, commandName, config, resultFunction) { //max Number in javascript is 9,007,199,254,740,992. At 10,000 requests per second, that is 28,561 years until we get an overflow on messageId messageId += 1; messageStack[messageId] = resultFunction; //tell the parent process to run the command process.send({id: messageId, err: err, commandName: commandName, config: config}); }
javascript
function(err, commandName, config, resultFunction) { //max Number in javascript is 9,007,199,254,740,992. At 10,000 requests per second, that is 28,561 years until we get an overflow on messageId messageId += 1; messageStack[messageId] = resultFunction; //tell the parent process to run the command process.send({id: messageId, err: err, commandName: commandName, config: config}); }
[ "function", "(", "err", ",", "commandName", ",", "config", ",", "resultFunction", ")", "{", "messageId", "+=", "1", ";", "messageStack", "[", "messageId", "]", "=", "resultFunction", ";", "process", ".", "send", "(", "{", "id", ":", "messageId", ",", "err", ":", "err", ",", "commandName", ":", "commandName", ",", "config", ":", "config", "}", ")", ";", "}" ]
define a function for the webserver to call when it receives a command
[ "define", "a", "function", "for", "the", "webserver", "to", "call", "when", "it", "receives", "a", "command" ]
aea295ede31994bf7f3c2903cedbe6d316b30062
https://github.com/perfectapi/node-perfectapi/blob/aea295ede31994bf7f3c2903cedbe6d316b30062/lib/worker.js#L34-L41
train
WorldMobileCoin/wmcc-core
src/utils/murmur3.js
murmur3
function murmur3(data, seed) { const tail = data.length - (data.length % 4); const c1 = 0xcc9e2d51; const c2 = 0x1b873593; let h1 = seed; let k1; for (let i = 0; i < tail; i += 4) { k1 = (data[i + 3] << 24) | (data[i + 2] << 16) | (data[i + 1] << 8) | data[i]; k1 = mul32(k1, c1); k1 = rotl32(k1, 15); k1 = mul32(k1, c2); h1 ^= k1; h1 = rotl32(h1, 13); h1 = sum32(mul32(h1, 5), 0xe6546b64); } k1 = 0; switch (data.length & 3) { case 3: k1 ^= data[tail + 2] << 16; case 2: k1 ^= data[tail + 1] << 8; case 1: k1 ^= data[tail + 0]; k1 = mul32(k1, c1); k1 = rotl32(k1, 15); k1 = mul32(k1, c2); h1 ^= k1; } h1 ^= data.length; h1 ^= h1 >>> 16; h1 = mul32(h1, 0x85ebca6b); h1 ^= h1 >>> 13; h1 = mul32(h1, 0xc2b2ae35); h1 ^= h1 >>> 16; if (h1 < 0) h1 += 0x100000000; return h1; }
javascript
function murmur3(data, seed) { const tail = data.length - (data.length % 4); const c1 = 0xcc9e2d51; const c2 = 0x1b873593; let h1 = seed; let k1; for (let i = 0; i < tail; i += 4) { k1 = (data[i + 3] << 24) | (data[i + 2] << 16) | (data[i + 1] << 8) | data[i]; k1 = mul32(k1, c1); k1 = rotl32(k1, 15); k1 = mul32(k1, c2); h1 ^= k1; h1 = rotl32(h1, 13); h1 = sum32(mul32(h1, 5), 0xe6546b64); } k1 = 0; switch (data.length & 3) { case 3: k1 ^= data[tail + 2] << 16; case 2: k1 ^= data[tail + 1] << 8; case 1: k1 ^= data[tail + 0]; k1 = mul32(k1, c1); k1 = rotl32(k1, 15); k1 = mul32(k1, c2); h1 ^= k1; } h1 ^= data.length; h1 ^= h1 >>> 16; h1 = mul32(h1, 0x85ebca6b); h1 ^= h1 >>> 13; h1 = mul32(h1, 0xc2b2ae35); h1 ^= h1 >>> 16; if (h1 < 0) h1 += 0x100000000; return h1; }
[ "function", "murmur3", "(", "data", ",", "seed", ")", "{", "const", "tail", "=", "data", ".", "length", "-", "(", "data", ".", "length", "%", "4", ")", ";", "const", "c1", "=", "0xcc9e2d51", ";", "const", "c2", "=", "0x1b873593", ";", "let", "h1", "=", "seed", ";", "let", "k1", ";", "for", "(", "let", "i", "=", "0", ";", "i", "<", "tail", ";", "i", "+=", "4", ")", "{", "k1", "=", "(", "data", "[", "i", "+", "3", "]", "<<", "24", ")", "|", "(", "data", "[", "i", "+", "2", "]", "<<", "16", ")", "|", "(", "data", "[", "i", "+", "1", "]", "<<", "8", ")", "|", "data", "[", "i", "]", ";", "k1", "=", "mul32", "(", "k1", ",", "c1", ")", ";", "k1", "=", "rotl32", "(", "k1", ",", "15", ")", ";", "k1", "=", "mul32", "(", "k1", ",", "c2", ")", ";", "h1", "^=", "k1", ";", "h1", "=", "rotl32", "(", "h1", ",", "13", ")", ";", "h1", "=", "sum32", "(", "mul32", "(", "h1", ",", "5", ")", ",", "0xe6546b64", ")", ";", "}", "k1", "=", "0", ";", "switch", "(", "data", ".", "length", "&", "3", ")", "{", "case", "3", ":", "k1", "^=", "data", "[", "tail", "+", "2", "]", "<<", "16", ";", "case", "2", ":", "k1", "^=", "data", "[", "tail", "+", "1", "]", "<<", "8", ";", "case", "1", ":", "k1", "^=", "data", "[", "tail", "+", "0", "]", ";", "k1", "=", "mul32", "(", "k1", ",", "c1", ")", ";", "k1", "=", "rotl32", "(", "k1", ",", "15", ")", ";", "k1", "=", "mul32", "(", "k1", ",", "c2", ")", ";", "h1", "^=", "k1", ";", "}", "h1", "^=", "data", ".", "length", ";", "h1", "^=", "h1", ">>>", "16", ";", "h1", "=", "mul32", "(", "h1", ",", "0x85ebca6b", ")", ";", "h1", "^=", "h1", ">>>", "13", ";", "h1", "=", "mul32", "(", "h1", ",", "0xc2b2ae35", ")", ";", "h1", "^=", "h1", ">>>", "16", ";", "if", "(", "h1", "<", "0", ")", "h1", "+=", "0x100000000", ";", "return", "h1", ";", "}" ]
Murmur3 hash. @alias module:utils.murmur3 @param {Buffer} data @param {Number} seed @returns {Number}
[ "Murmur3", "hash", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/utils/murmur3.js#L24-L69
train
WorldMobileCoin/wmcc-core
src/blockchain/chain.js
Chain
function Chain(options) { if (!(this instanceof Chain)) return new Chain(options); AsyncObject.call(this); this.options = new ChainOptions(options); this.network = this.options.network; this.logger = this.options.logger.context('chain'); this.workers = this.options.workers; this.db = new ChainDB(this.options); this.locker = new Lock(true); this.invalid = new LRU(100); this.state = new DeploymentState(); this.tip = new ChainEntry(); this.height = -1; this.synced = false; this.orphanMap = new Map(); this.orphanPrev = new Map(); this.subscribers = {}; this.subscribeJobs = {}; this._subscribes = { cmds: [], cp: null }; this._notifies = { cmds: [], cp: null }; }
javascript
function Chain(options) { if (!(this instanceof Chain)) return new Chain(options); AsyncObject.call(this); this.options = new ChainOptions(options); this.network = this.options.network; this.logger = this.options.logger.context('chain'); this.workers = this.options.workers; this.db = new ChainDB(this.options); this.locker = new Lock(true); this.invalid = new LRU(100); this.state = new DeploymentState(); this.tip = new ChainEntry(); this.height = -1; this.synced = false; this.orphanMap = new Map(); this.orphanPrev = new Map(); this.subscribers = {}; this.subscribeJobs = {}; this._subscribes = { cmds: [], cp: null }; this._notifies = { cmds: [], cp: null }; }
[ "function", "Chain", "(", "options", ")", "{", "if", "(", "!", "(", "this", "instanceof", "Chain", ")", ")", "return", "new", "Chain", "(", "options", ")", ";", "AsyncObject", ".", "call", "(", "this", ")", ";", "this", ".", "options", "=", "new", "ChainOptions", "(", "options", ")", ";", "this", ".", "network", "=", "this", ".", "options", ".", "network", ";", "this", ".", "logger", "=", "this", ".", "options", ".", "logger", ".", "context", "(", "'chain'", ")", ";", "this", ".", "workers", "=", "this", ".", "options", ".", "workers", ";", "this", ".", "db", "=", "new", "ChainDB", "(", "this", ".", "options", ")", ";", "this", ".", "locker", "=", "new", "Lock", "(", "true", ")", ";", "this", ".", "invalid", "=", "new", "LRU", "(", "100", ")", ";", "this", ".", "state", "=", "new", "DeploymentState", "(", ")", ";", "this", ".", "tip", "=", "new", "ChainEntry", "(", ")", ";", "this", ".", "height", "=", "-", "1", ";", "this", ".", "synced", "=", "false", ";", "this", ".", "orphanMap", "=", "new", "Map", "(", ")", ";", "this", ".", "orphanPrev", "=", "new", "Map", "(", ")", ";", "this", ".", "subscribers", "=", "{", "}", ";", "this", ".", "subscribeJobs", "=", "{", "}", ";", "this", ".", "_subscribes", "=", "{", "cmds", ":", "[", "]", ",", "cp", ":", "null", "}", ";", "this", ".", "_notifies", "=", "{", "cmds", ":", "[", "]", ",", "cp", ":", "null", "}", ";", "}" ]
Represents a blockchain. @alias module:blockchain.Chain @constructor @param {Object} options @param {String?} options.name - Database name. @param {String?} options.location - Database file location. @param {String?} options.db - Database backend (`"leveldb"` by default). @param {Number?} options.maxOrphans @param {Boolean?} options.spv @property {Boolean} loaded @property {ChainDB} db - Note that Chain `options` will be passed to the instantiated ChainDB. @property {Lock} locker @property {Object} invalid @property {ChainEntry?} tip @property {Number} height @property {DeploymentState} state @property {Object} orphan - Orphan map. @emits Chain#open @emits Chain#error @emits Chain#block @emits Chain#competitor @emits Chain#resolved @emits Chain#checkpoint @emits Chain#fork @emits Chain#reorganize @emits Chain#invalid @emits Chain#exists @emits Chain#purge @emits Chain#connect @emits Chain#reconnect @emits Chain#disconnect
[ "Represents", "a", "blockchain", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/blockchain/chain.js#L68-L103
train
WorldMobileCoin/wmcc-core
src/blockchain/chain.js
DeploymentState
function DeploymentState() { if (!(this instanceof DeploymentState)) return new DeploymentState(); this.flags = Script.flags.MANDATORY_VERIFY_FLAGS; this.flags &= ~Script.flags.VERIFY_P2SH; this.lockFlags = common.lockFlags.MANDATORY_LOCKTIME_FLAGS; this.bip34 = false; this.bip91 = false; this.bip148 = false; }
javascript
function DeploymentState() { if (!(this instanceof DeploymentState)) return new DeploymentState(); this.flags = Script.flags.MANDATORY_VERIFY_FLAGS; this.flags &= ~Script.flags.VERIFY_P2SH; this.lockFlags = common.lockFlags.MANDATORY_LOCKTIME_FLAGS; this.bip34 = false; this.bip91 = false; this.bip148 = false; }
[ "function", "DeploymentState", "(", ")", "{", "if", "(", "!", "(", "this", "instanceof", "DeploymentState", ")", ")", "return", "new", "DeploymentState", "(", ")", ";", "this", ".", "flags", "=", "Script", ".", "flags", ".", "MANDATORY_VERIFY_FLAGS", ";", "this", ".", "flags", "&=", "~", "Script", ".", "flags", ".", "VERIFY_P2SH", ";", "this", ".", "lockFlags", "=", "common", ".", "lockFlags", ".", "MANDATORY_LOCKTIME_FLAGS", ";", "this", ".", "bip34", "=", "false", ";", "this", ".", "bip91", "=", "false", ";", "this", ".", "bip148", "=", "false", ";", "}" ]
Represents the deployment state of the chain. @alias module:blockchain.DeploymentState @constructor @property {VerifyFlags} flags @property {LockFlags} lockFlags @property {Boolean} bip34
[ "Represents", "the", "deployment", "state", "of", "the", "chain", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/blockchain/chain.js#L3110-L3120
train
Mercateo/less-plugin-bower-resolve
lib/bower-file-manager.js
createVirtualLessFileFromBowerJson
function createVirtualLessFileFromBowerJson(bowerJsonPath) { return new PromiseConstructor(function(fullfill, reject) { bowerJson.read(bowerJsonPath, { validate: false }, function(err, bowerJsonData) { if (err) { return reject(err); } if (!bowerJsonData.main) { err = bowerJsonPath + ' has no "main" property.'; return reject(new Error(err)); } // convert bower json into less file var virtualLessFile = bowerJsonData.main.filter(function(filename) { return path.extname(filename) === '.less'; }).map(function(filename) { return '@import "' + filename + '";'; }).join('\n'); if (virtualLessFile) { var file = { contents: virtualLessFile, filename: bowerJsonPath }; return fullfill(file); } else { err = 'Couldn\'t find a less file in ' + bowerJsonPath + '.'; return reject(new Error(err)); } }); }); }
javascript
function createVirtualLessFileFromBowerJson(bowerJsonPath) { return new PromiseConstructor(function(fullfill, reject) { bowerJson.read(bowerJsonPath, { validate: false }, function(err, bowerJsonData) { if (err) { return reject(err); } if (!bowerJsonData.main) { err = bowerJsonPath + ' has no "main" property.'; return reject(new Error(err)); } // convert bower json into less file var virtualLessFile = bowerJsonData.main.filter(function(filename) { return path.extname(filename) === '.less'; }).map(function(filename) { return '@import "' + filename + '";'; }).join('\n'); if (virtualLessFile) { var file = { contents: virtualLessFile, filename: bowerJsonPath }; return fullfill(file); } else { err = 'Couldn\'t find a less file in ' + bowerJsonPath + '.'; return reject(new Error(err)); } }); }); }
[ "function", "createVirtualLessFileFromBowerJson", "(", "bowerJsonPath", ")", "{", "return", "new", "PromiseConstructor", "(", "function", "(", "fullfill", ",", "reject", ")", "{", "bowerJson", ".", "read", "(", "bowerJsonPath", ",", "{", "validate", ":", "false", "}", ",", "function", "(", "err", ",", "bowerJsonData", ")", "{", "if", "(", "err", ")", "{", "return", "reject", "(", "err", ")", ";", "}", "if", "(", "!", "bowerJsonData", ".", "main", ")", "{", "err", "=", "bowerJsonPath", "+", "' has no \"main\" property.'", ";", "return", "reject", "(", "new", "Error", "(", "err", ")", ")", ";", "}", "var", "virtualLessFile", "=", "bowerJsonData", ".", "main", ".", "filter", "(", "function", "(", "filename", ")", "{", "return", "path", ".", "extname", "(", "filename", ")", "===", "'.less'", ";", "}", ")", ".", "map", "(", "function", "(", "filename", ")", "{", "return", "'@import \"'", "+", "filename", "+", "'\";'", ";", "}", ")", ".", "join", "(", "'\\n'", ")", ";", "\\n", "}", ")", ";", "}", ")", ";", "}" ]
Tries to convert a Bower JSON into a virtual Less file. @param {string} bowerJsonPath @returns {PromiseConstructor}
[ "Tries", "to", "convert", "a", "Bower", "JSON", "into", "a", "virtual", "Less", "file", "." ]
f346cad68e90e4c445ebd3ccc95ed9d18ecaca86
https://github.com/Mercateo/less-plugin-bower-resolve/blob/f346cad68e90e4c445ebd3ccc95ed9d18ecaca86/lib/bower-file-manager.js#L25-L55
train
Karnith/machinepack-sailsgulpify
lib/gulp/index.js
function (cb) { sails.log.verbose('Loading app Gulpfile...'); // Start task depending on environment if(sails.config.environment === 'production'){ return this.runTask('prod', cb); } this.runTask('default', cb); }
javascript
function (cb) { sails.log.verbose('Loading app Gulpfile...'); // Start task depending on environment if(sails.config.environment === 'production'){ return this.runTask('prod', cb); } this.runTask('default', cb); }
[ "function", "(", "cb", ")", "{", "sails", ".", "log", ".", "verbose", "(", "'Loading app Gulpfile...'", ")", ";", "if", "(", "sails", ".", "config", ".", "environment", "===", "'production'", ")", "{", "return", "this", ".", "runTask", "(", "'prod'", ",", "cb", ")", ";", "}", "this", ".", "runTask", "(", "'default'", ",", "cb", ")", ";", "}" ]
Initialize this project's Grunt tasks and execute the environment-specific gulpfile
[ "Initialize", "this", "project", "s", "Grunt", "tasks", "and", "execute", "the", "environment", "-", "specific", "gulpfile" ]
38424f98d59cac4240e676159bd25e3bc82ad8ac
https://github.com/Karnith/machinepack-sailsgulpify/blob/38424f98d59cac4240e676159bd25e3bc82ad8ac/lib/gulp/index.js#L25-L35
train
Karnith/machinepack-sailsgulpify
lib/gulp/index.js
_sanitize
function _sanitize (chunk) { if (chunk && typeof chunk === 'object' && chunk.toString) { chunk = chunk.toString(); } if (typeof chunk === 'string') { chunk = chunk.replace(/^[\s\n]*/, ''); chunk = chunk.replace(/[\s\n]*$/, ''); } return chunk; }
javascript
function _sanitize (chunk) { if (chunk && typeof chunk === 'object' && chunk.toString) { chunk = chunk.toString(); } if (typeof chunk === 'string') { chunk = chunk.replace(/^[\s\n]*/, ''); chunk = chunk.replace(/[\s\n]*$/, ''); } return chunk; }
[ "function", "_sanitize", "(", "chunk", ")", "{", "if", "(", "chunk", "&&", "typeof", "chunk", "===", "'object'", "&&", "chunk", ".", "toString", ")", "{", "chunk", "=", "chunk", ".", "toString", "(", ")", ";", "}", "if", "(", "typeof", "chunk", "===", "'string'", ")", "{", "chunk", "=", "chunk", ".", "replace", "(", "/", "^[\\s\\n]*", "/", ",", "''", ")", ";", "chunk", "=", "chunk", ".", "replace", "(", "/", "[\\s\\n]*$", "/", ",", "''", ")", ";", "}", "return", "chunk", ";", "}" ]
After ensuring a chunk is a string, trim any leading or trailing whitespace. If chunk cannot be nicely casted to a string, pass it straight through. @param {*} chunk @return {*}
[ "After", "ensuring", "a", "chunk", "is", "a", "string", "trim", "any", "leading", "or", "trailing", "whitespace", ".", "If", "chunk", "cannot", "be", "nicely", "casted", "to", "a", "string", "pass", "it", "straight", "through", "." ]
38424f98d59cac4240e676159bd25e3bc82ad8ac
https://github.com/Karnith/machinepack-sailsgulpify/blob/38424f98d59cac4240e676159bd25e3bc82ad8ac/lib/gulp/index.js#L203-L213
train
jedmao/blink
js/lib/overrides/background.js
background
function background(options) { options = options || {}; // ReSharper disable once UnusedParameter return function (config) { var values = []; [ 'attachment', 'clip', 'color', 'image', 'origin', 'position', 'repeat', 'size' ].forEach(function (prop) { if (options.hasOwnProperty(prop)) { values.push(options[prop]); } }); if (values.length) { return [['background', values.join(' ')]]; } return []; }; }
javascript
function background(options) { options = options || {}; // ReSharper disable once UnusedParameter return function (config) { var values = []; [ 'attachment', 'clip', 'color', 'image', 'origin', 'position', 'repeat', 'size' ].forEach(function (prop) { if (options.hasOwnProperty(prop)) { values.push(options[prop]); } }); if (values.length) { return [['background', values.join(' ')]]; } return []; }; }
[ "function", "background", "(", "options", ")", "{", "options", "=", "options", "||", "{", "}", ";", "return", "function", "(", "config", ")", "{", "var", "values", "=", "[", "]", ";", "[", "'attachment'", ",", "'clip'", ",", "'color'", ",", "'image'", ",", "'origin'", ",", "'position'", ",", "'repeat'", ",", "'size'", "]", ".", "forEach", "(", "function", "(", "prop", ")", "{", "if", "(", "options", ".", "hasOwnProperty", "(", "prop", ")", ")", "{", "values", ".", "push", "(", "options", "[", "prop", "]", ")", ";", "}", "}", ")", ";", "if", "(", "values", ".", "length", ")", "{", "return", "[", "[", "'background'", ",", "values", ".", "join", "(", "' '", ")", "]", "]", ";", "}", "return", "[", "]", ";", "}", ";", "}" ]
ReSharper disable once UnusedLocals
[ "ReSharper", "disable", "once", "UnusedLocals" ]
f80fb591d33ee0cf063b6d6afae897e69ffcf407
https://github.com/jedmao/blink/blob/f80fb591d33ee0cf063b6d6afae897e69ffcf407/js/lib/overrides/background.js#L2-L26
train
WorldMobileCoin/wmcc-core
src/net/packets.js
PingPacket
function PingPacket(nonce) { if (!(this instanceof PingPacket)) return new PingPacket(nonce); Packet.call(this); this.nonce = nonce || null; }
javascript
function PingPacket(nonce) { if (!(this instanceof PingPacket)) return new PingPacket(nonce); Packet.call(this); this.nonce = nonce || null; }
[ "function", "PingPacket", "(", "nonce", ")", "{", "if", "(", "!", "(", "this", "instanceof", "PingPacket", ")", ")", "return", "new", "PingPacket", "(", "nonce", ")", ";", "Packet", ".", "call", "(", "this", ")", ";", "this", ".", "nonce", "=", "nonce", "||", "null", ";", "}" ]
Represents a `ping` packet. @constructor @param {BN?} nonce @property {BN|null} nonce
[ "Represents", "a", "ping", "packet", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/net/packets.js#L408-L415
train
WorldMobileCoin/wmcc-core
src/net/packets.js
PongPacket
function PongPacket(nonce) { if (!(this instanceof PongPacket)) return new PongPacket(nonce); Packet.call(this); this.nonce = nonce || encoding.ZERO_U64; }
javascript
function PongPacket(nonce) { if (!(this instanceof PongPacket)) return new PongPacket(nonce); Packet.call(this); this.nonce = nonce || encoding.ZERO_U64; }
[ "function", "PongPacket", "(", "nonce", ")", "{", "if", "(", "!", "(", "this", "instanceof", "PongPacket", ")", ")", "return", "new", "PongPacket", "(", "nonce", ")", ";", "Packet", ".", "call", "(", "this", ")", ";", "this", ".", "nonce", "=", "nonce", "||", "encoding", ".", "ZERO_U64", ";", "}" ]
Represents a `pong` packet. @constructor @param {BN?} nonce @property {BN} nonce
[ "Represents", "a", "pong", "packet", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/net/packets.js#L504-L511
train
WorldMobileCoin/wmcc-core
src/net/packets.js
GetBlocksPacket
function GetBlocksPacket(locator, stop) { if (!(this instanceof GetBlocksPacket)) return new GetBlocksPacket(locator, stop); Packet.call(this); this.version = common.PROTOCOL_VERSION; this.locator = locator || []; this.stop = stop || null; }
javascript
function GetBlocksPacket(locator, stop) { if (!(this instanceof GetBlocksPacket)) return new GetBlocksPacket(locator, stop); Packet.call(this); this.version = common.PROTOCOL_VERSION; this.locator = locator || []; this.stop = stop || null; }
[ "function", "GetBlocksPacket", "(", "locator", ",", "stop", ")", "{", "if", "(", "!", "(", "this", "instanceof", "GetBlocksPacket", ")", ")", "return", "new", "GetBlocksPacket", "(", "locator", ",", "stop", ")", ";", "Packet", ".", "call", "(", "this", ")", ";", "this", ".", "version", "=", "common", ".", "PROTOCOL_VERSION", ";", "this", ".", "locator", "=", "locator", "||", "[", "]", ";", "this", ".", "stop", "=", "stop", "||", "null", ";", "}" ]
Represents a `getblocks` packet. @constructor @param {Hash[]} locator @param {Hash?} stop @property {Hash[]} locator @property {Hash|null} stop
[ "Represents", "a", "getblocks", "packet", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/net/packets.js#L928-L937
train
WorldMobileCoin/wmcc-core
src/net/packets.js
GetHeadersPacket
function GetHeadersPacket(locator, stop) { if (!(this instanceof GetHeadersPacket)) return new GetHeadersPacket(locator, stop); GetBlocksPacket.call(this, locator, stop); }
javascript
function GetHeadersPacket(locator, stop) { if (!(this instanceof GetHeadersPacket)) return new GetHeadersPacket(locator, stop); GetBlocksPacket.call(this, locator, stop); }
[ "function", "GetHeadersPacket", "(", "locator", ",", "stop", ")", "{", "if", "(", "!", "(", "this", "instanceof", "GetHeadersPacket", ")", ")", "return", "new", "GetHeadersPacket", "(", "locator", ",", "stop", ")", ";", "GetBlocksPacket", ".", "call", "(", "this", ",", "locator", ",", "stop", ")", ";", "}" ]
Represents a `getheaders` packet. @extends GetBlocksPacket @constructor @param {Hash[]} locator @param {Hash?} stop
[ "Represents", "a", "getheaders", "packet", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/net/packets.js#L1042-L1047
train
WorldMobileCoin/wmcc-core
src/net/packets.js
BlockPacket
function BlockPacket(block, witness) { if (!(this instanceof BlockPacket)) return new BlockPacket(block, witness); Packet.call(this); this.block = block || new MemBlock(); this.witness = witness || false; }
javascript
function BlockPacket(block, witness) { if (!(this instanceof BlockPacket)) return new BlockPacket(block, witness); Packet.call(this); this.block = block || new MemBlock(); this.witness = witness || false; }
[ "function", "BlockPacket", "(", "block", ",", "witness", ")", "{", "if", "(", "!", "(", "this", "instanceof", "BlockPacket", ")", ")", "return", "new", "BlockPacket", "(", "block", ",", "witness", ")", ";", "Packet", ".", "call", "(", "this", ")", ";", "this", ".", "block", "=", "block", "||", "new", "MemBlock", "(", ")", ";", "this", ".", "witness", "=", "witness", "||", "false", ";", "}" ]
Represents a `block` packet. @constructor @param {Block|null} block @param {Boolean?} witness @property {Block} block @property {Boolean} witness
[ "Represents", "a", "block", "packet", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/net/packets.js#L1229-L1237
train
WorldMobileCoin/wmcc-core
src/net/packets.js
TXPacket
function TXPacket(tx, witness) { if (!(this instanceof TXPacket)) return new TXPacket(tx, witness); Packet.call(this); this.tx = tx || new TX(); this.witness = witness || false; }
javascript
function TXPacket(tx, witness) { if (!(this instanceof TXPacket)) return new TXPacket(tx, witness); Packet.call(this); this.tx = tx || new TX(); this.witness = witness || false; }
[ "function", "TXPacket", "(", "tx", ",", "witness", ")", "{", "if", "(", "!", "(", "this", "instanceof", "TXPacket", ")", ")", "return", "new", "TXPacket", "(", "tx", ",", "witness", ")", ";", "Packet", ".", "call", "(", "this", ")", ";", "this", ".", "tx", "=", "tx", "||", "new", "TX", "(", ")", ";", "this", ".", "witness", "=", "witness", "||", "false", ";", "}" ]
Represents a `tx` packet. @constructor @param {TX|null} tx @param {Boolean?} witness @property {TX} block @property {Boolean} witness
[ "Represents", "a", "tx", "packet", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/net/packets.js#L1331-L1339
train
WorldMobileCoin/wmcc-core
src/net/packets.js
FilterLoadPacket
function FilterLoadPacket(filter) { if (!(this instanceof FilterLoadPacket)) return new FilterLoadPacket(filter); Packet.call(this); this.filter = filter || new Bloom(); }
javascript
function FilterLoadPacket(filter) { if (!(this instanceof FilterLoadPacket)) return new FilterLoadPacket(filter); Packet.call(this); this.filter = filter || new Bloom(); }
[ "function", "FilterLoadPacket", "(", "filter", ")", "{", "if", "(", "!", "(", "this", "instanceof", "FilterLoadPacket", ")", ")", "return", "new", "FilterLoadPacket", "(", "filter", ")", ";", "Packet", ".", "call", "(", "this", ")", ";", "this", ".", "filter", "=", "filter", "||", "new", "Bloom", "(", ")", ";", "}" ]
Represents a `filterload` packet. @constructor @param {Bloom|null} filter
[ "Represents", "a", "filterload", "packet", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/net/packets.js#L1770-L1777
train
WorldMobileCoin/wmcc-core
src/net/packets.js
FilterAddPacket
function FilterAddPacket(data) { if (!(this instanceof FilterAddPacket)) return new FilterAddPacket(data); Packet.call(this); this.data = data || DUMMY; }
javascript
function FilterAddPacket(data) { if (!(this instanceof FilterAddPacket)) return new FilterAddPacket(data); Packet.call(this); this.data = data || DUMMY; }
[ "function", "FilterAddPacket", "(", "data", ")", "{", "if", "(", "!", "(", "this", "instanceof", "FilterAddPacket", ")", ")", "return", "new", "FilterAddPacket", "(", "data", ")", ";", "Packet", ".", "call", "(", "this", ")", ";", "this", ".", "data", "=", "data", "||", "DUMMY", ";", "}" ]
Represents a `filteradd` packet. @constructor @param {Buffer?} data @property {Buffer} data
[ "Represents", "a", "filteradd", "packet", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/net/packets.js#L1872-L1879
train
WorldMobileCoin/wmcc-core
src/net/packets.js
MerkleBlockPacket
function MerkleBlockPacket(block) { if (!(this instanceof MerkleBlockPacket)) return new MerkleBlockPacket(block); Packet.call(this); this.block = block || new MerkleBlock(); }
javascript
function MerkleBlockPacket(block) { if (!(this instanceof MerkleBlockPacket)) return new MerkleBlockPacket(block); Packet.call(this); this.block = block || new MerkleBlock(); }
[ "function", "MerkleBlockPacket", "(", "block", ")", "{", "if", "(", "!", "(", "this", "instanceof", "MerkleBlockPacket", ")", ")", "return", "new", "MerkleBlockPacket", "(", "block", ")", ";", "Packet", ".", "call", "(", "this", ")", ";", "this", ".", "block", "=", "block", "||", "new", "MerkleBlock", "(", ")", ";", "}" ]
Represents a `merkleblock` packet. @constructor @param {MerkleBlock?} block @property {MerkleBlock} block
[ "Represents", "a", "merkleblock", "packet", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/net/packets.js#L1986-L1993
train
WorldMobileCoin/wmcc-core
src/net/packets.js
SendCmpctPacket
function SendCmpctPacket(mode, version) { if (!(this instanceof SendCmpctPacket)) return new SendCmpctPacket(mode, version); Packet.call(this); this.mode = mode || 0; this.version = version || 1; }
javascript
function SendCmpctPacket(mode, version) { if (!(this instanceof SendCmpctPacket)) return new SendCmpctPacket(mode, version); Packet.call(this); this.mode = mode || 0; this.version = version || 1; }
[ "function", "SendCmpctPacket", "(", "mode", ",", "version", ")", "{", "if", "(", "!", "(", "this", "instanceof", "SendCmpctPacket", ")", ")", "return", "new", "SendCmpctPacket", "(", "mode", ",", "version", ")", ";", "Packet", ".", "call", "(", "this", ")", ";", "this", ".", "mode", "=", "mode", "||", "0", ";", "this", ".", "version", "=", "version", "||", "1", ";", "}" ]
Represents a `sendcmpct` packet. @constructor @param {Number|null} mode @param {Number|null} version @property {Number} mode @property {Number} version
[ "Represents", "a", "sendcmpct", "packet", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/net/packets.js#L2164-L2172
train
WorldMobileCoin/wmcc-core
src/net/packets.js
CmpctBlockPacket
function CmpctBlockPacket(block, witness) { if (!(this instanceof CmpctBlockPacket)) return new CmpctBlockPacket(block, witness); Packet.call(this); this.block = block || new bip152.CompactBlock(); this.witness = witness || false; }
javascript
function CmpctBlockPacket(block, witness) { if (!(this instanceof CmpctBlockPacket)) return new CmpctBlockPacket(block, witness); Packet.call(this); this.block = block || new bip152.CompactBlock(); this.witness = witness || false; }
[ "function", "CmpctBlockPacket", "(", "block", ",", "witness", ")", "{", "if", "(", "!", "(", "this", "instanceof", "CmpctBlockPacket", ")", ")", "return", "new", "CmpctBlockPacket", "(", "block", ",", "witness", ")", ";", "Packet", ".", "call", "(", "this", ")", ";", "this", ".", "block", "=", "block", "||", "new", "bip152", ".", "CompactBlock", "(", ")", ";", "this", ".", "witness", "=", "witness", "||", "false", ";", "}" ]
Represents a `cmpctblock` packet. @constructor @param {Block|null} block @param {Boolean|null} witness @property {Block} block @property {Boolean} witness
[ "Represents", "a", "cmpctblock", "packet", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/net/packets.js#L2272-L2280
train
WorldMobileCoin/wmcc-core
src/net/packets.js
GetBlockTxnPacket
function GetBlockTxnPacket(request) { if (!(this instanceof GetBlockTxnPacket)) return new GetBlockTxnPacket(request); Packet.call(this); this.request = request || new bip152.TXRequest(); }
javascript
function GetBlockTxnPacket(request) { if (!(this instanceof GetBlockTxnPacket)) return new GetBlockTxnPacket(request); Packet.call(this); this.request = request || new bip152.TXRequest(); }
[ "function", "GetBlockTxnPacket", "(", "request", ")", "{", "if", "(", "!", "(", "this", "instanceof", "GetBlockTxnPacket", ")", ")", "return", "new", "GetBlockTxnPacket", "(", "request", ")", ";", "Packet", ".", "call", "(", "this", ")", ";", "this", ".", "request", "=", "request", "||", "new", "bip152", ".", "TXRequest", "(", ")", ";", "}" ]
Represents a `getblocktxn` packet. @constructor @param {TXRequest?} request @property {TXRequest} request
[ "Represents", "a", "getblocktxn", "packet", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/net/packets.js#L2372-L2379
train
WorldMobileCoin/wmcc-core
src/net/packets.js
BlockTxnPacket
function BlockTxnPacket(response, witness) { if (!(this instanceof BlockTxnPacket)) return new BlockTxnPacket(response, witness); Packet.call(this); this.response = response || new bip152.TXResponse(); this.witness = witness || false; }
javascript
function BlockTxnPacket(response, witness) { if (!(this instanceof BlockTxnPacket)) return new BlockTxnPacket(response, witness); Packet.call(this); this.response = response || new bip152.TXResponse(); this.witness = witness || false; }
[ "function", "BlockTxnPacket", "(", "response", ",", "witness", ")", "{", "if", "(", "!", "(", "this", "instanceof", "BlockTxnPacket", ")", ")", "return", "new", "BlockTxnPacket", "(", "response", ",", "witness", ")", ";", "Packet", ".", "call", "(", "this", ")", ";", "this", ".", "response", "=", "response", "||", "new", "bip152", ".", "TXResponse", "(", ")", ";", "this", ".", "witness", "=", "witness", "||", "false", ";", "}" ]
Represents a `blocktxn` packet. @constructor @param {TXResponse?} response @param {Boolean?} witness @property {TXResponse} response @property {Boolean} witness
[ "Represents", "a", "blocktxn", "packet", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/net/packets.js#L2467-L2475
train
WorldMobileCoin/wmcc-core
src/net/packets.js
EncinitPacket
function EncinitPacket(publicKey, cipher) { if (!(this instanceof EncinitPacket)) return new EncinitPacket(publicKey, cipher); Packet.call(this); this.publicKey = publicKey || encoding.ZERO_KEY; this.cipher = cipher || 0; }
javascript
function EncinitPacket(publicKey, cipher) { if (!(this instanceof EncinitPacket)) return new EncinitPacket(publicKey, cipher); Packet.call(this); this.publicKey = publicKey || encoding.ZERO_KEY; this.cipher = cipher || 0; }
[ "function", "EncinitPacket", "(", "publicKey", ",", "cipher", ")", "{", "if", "(", "!", "(", "this", "instanceof", "EncinitPacket", ")", ")", "return", "new", "EncinitPacket", "(", "publicKey", ",", "cipher", ")", ";", "Packet", ".", "call", "(", "this", ")", ";", "this", ".", "publicKey", "=", "publicKey", "||", "encoding", ".", "ZERO_KEY", ";", "this", ".", "cipher", "=", "cipher", "||", "0", ";", "}" ]
Represents a `encinit` packet. @constructor @param {Buffer|null} publicKey @param {Number|null} cipher @property {Buffer} publicKey @property {Number} cipher
[ "Represents", "a", "encinit", "packet", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/net/packets.js#L2569-L2577
train
WorldMobileCoin/wmcc-core
src/net/packets.js
EncackPacket
function EncackPacket(publicKey) { if (!(this instanceof EncackPacket)) return new EncackPacket(publicKey); Packet.call(this); this.publicKey = publicKey || encoding.ZERO_KEY; }
javascript
function EncackPacket(publicKey) { if (!(this instanceof EncackPacket)) return new EncackPacket(publicKey); Packet.call(this); this.publicKey = publicKey || encoding.ZERO_KEY; }
[ "function", "EncackPacket", "(", "publicKey", ")", "{", "if", "(", "!", "(", "this", "instanceof", "EncackPacket", ")", ")", "return", "new", "EncackPacket", "(", "publicKey", ")", ";", "Packet", ".", "call", "(", "this", ")", ";", "this", ".", "publicKey", "=", "publicKey", "||", "encoding", ".", "ZERO_KEY", ";", "}" ]
Represents a `encack` packet. @constructor @param {Buffer?} publicKey @property {Buffer} publicKey
[ "Represents", "a", "encack", "packet", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/net/packets.js#L2665-L2672
train
WorldMobileCoin/wmcc-core
src/net/packets.js
AuthChallengePacket
function AuthChallengePacket(hash) { if (!(this instanceof AuthChallengePacket)) return new AuthChallengePacket(hash); Packet.call(this); this.hash = hash || encoding.ZERO_HASH; }
javascript
function AuthChallengePacket(hash) { if (!(this instanceof AuthChallengePacket)) return new AuthChallengePacket(hash); Packet.call(this); this.hash = hash || encoding.ZERO_HASH; }
[ "function", "AuthChallengePacket", "(", "hash", ")", "{", "if", "(", "!", "(", "this", "instanceof", "AuthChallengePacket", ")", ")", "return", "new", "AuthChallengePacket", "(", "hash", ")", ";", "Packet", ".", "call", "(", "this", ")", ";", "this", ".", "hash", "=", "hash", "||", "encoding", ".", "ZERO_HASH", ";", "}" ]
Represents a `authchallenge` packet. @constructor @param {Buffer?} hash @property {Buffer} hash
[ "Represents", "a", "authchallenge", "packet", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/net/packets.js#L2758-L2765
train
WorldMobileCoin/wmcc-core
src/net/packets.js
AuthReplyPacket
function AuthReplyPacket(signature) { if (!(this instanceof AuthReplyPacket)) return new AuthReplyPacket(signature); Packet.call(this); this.signature = signature || encoding.ZERO_SIG64; }
javascript
function AuthReplyPacket(signature) { if (!(this instanceof AuthReplyPacket)) return new AuthReplyPacket(signature); Packet.call(this); this.signature = signature || encoding.ZERO_SIG64; }
[ "function", "AuthReplyPacket", "(", "signature", ")", "{", "if", "(", "!", "(", "this", "instanceof", "AuthReplyPacket", ")", ")", "return", "new", "AuthReplyPacket", "(", "signature", ")", ";", "Packet", ".", "call", "(", "this", ")", ";", "this", ".", "signature", "=", "signature", "||", "encoding", ".", "ZERO_SIG64", ";", "}" ]
Represents a `authreply` packet. @constructor @param {Buffer?} signature @property {Buffer} signature
[ "Represents", "a", "authreply", "packet", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/net/packets.js#L2851-L2858
train
WorldMobileCoin/wmcc-core
src/net/packets.js
AuthProposePacket
function AuthProposePacket(hash) { if (!(this instanceof AuthProposePacket)) return new AuthProposePacket(hash); Packet.call(this); this.hash = hash || encoding.ZERO_HASH; }
javascript
function AuthProposePacket(hash) { if (!(this instanceof AuthProposePacket)) return new AuthProposePacket(hash); Packet.call(this); this.hash = hash || encoding.ZERO_HASH; }
[ "function", "AuthProposePacket", "(", "hash", ")", "{", "if", "(", "!", "(", "this", "instanceof", "AuthProposePacket", ")", ")", "return", "new", "AuthProposePacket", "(", "hash", ")", ";", "Packet", ".", "call", "(", "this", ")", ";", "this", ".", "hash", "=", "hash", "||", "encoding", ".", "ZERO_HASH", ";", "}" ]
Represents a `authpropose` packet. @constructor @param {Hash?} hash @property {Hash} hash
[ "Represents", "a", "authpropose", "packet", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/net/packets.js#L2944-L2951
train
WorldMobileCoin/wmcc-core
src/net/packets.js
UnknownPacket
function UnknownPacket(cmd, data) { if (!(this instanceof UnknownPacket)) return new UnknownPacket(cmd, data); Packet.call(this); this.cmd = cmd; this.data = data; }
javascript
function UnknownPacket(cmd, data) { if (!(this instanceof UnknownPacket)) return new UnknownPacket(cmd, data); Packet.call(this); this.cmd = cmd; this.data = data; }
[ "function", "UnknownPacket", "(", "cmd", ",", "data", ")", "{", "if", "(", "!", "(", "this", "instanceof", "UnknownPacket", ")", ")", "return", "new", "UnknownPacket", "(", "cmd", ",", "data", ")", ";", "Packet", ".", "call", "(", "this", ")", ";", "this", ".", "cmd", "=", "cmd", ";", "this", ".", "data", "=", "data", ";", "}" ]
Represents an unknown packet. @constructor @param {String|null} cmd @param {Buffer|null} data @property {String} cmd @property {Buffer} data
[ "Represents", "an", "unknown", "packet", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/net/packets.js#L3039-L3047
train
WorldMobileCoin/wmcc-core
src/script/sigcache.js
SigCache
function SigCache(size) { if (!(this instanceof SigCache)) return new SigCache(size); if (size == null) size = 10000; assert(util.isU32(size)); this.size = size; this.keys = []; this.valid = new Map(); }
javascript
function SigCache(size) { if (!(this instanceof SigCache)) return new SigCache(size); if (size == null) size = 10000; assert(util.isU32(size)); this.size = size; this.keys = []; this.valid = new Map(); }
[ "function", "SigCache", "(", "size", ")", "{", "if", "(", "!", "(", "this", "instanceof", "SigCache", ")", ")", "return", "new", "SigCache", "(", "size", ")", ";", "if", "(", "size", "==", "null", ")", "size", "=", "10000", ";", "assert", "(", "util", ".", "isU32", "(", "size", ")", ")", ";", "this", ".", "size", "=", "size", ";", "this", ".", "keys", "=", "[", "]", ";", "this", ".", "valid", "=", "new", "Map", "(", ")", ";", "}" ]
Signature cache. @alias module:script.SigCache @constructor @param {Number} [size=10000] @property {Number} size @property {Hash[]} keys @property {Object} valid
[ "Signature", "cache", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/script/sigcache.js#L27-L39
train
WorldMobileCoin/wmcc-core
src/script/sigcache.js
SigCacheEntry
function SigCacheEntry(sig, key) { this.sig = Buffer.from(sig); this.key = Buffer.from(key); }
javascript
function SigCacheEntry(sig, key) { this.sig = Buffer.from(sig); this.key = Buffer.from(key); }
[ "function", "SigCacheEntry", "(", "sig", ",", "key", ")", "{", "this", ".", "sig", "=", "Buffer", ".", "from", "(", "sig", ")", ";", "this", ".", "key", "=", "Buffer", ".", "from", "(", "key", ")", ";", "}" ]
Signature cache entry. @constructor @ignore @param {Buffer} sig @param {Buffer} key @property {Buffer} sig @property {Buffer} key
[ "Signature", "cache", "entry", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/script/sigcache.js#L133-L136
train
blakeembrey/kroute
lib/proto.js
sanitize
function sanitize (fn) { return function (/* path, ...middleware */) { var middleware = [] var startindex = 0 var endindex = arguments.length var path var options if (typeof arguments[0] === 'string') { path = arguments[0] startindex = 1 } if (typeof arguments[arguments.length - 1] === 'object') { endindex = arguments.length - 1 options = arguments[endindex] } // Concat all the middleware functions. for (var i = startindex; i < endindex; i++) { middleware.push(arguments[i]) } middleware = flatten(middleware) if (middleware.length === 0) { throw new TypeError('Expected a function but got no arguments') } if (middleware.length === 1) { middleware = middleware[0] } else { middleware = compose(middleware) } fn.call(this, path, middleware, extend({}, this._options, options)) return this } }
javascript
function sanitize (fn) { return function (/* path, ...middleware */) { var middleware = [] var startindex = 0 var endindex = arguments.length var path var options if (typeof arguments[0] === 'string') { path = arguments[0] startindex = 1 } if (typeof arguments[arguments.length - 1] === 'object') { endindex = arguments.length - 1 options = arguments[endindex] } // Concat all the middleware functions. for (var i = startindex; i < endindex; i++) { middleware.push(arguments[i]) } middleware = flatten(middleware) if (middleware.length === 0) { throw new TypeError('Expected a function but got no arguments') } if (middleware.length === 1) { middleware = middleware[0] } else { middleware = compose(middleware) } fn.call(this, path, middleware, extend({}, this._options, options)) return this } }
[ "function", "sanitize", "(", "fn", ")", "{", "return", "function", "(", ")", "{", "var", "middleware", "=", "[", "]", "var", "startindex", "=", "0", "var", "endindex", "=", "arguments", ".", "length", "var", "path", "var", "options", "if", "(", "typeof", "arguments", "[", "0", "]", "===", "'string'", ")", "{", "path", "=", "arguments", "[", "0", "]", "startindex", "=", "1", "}", "if", "(", "typeof", "arguments", "[", "arguments", ".", "length", "-", "1", "]", "===", "'object'", ")", "{", "endindex", "=", "arguments", ".", "length", "-", "1", "options", "=", "arguments", "[", "endindex", "]", "}", "for", "(", "var", "i", "=", "startindex", ";", "i", "<", "endindex", ";", "i", "++", ")", "{", "middleware", ".", "push", "(", "arguments", "[", "i", "]", ")", "}", "middleware", "=", "flatten", "(", "middleware", ")", "if", "(", "middleware", ".", "length", "===", "0", ")", "{", "throw", "new", "TypeError", "(", "'Expected a function but got no arguments'", ")", "}", "if", "(", "middleware", ".", "length", "===", "1", ")", "{", "middleware", "=", "middleware", "[", "0", "]", "}", "else", "{", "middleware", "=", "compose", "(", "middleware", ")", "}", "fn", ".", "call", "(", "this", ",", "path", ",", "middleware", ",", "extend", "(", "{", "}", ",", "this", ".", "_options", ",", "options", ")", ")", "return", "this", "}", "}" ]
Sanitize a function to accept an optional path and unlimited middleware. @param {Function} fn @return {Function}
[ "Sanitize", "a", "function", "to", "accept", "an", "optional", "path", "and", "unlimited", "middleware", "." ]
b39f76fb6402e257a8b4d6b26b6511d16fa22871
https://github.com/blakeembrey/kroute/blob/b39f76fb6402e257a8b4d6b26b6511d16fa22871/lib/proto.js#L22-L61
train
WorldMobileCoin/wmcc-core
src/utils/rbt.js
RBT
function RBT(compare, unique) { if (!(this instanceof RBT)) return new RBT(compare, unique); assert(typeof compare === 'function'); this.root = SENTINEL; this.compare = compare; this.unique = unique || false; }
javascript
function RBT(compare, unique) { if (!(this instanceof RBT)) return new RBT(compare, unique); assert(typeof compare === 'function'); this.root = SENTINEL; this.compare = compare; this.unique = unique || false; }
[ "function", "RBT", "(", "compare", ",", "unique", ")", "{", "if", "(", "!", "(", "this", "instanceof", "RBT", ")", ")", "return", "new", "RBT", "(", "compare", ",", "unique", ")", ";", "assert", "(", "typeof", "compare", "===", "'function'", ")", ";", "this", ".", "root", "=", "SENTINEL", ";", "this", ".", "compare", "=", "compare", ";", "this", ".", "unique", "=", "unique", "||", "false", ";", "}" ]
An iterative red black tree. @alias module:utils.RBT @constructor @param {Function} compare - Comparator. @param {Boolean?} unique
[ "An", "iterative", "red", "black", "tree", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/utils/rbt.js#L26-L35
train
WorldMobileCoin/wmcc-core
src/utils/rbt.js
RBTSentinel
function RBTSentinel() { this.key = null; this.value = null; this.color = BLACK; this.parent = null; this.left = null; this.right = null; }
javascript
function RBTSentinel() { this.key = null; this.value = null; this.color = BLACK; this.parent = null; this.left = null; this.right = null; }
[ "function", "RBTSentinel", "(", ")", "{", "this", ".", "key", "=", "null", ";", "this", ".", "value", "=", "null", ";", "this", ".", "color", "=", "BLACK", ";", "this", ".", "parent", "=", "null", ";", "this", ".", "left", "=", "null", ";", "this", ".", "right", "=", "null", ";", "}" ]
RBT Sentinel Node @constructor @ignore @property {null} key @property {null} value @property {Number} [color=BLACK] @property {null} parent @property {null} left @property {null} right
[ "RBT", "Sentinel", "Node" ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/utils/rbt.js#L820-L827
train
gsdriver/blackjack-strategy
src/ExactComposition.js
function (playerCards, dealerCard, handValue, handCount, dealerCheckedBlackjack, options) { // If exactComposition isn't set, no override if (options.strategyComplexity != "exactComposition") { return null; } // Now look at strategies based on game options if ((options.numberOfDecks == 2) && (!options.hitSoft17)) { return TwoDeckStandSoft17(playerCards, dealerCard, handValue, handCount, dealerCheckedBlackjack, options); } }
javascript
function (playerCards, dealerCard, handValue, handCount, dealerCheckedBlackjack, options) { // If exactComposition isn't set, no override if (options.strategyComplexity != "exactComposition") { return null; } // Now look at strategies based on game options if ((options.numberOfDecks == 2) && (!options.hitSoft17)) { return TwoDeckStandSoft17(playerCards, dealerCard, handValue, handCount, dealerCheckedBlackjack, options); } }
[ "function", "(", "playerCards", ",", "dealerCard", ",", "handValue", ",", "handCount", ",", "dealerCheckedBlackjack", ",", "options", ")", "{", "if", "(", "options", ".", "strategyComplexity", "!=", "\"exactComposition\"", ")", "{", "return", "null", ";", "}", "if", "(", "(", "options", ".", "numberOfDecks", "==", "2", ")", "&&", "(", "!", "options", ".", "hitSoft17", ")", ")", "{", "return", "TwoDeckStandSoft17", "(", "playerCards", ",", "dealerCard", ",", "handValue", ",", "handCount", ",", "dealerCheckedBlackjack", ",", "options", ")", ";", "}", "}" ]
Special-case overrides based on exact composition of cards
[ "Special", "-", "case", "overrides", "based", "on", "exact", "composition", "of", "cards" ]
dfcb976ab9bb33c74c24c9bacf369e8ffb6506f3
https://github.com/gsdriver/blackjack-strategy/blob/dfcb976ab9bb33c74c24c9bacf369e8ffb6506f3/src/ExactComposition.js#L27-L40
train
eccentric-j/cli-glob
lib/index.js
globcmd
function globcmd(globstr) { var dir = arguments.length <= 1 || arguments[1] === undefined ? process.cwd() : arguments[1]; return new Promise(function (resolve, reject) { if (!globstr || !globstr.length) { return reject(new Error('No glob string given.')); } // Use glob to read the files in the dir (0, _glob2.default)(String(globstr), { cwd: dir }, function (err, files) { if (err) return reject(err); // Files if (files.length === 0) { reject(new Error('No files match the glob string "' + globstr + '"')); } // Append the matching file to an array resolve(files.map(function (filename) { return { path: _path2.default.resolve(dir, filename), relative: _path2.default.relative(dir, filename) }; })); }); }); }
javascript
function globcmd(globstr) { var dir = arguments.length <= 1 || arguments[1] === undefined ? process.cwd() : arguments[1]; return new Promise(function (resolve, reject) { if (!globstr || !globstr.length) { return reject(new Error('No glob string given.')); } // Use glob to read the files in the dir (0, _glob2.default)(String(globstr), { cwd: dir }, function (err, files) { if (err) return reject(err); // Files if (files.length === 0) { reject(new Error('No files match the glob string "' + globstr + '"')); } // Append the matching file to an array resolve(files.map(function (filename) { return { path: _path2.default.resolve(dir, filename), relative: _path2.default.relative(dir, filename) }; })); }); }); }
[ "function", "globcmd", "(", "globstr", ")", "{", "var", "dir", "=", "arguments", ".", "length", "<=", "1", "||", "arguments", "[", "1", "]", "===", "undefined", "?", "process", ".", "cwd", "(", ")", ":", "arguments", "[", "1", "]", ";", "return", "new", "Promise", "(", "function", "(", "resolve", ",", "reject", ")", "{", "if", "(", "!", "globstr", "||", "!", "globstr", ".", "length", ")", "{", "return", "reject", "(", "new", "Error", "(", "'No glob string given.'", ")", ")", ";", "}", "(", "0", ",", "_glob2", ".", "default", ")", "(", "String", "(", "globstr", ")", ",", "{", "cwd", ":", "dir", "}", ",", "function", "(", "err", ",", "files", ")", "{", "if", "(", "err", ")", "return", "reject", "(", "err", ")", ";", "if", "(", "files", ".", "length", "===", "0", ")", "{", "reject", "(", "new", "Error", "(", "'No files match the glob string \"'", "+", "globstr", "+", "'\"'", ")", ")", ";", "}", "resolve", "(", "files", ".", "map", "(", "function", "(", "filename", ")", "{", "return", "{", "path", ":", "_path2", ".", "default", ".", "resolve", "(", "dir", ",", "filename", ")", ",", "relative", ":", "_path2", ".", "default", ".", "relative", "(", "dir", ",", "filename", ")", "}", ";", "}", ")", ")", ";", "}", ")", ";", "}", ")", ";", "}" ]
Globcmd Returns a promise that will be resolved with an array of files @param {string} globstr - Glob str to look for @param {string} [dir=process.cwd()] - Root directory @returns {Promise} A promise object to be resolved with an array of files or rejected with an error.
[ "Globcmd", "Returns", "a", "promise", "that", "will", "be", "resolved", "with", "an", "array", "of", "files" ]
a2f5bfdb29e1ccac6a93c509ca1f9172c06939a4
https://github.com/eccentric-j/cli-glob/blob/a2f5bfdb29e1ccac6a93c509ca1f9172c06939a4/lib/index.js#L31-L57
train
Spiffyk/twitch-node-sdk
lib/twitch.init.js
init
function init(options, callback) { if (!options.clientId) { throw new Error('client id not specified'); } core.setClientId(options.clientId); if (options.nw) { if (options.nw === true) { core.log('NW.js 0.13 is experimental.'); gui.setGUIType('nw13'); } else { gui.setGUIType('nw', options.nw); } } else if (options.electron) { gui.setGUIType('electron'); } auth.initSession(options.session, callback); }
javascript
function init(options, callback) { if (!options.clientId) { throw new Error('client id not specified'); } core.setClientId(options.clientId); if (options.nw) { if (options.nw === true) { core.log('NW.js 0.13 is experimental.'); gui.setGUIType('nw13'); } else { gui.setGUIType('nw', options.nw); } } else if (options.electron) { gui.setGUIType('electron'); } auth.initSession(options.session, callback); }
[ "function", "init", "(", "options", ",", "callback", ")", "{", "if", "(", "!", "options", ".", "clientId", ")", "{", "throw", "new", "Error", "(", "'client id not specified'", ")", ";", "}", "core", ".", "setClientId", "(", "options", ".", "clientId", ")", ";", "if", "(", "options", ".", "nw", ")", "{", "if", "(", "options", ".", "nw", "===", "true", ")", "{", "core", ".", "log", "(", "'NW.js 0.13 is experimental.'", ")", ";", "gui", ".", "setGUIType", "(", "'nw13'", ")", ";", "}", "else", "{", "gui", ".", "setGUIType", "(", "'nw'", ",", "options", ".", "nw", ")", ";", "}", "}", "else", "if", "(", "options", ".", "electron", ")", "{", "gui", ".", "setGUIType", "(", "'electron'", ")", ";", "}", "auth", ".", "initSession", "(", "options", ".", "session", ",", "callback", ")", ";", "}" ]
Initializes the SDK. The `options` parameter can have the following properties (optional if not stated otherwise): * `clientId` (**required**) - The client ID of your application * `session` - If your application has stored the session object somewhere, you can pass it to the SDK to speed up the login process. * `electron` - `true` if **Electron** is used. * `nw` - `true` if **NW.js v0.13 or higher** is used. If you use **NW.js v0.12 or lower**, set to the object you get by calling `require('nw.gui')` @method init @param {Object} options Options to initialize the SDK with @param {function} [callback] The callback to run after the SDK is initialized. @memberof Twitch
[ "Initializes", "the", "SDK", "." ]
e98234ca52b12569298213869439d17169e26f27
https://github.com/Spiffyk/twitch-node-sdk/blob/e98234ca52b12569298213869439d17169e26f27/lib/twitch.init.js#L31-L52
train
WorldMobileCoin/wmcc-core
src/mining/mine.js
mine
function mine(data, target, min, max) { let nonce = min; data.writeUInt32LE(nonce, 76, true); // The heart and soul of the miner: match the target. while (nonce <= max) { // Hash and test against the next target. // if (rcmp(digest.hash256(data), target) <= 0) // cfc // if (rcmp(powHash(data), target) <= 0) // ctl if (rcmp(calHash(data), target) <= 0) return nonce; // Increment the nonce to get a different hash. nonce++; // Update the raw buffer. data.writeUInt32LE(nonce, 76, true); } return -1; }
javascript
function mine(data, target, min, max) { let nonce = min; data.writeUInt32LE(nonce, 76, true); // The heart and soul of the miner: match the target. while (nonce <= max) { // Hash and test against the next target. // if (rcmp(digest.hash256(data), target) <= 0) // cfc // if (rcmp(powHash(data), target) <= 0) // ctl if (rcmp(calHash(data), target) <= 0) return nonce; // Increment the nonce to get a different hash. nonce++; // Update the raw buffer. data.writeUInt32LE(nonce, 76, true); } return -1; }
[ "function", "mine", "(", "data", ",", "target", ",", "min", ",", "max", ")", "{", "let", "nonce", "=", "min", ";", "data", ".", "writeUInt32LE", "(", "nonce", ",", "76", ",", "true", ")", ";", "while", "(", "nonce", "<=", "max", ")", "{", "if", "(", "rcmp", "(", "calHash", "(", "data", ")", ",", "target", ")", "<=", "0", ")", "return", "nonce", ";", "nonce", "++", ";", "data", ".", "writeUInt32LE", "(", "nonce", ",", "76", ",", "true", ")", ";", "}", "return", "-", "1", ";", "}" ]
Hash until the nonce overflows. @alias module:mining.mine @param {Buffer} data @param {Buffer} target - Big endian. @param {Number} min @param {Number} max @returns {Number} Nonce or -1.
[ "Hash", "until", "the", "nonce", "overflows", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/mining/mine.js#L28-L49
train
WorldMobileCoin/wmcc-core
src/bip70/payment.js
Payment
function Payment(options) { if (!(this instanceof Payment)) return new Payment(options); this.merchantData = null; this.transactions = []; this.refundTo = []; this.memo = null; if (options) this.fromOptions(options); }
javascript
function Payment(options) { if (!(this instanceof Payment)) return new Payment(options); this.merchantData = null; this.transactions = []; this.refundTo = []; this.memo = null; if (options) this.fromOptions(options); }
[ "function", "Payment", "(", "options", ")", "{", "if", "(", "!", "(", "this", "instanceof", "Payment", ")", ")", "return", "new", "Payment", "(", "options", ")", ";", "this", ".", "merchantData", "=", "null", ";", "this", ".", "transactions", "=", "[", "]", ";", "this", ".", "refundTo", "=", "[", "]", ";", "this", ".", "memo", "=", "null", ";", "if", "(", "options", ")", "this", ".", "fromOptions", "(", "options", ")", ";", "}" ]
Represents a BIP70 payment. @alias module:bip70.Payment @constructor @param {Object?} options @property {Buffer} merchantData @property {TX[]} transactions @property {Output[]} refundTo @property {String|null} memo
[ "Represents", "a", "BIP70", "payment", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/bip70/payment.js#L32-L43
train
ahtohbi4/postcss-bgimage
src/isNodeIgnored.js
isNodeIgnored
function isNodeIgnored(node) { const parent = node.parent; if (!parent) { // Root was reached. return false; } if (parent.some((child) => (child.type === 'comment' && PATTERN_IGNORE.test(child.text)))) { // Instruction to ignore the node was detected. return true; } // Check the instruction on one level above. return isNodeIgnored(parent); }
javascript
function isNodeIgnored(node) { const parent = node.parent; if (!parent) { // Root was reached. return false; } if (parent.some((child) => (child.type === 'comment' && PATTERN_IGNORE.test(child.text)))) { // Instruction to ignore the node was detected. return true; } // Check the instruction on one level above. return isNodeIgnored(parent); }
[ "function", "isNodeIgnored", "(", "node", ")", "{", "const", "parent", "=", "node", ".", "parent", ";", "if", "(", "!", "parent", ")", "{", "return", "false", ";", "}", "if", "(", "parent", ".", "some", "(", "(", "child", ")", "=>", "(", "child", ".", "type", "===", "'comment'", "&&", "PATTERN_IGNORE", ".", "test", "(", "child", ".", "text", ")", ")", ")", ")", "{", "return", "true", ";", "}", "return", "isNodeIgnored", "(", "parent", ")", ";", "}" ]
Check instruction to ignore the node. @param {Node} node @return {boolean}
[ "Check", "instruction", "to", "ignore", "the", "node", "." ]
b955c9f0aa0e24e57b17825c9aaec3016ef3b715
https://github.com/ahtohbi4/postcss-bgimage/blob/b955c9f0aa0e24e57b17825c9aaec3016ef3b715/src/isNodeIgnored.js#L8-L23
train
bunnybones1/threejs-light-probe
lib/three.js
function ( contour, indices ) { var n = contour.length; if ( n < 3 ) return null; var result = [], verts = [], vertIndices = []; /* we want a counter-clockwise polygon in verts */ var u, v, w; if ( area( contour ) > 0.0 ) { for ( v = 0; v < n; v ++ ) verts[ v ] = v; } else { for ( v = 0; v < n; v ++ ) verts[ v ] = ( n - 1 ) - v; } var nv = n; /* remove nv - 2 vertices, creating 1 triangle every time */ var count = 2 * nv; /* error detection */ for ( v = nv - 1; nv > 2; ) { /* if we loop, it is probably a non-simple polygon */ if ( ( count -- ) <= 0 ) { //** Triangulate: ERROR - probable bad polygon! //throw ( "Warning, unable to triangulate polygon!" ); //return null; // Sometimes warning is fine, especially polygons are triangulated in reverse. console.log( 'Warning, unable to triangulate polygon!' ); if ( indices ) return vertIndices; return result; } /* three consecutive vertices in current polygon, <u,v,w> */ u = v; if ( nv <= u ) u = 0; /* previous */ v = u + 1; if ( nv <= v ) v = 0; /* new v */ w = v + 1; if ( nv <= w ) w = 0; /* next */ if ( snip( contour, u, v, w, nv, verts ) ) { var a, b, c, s, t; /* true names of the vertices */ a = verts[ u ]; b = verts[ v ]; c = verts[ w ]; /* output Triangle */ result.push( [ contour[ a ], contour[ b ], contour[ c ] ] ); vertIndices.push( [ verts[ u ], verts[ v ], verts[ w ] ] ); /* remove v from the remaining polygon */ for ( s = v, t = v + 1; t < nv; s++, t++ ) { verts[ s ] = verts[ t ]; } nv --; /* reset error detection counter */ count = 2 * nv; } } if ( indices ) return vertIndices; return result; }
javascript
function ( contour, indices ) { var n = contour.length; if ( n < 3 ) return null; var result = [], verts = [], vertIndices = []; /* we want a counter-clockwise polygon in verts */ var u, v, w; if ( area( contour ) > 0.0 ) { for ( v = 0; v < n; v ++ ) verts[ v ] = v; } else { for ( v = 0; v < n; v ++ ) verts[ v ] = ( n - 1 ) - v; } var nv = n; /* remove nv - 2 vertices, creating 1 triangle every time */ var count = 2 * nv; /* error detection */ for ( v = nv - 1; nv > 2; ) { /* if we loop, it is probably a non-simple polygon */ if ( ( count -- ) <= 0 ) { //** Triangulate: ERROR - probable bad polygon! //throw ( "Warning, unable to triangulate polygon!" ); //return null; // Sometimes warning is fine, especially polygons are triangulated in reverse. console.log( 'Warning, unable to triangulate polygon!' ); if ( indices ) return vertIndices; return result; } /* three consecutive vertices in current polygon, <u,v,w> */ u = v; if ( nv <= u ) u = 0; /* previous */ v = u + 1; if ( nv <= v ) v = 0; /* new v */ w = v + 1; if ( nv <= w ) w = 0; /* next */ if ( snip( contour, u, v, w, nv, verts ) ) { var a, b, c, s, t; /* true names of the vertices */ a = verts[ u ]; b = verts[ v ]; c = verts[ w ]; /* output Triangle */ result.push( [ contour[ a ], contour[ b ], contour[ c ] ] ); vertIndices.push( [ verts[ u ], verts[ v ], verts[ w ] ] ); /* remove v from the remaining polygon */ for ( s = v, t = v + 1; t < nv; s++, t++ ) { verts[ s ] = verts[ t ]; } nv --; /* reset error detection counter */ count = 2 * nv; } } if ( indices ) return vertIndices; return result; }
[ "function", "(", "contour", ",", "indices", ")", "{", "var", "n", "=", "contour", ".", "length", ";", "if", "(", "n", "<", "3", ")", "return", "null", ";", "var", "result", "=", "[", "]", ",", "verts", "=", "[", "]", ",", "vertIndices", "=", "[", "]", ";", "var", "u", ",", "v", ",", "w", ";", "if", "(", "area", "(", "contour", ")", ">", "0.0", ")", "{", "for", "(", "v", "=", "0", ";", "v", "<", "n", ";", "v", "++", ")", "verts", "[", "v", "]", "=", "v", ";", "}", "else", "{", "for", "(", "v", "=", "0", ";", "v", "<", "n", ";", "v", "++", ")", "verts", "[", "v", "]", "=", "(", "n", "-", "1", ")", "-", "v", ";", "}", "var", "nv", "=", "n", ";", "var", "count", "=", "2", "*", "nv", ";", "for", "(", "v", "=", "nv", "-", "1", ";", "nv", ">", "2", ";", ")", "{", "if", "(", "(", "count", "--", ")", "<=", "0", ")", "{", "console", ".", "log", "(", "'Warning, unable to triangulate polygon!'", ")", ";", "if", "(", "indices", ")", "return", "vertIndices", ";", "return", "result", ";", "}", "u", "=", "v", ";", "if", "(", "nv", "<=", "u", ")", "u", "=", "0", ";", "v", "=", "u", "+", "1", ";", "if", "(", "nv", "<=", "v", ")", "v", "=", "0", ";", "w", "=", "v", "+", "1", ";", "if", "(", "nv", "<=", "w", ")", "w", "=", "0", ";", "if", "(", "snip", "(", "contour", ",", "u", ",", "v", ",", "w", ",", "nv", ",", "verts", ")", ")", "{", "var", "a", ",", "b", ",", "c", ",", "s", ",", "t", ";", "a", "=", "verts", "[", "u", "]", ";", "b", "=", "verts", "[", "v", "]", ";", "c", "=", "verts", "[", "w", "]", ";", "result", ".", "push", "(", "[", "contour", "[", "a", "]", ",", "contour", "[", "b", "]", ",", "contour", "[", "c", "]", "]", ")", ";", "vertIndices", ".", "push", "(", "[", "verts", "[", "u", "]", ",", "verts", "[", "v", "]", ",", "verts", "[", "w", "]", "]", ")", ";", "for", "(", "s", "=", "v", ",", "t", "=", "v", "+", "1", ";", "t", "<", "nv", ";", "s", "++", ",", "t", "++", ")", "{", "verts", "[", "s", "]", "=", "verts", "[", "t", "]", ";", "}", "nv", "--", ";", "count", "=", "2", "*", "nv", ";", "}", "}", "if", "(", "indices", ")", "return", "vertIndices", ";", "return", "result", ";", "}" ]
takes in an contour array and returns
[ "takes", "in", "an", "contour", "array", "and", "returns" ]
1d74986ef4477cb7c2d667522855c04cbc0edcb0
https://github.com/bunnybones1/threejs-light-probe/blob/1d74986ef4477cb7c2d667522855c04cbc0edcb0/lib/three.js#L26695-L26789
train
ucd-cws/calvin-network-tools
nodejs/pri/debugger/parser.js
parseNode
function parseNode(line) { current = { is : 'NODE', type : 'NODE', id : line.substr(10, 10).trim().toLowerCase(), initialStorage : line.substr(20, 10).trim(), areaCapfactor : line.substr(30, 10).trim(), endingStorage : line.substr(40, 10).trim() }; }
javascript
function parseNode(line) { current = { is : 'NODE', type : 'NODE', id : line.substr(10, 10).trim().toLowerCase(), initialStorage : line.substr(20, 10).trim(), areaCapfactor : line.substr(30, 10).trim(), endingStorage : line.substr(40, 10).trim() }; }
[ "function", "parseNode", "(", "line", ")", "{", "current", "=", "{", "is", ":", "'NODE'", ",", "type", ":", "'NODE'", ",", "id", ":", "line", ".", "substr", "(", "10", ",", "10", ")", ".", "trim", "(", ")", ".", "toLowerCase", "(", ")", ",", "initialStorage", ":", "line", ".", "substr", "(", "20", ",", "10", ")", ".", "trim", "(", ")", ",", "areaCapfactor", ":", "line", ".", "substr", "(", "30", ",", "10", ")", ".", "trim", "(", ")", ",", "endingStorage", ":", "line", ".", "substr", "(", "40", ",", "10", ")", ".", "trim", "(", ")", "}", ";", "}" ]
LINK DIVR DIVR SR_SCC
[ "LINK", "DIVR", "DIVR", "SR_SCC" ]
9c276972394878dfb6927b56303fca4c4a2bf8f5
https://github.com/ucd-cws/calvin-network-tools/blob/9c276972394878dfb6927b56303fca4c4a2bf8f5/nodejs/pri/debugger/parser.js#L45-L54
train
WorldMobileCoin/wmcc-core
src/wmcc/uri.js
URI
function URI(options) { if (!(this instanceof URI)) return new URI(options); this.address = new Address(); this.amount = -1; this.label = null; this.message = null; this.request = null; if (options) this.fromOptions(options); }
javascript
function URI(options) { if (!(this instanceof URI)) return new URI(options); this.address = new Address(); this.amount = -1; this.label = null; this.message = null; this.request = null; if (options) this.fromOptions(options); }
[ "function", "URI", "(", "options", ")", "{", "if", "(", "!", "(", "this", "instanceof", "URI", ")", ")", "return", "new", "URI", "(", "options", ")", ";", "this", ".", "address", "=", "new", "Address", "(", ")", ";", "this", ".", "amount", "=", "-", "1", ";", "this", ".", "label", "=", "null", ";", "this", ".", "message", "=", "null", ";", "this", ".", "request", "=", "null", ";", "if", "(", "options", ")", "this", ".", "fromOptions", "(", "options", ")", ";", "}" ]
Represents a WMCC URI. @alias module:wmcc.URI @constructor @param {Object|String} options @property {Address} address @property {Amount} amount @property {String|null} label @property {String|null} message @property {String|null} request
[ "Represents", "a", "WMCC", "URI", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/wmcc/uri.js#L30-L42
train
WorldMobileCoin/wmcc-core
src/primitives/tx.js
TX
function TX(options) { if (!(this instanceof TX)) return new TX(options); this.version = 1; this.inputs = []; this.outputs = []; this.locktime = 0; this.mutable = false; this._hash = null; this._hhash = null; this._whash = null; this._raw = null; this._size = -1; this._witness = -1; this._sigops = -1; this._hashPrevouts = null; this._hashSequence = null; this._hashOutputs = null; if (options) this.fromOptions(options); }
javascript
function TX(options) { if (!(this instanceof TX)) return new TX(options); this.version = 1; this.inputs = []; this.outputs = []; this.locktime = 0; this.mutable = false; this._hash = null; this._hhash = null; this._whash = null; this._raw = null; this._size = -1; this._witness = -1; this._sigops = -1; this._hashPrevouts = null; this._hashSequence = null; this._hashOutputs = null; if (options) this.fromOptions(options); }
[ "function", "TX", "(", "options", ")", "{", "if", "(", "!", "(", "this", "instanceof", "TX", ")", ")", "return", "new", "TX", "(", "options", ")", ";", "this", ".", "version", "=", "1", ";", "this", ".", "inputs", "=", "[", "]", ";", "this", ".", "outputs", "=", "[", "]", ";", "this", ".", "locktime", "=", "0", ";", "this", ".", "mutable", "=", "false", ";", "this", ".", "_hash", "=", "null", ";", "this", ".", "_hhash", "=", "null", ";", "this", ".", "_whash", "=", "null", ";", "this", ".", "_raw", "=", "null", ";", "this", ".", "_size", "=", "-", "1", ";", "this", ".", "_witness", "=", "-", "1", ";", "this", ".", "_sigops", "=", "-", "1", ";", "this", ".", "_hashPrevouts", "=", "null", ";", "this", ".", "_hashSequence", "=", "null", ";", "this", ".", "_hashOutputs", "=", "null", ";", "if", "(", "options", ")", "this", ".", "fromOptions", "(", "options", ")", ";", "}" ]
A static transaction object. @alias module:primitives.TX @constructor @param {Object} options - Transaction fields. @property {Number} version - Transaction version. Note that WMCC_Core reads versions as unsigned even though they are signed at the protocol level. This value will never be negative. @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
[ "A", "static", "transaction", "object", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/primitives/tx.js#L49-L75
train
WorldMobileCoin/wmcc-core
src/utils/mappedlock.js
MappedLock
function MappedLock() { if (!(this instanceof MappedLock)) return MappedLock.create(); this.jobs = new Map(); this.busy = new Set(); this.destroyed = false; }
javascript
function MappedLock() { if (!(this instanceof MappedLock)) return MappedLock.create(); this.jobs = new Map(); this.busy = new Set(); this.destroyed = false; }
[ "function", "MappedLock", "(", ")", "{", "if", "(", "!", "(", "this", "instanceof", "MappedLock", ")", ")", "return", "MappedLock", ".", "create", "(", ")", ";", "this", ".", "jobs", "=", "new", "Map", "(", ")", ";", "this", ".", "busy", "=", "new", "Set", "(", ")", ";", "this", ".", "destroyed", "=", "false", ";", "}" ]
Represents a mutex lock for locking asynchronous object methods. Locks methods according to passed-in key. @alias module:utils.MappedLock @constructor
[ "Represents", "a", "mutex", "lock", "for", "locking", "asynchronous", "object", "methods", ".", "Locks", "methods", "according", "to", "passed", "-", "in", "key", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/utils/mappedlock.js#L23-L30
train
blakeembrey/kroute
lib/layer.js
decode
function decode (param) { try { return decodeURIComponent(param) } catch (_) { var err = new Error('Failed to decode param "' + param + '"') err.status = 400 throw err } }
javascript
function decode (param) { try { return decodeURIComponent(param) } catch (_) { var err = new Error('Failed to decode param "' + param + '"') err.status = 400 throw err } }
[ "function", "decode", "(", "param", ")", "{", "try", "{", "return", "decodeURIComponent", "(", "param", ")", "}", "catch", "(", "_", ")", "{", "var", "err", "=", "new", "Error", "(", "'Failed to decode param \"'", "+", "param", "+", "'\"'", ")", "err", ".", "status", "=", "400", "throw", "err", "}", "}" ]
URI decode a string. @param {String} param @return {String}
[ "URI", "decode", "a", "string", "." ]
b39f76fb6402e257a8b4d6b26b6511d16fa22871
https://github.com/blakeembrey/kroute/blob/b39f76fb6402e257a8b4d6b26b6511d16fa22871/lib/layer.js#L9-L17
train
WorldMobileCoin/wmcc-core
src/blockchain/chainentry.js
ChainEntry
function ChainEntry(options) { if (!(this instanceof ChainEntry)) return new ChainEntry(options); this.hash = encoding.NULL_HASH; this.version = 1; this.prevBlock = encoding.NULL_HASH; this.merkleRoot = encoding.NULL_HASH; this.time = 0; this.bits = 0; this.nonce = 0; this.height = 0; this.chainwork = ZERO; if (options) this.fromOptions(options); }
javascript
function ChainEntry(options) { if (!(this instanceof ChainEntry)) return new ChainEntry(options); this.hash = encoding.NULL_HASH; this.version = 1; this.prevBlock = encoding.NULL_HASH; this.merkleRoot = encoding.NULL_HASH; this.time = 0; this.bits = 0; this.nonce = 0; this.height = 0; this.chainwork = ZERO; if (options) this.fromOptions(options); }
[ "function", "ChainEntry", "(", "options", ")", "{", "if", "(", "!", "(", "this", "instanceof", "ChainEntry", ")", ")", "return", "new", "ChainEntry", "(", "options", ")", ";", "this", ".", "hash", "=", "encoding", ".", "NULL_HASH", ";", "this", ".", "version", "=", "1", ";", "this", ".", "prevBlock", "=", "encoding", ".", "NULL_HASH", ";", "this", ".", "merkleRoot", "=", "encoding", ".", "NULL_HASH", ";", "this", ".", "time", "=", "0", ";", "this", ".", "bits", "=", "0", ";", "this", ".", "nonce", "=", "0", ";", "this", ".", "height", "=", "0", ";", "this", ".", "chainwork", "=", "ZERO", ";", "if", "(", "options", ")", "this", ".", "fromOptions", "(", "options", ")", ";", "}" ]
Represents an entry in the chain. Unlike other bitcoin fullnodes, we store the chainwork _with_ the entry in order to avoid reading the entire chain index on boot and recalculating the chainworks. @alias module:blockchain.ChainEntry @constructor @param {Object?} options @property {Hash} hash @property {Number} version - Transaction version. Note that wmcc_core reads versions as unsigned even though they are signed at the protocol level. This value will never be negative. @property {Hash} prevBlock @property {Hash} merkleRoot @property {Number} time @property {Number} bits @property {Number} nonce @property {Number} height @property {BN} chainwork @property {ReversedHash} rhash - Reversed block hash (uint256le).
[ "Represents", "an", "entry", "in", "the", "chain", ".", "Unlike", "other", "bitcoin", "fullnodes", "we", "store", "the", "chainwork", "_with_", "the", "entry", "in", "order", "to", "avoid", "reading", "the", "entire", "chain", "index", "on", "boot", "and", "recalculating", "the", "chainworks", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/blockchain/chainentry.js#L50-L66
train
WorldMobileCoin/wmcc-core
src/bip70/paymentrequest.js
PaymentRequest
function PaymentRequest(options) { if (!(this instanceof PaymentRequest)) return new PaymentRequest(options); this.version = -1; this.pkiType = null; this.pkiData = null; this.paymentDetails = new PaymentDetails(); this.signature = null; if (options) this.fromOptions(options); }
javascript
function PaymentRequest(options) { if (!(this instanceof PaymentRequest)) return new PaymentRequest(options); this.version = -1; this.pkiType = null; this.pkiData = null; this.paymentDetails = new PaymentDetails(); this.signature = null; if (options) this.fromOptions(options); }
[ "function", "PaymentRequest", "(", "options", ")", "{", "if", "(", "!", "(", "this", "instanceof", "PaymentRequest", ")", ")", "return", "new", "PaymentRequest", "(", "options", ")", ";", "this", ".", "version", "=", "-", "1", ";", "this", ".", "pkiType", "=", "null", ";", "this", ".", "pkiData", "=", "null", ";", "this", ".", "paymentDetails", "=", "new", "PaymentDetails", "(", ")", ";", "this", ".", "signature", "=", "null", ";", "if", "(", "options", ")", "this", ".", "fromOptions", "(", "options", ")", ";", "}" ]
Represents a BIP70 payment request. @alias module:bip70.PaymentRequest @constructor @param {Object?} options @property {Number} version @property {String|null} pkiType @property {Buffer|null} pkiData @property {PaymentDetails} paymentDetails @property {Buffer|null} signature
[ "Represents", "a", "BIP70", "payment", "request", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/bip70/paymentrequest.js#L34-L46
train
WorldMobileCoin/wmcc-core
src/protocol/errors.js
VerifyError
function VerifyError(msg, code, reason, score, malleated) { Error.call(this); assert(typeof code === 'string'); assert(typeof reason === 'string'); assert(score >= 0); this.type = 'VerifyError'; this.message = ''; this.code = code; this.reason = reason; this.score = score; this.hash = msg.hash('hex'); this.malleated = malleated || false; this.message = `Verification failure: ${reason}` + ` (code=${code} score=${score} hash=${msg.rhash()})`; if (Error.captureStackTrace) Error.captureStackTrace(this, VerifyError); }
javascript
function VerifyError(msg, code, reason, score, malleated) { Error.call(this); assert(typeof code === 'string'); assert(typeof reason === 'string'); assert(score >= 0); this.type = 'VerifyError'; this.message = ''; this.code = code; this.reason = reason; this.score = score; this.hash = msg.hash('hex'); this.malleated = malleated || false; this.message = `Verification failure: ${reason}` + ` (code=${code} score=${score} hash=${msg.rhash()})`; if (Error.captureStackTrace) Error.captureStackTrace(this, VerifyError); }
[ "function", "VerifyError", "(", "msg", ",", "code", ",", "reason", ",", "score", ",", "malleated", ")", "{", "Error", ".", "call", "(", "this", ")", ";", "assert", "(", "typeof", "code", "===", "'string'", ")", ";", "assert", "(", "typeof", "reason", "===", "'string'", ")", ";", "assert", "(", "score", ">=", "0", ")", ";", "this", ".", "type", "=", "'VerifyError'", ";", "this", ".", "message", "=", "''", ";", "this", ".", "code", "=", "code", ";", "this", ".", "reason", "=", "reason", ";", "this", ".", "score", "=", "score", ";", "this", ".", "hash", "=", "msg", ".", "hash", "(", "'hex'", ")", ";", "this", ".", "malleated", "=", "malleated", "||", "false", ";", "this", ".", "message", "=", "`", "${", "reason", "}", "`", "+", "`", "${", "code", "}", "${", "score", "}", "${", "msg", ".", "rhash", "(", ")", "}", "`", ";", "if", "(", "Error", ".", "captureStackTrace", ")", "Error", ".", "captureStackTrace", "(", "this", ",", "VerifyError", ")", ";", "}" ]
An error thrown during verification. Can be either a mempool transaction validation error or a blockchain block verification error. Ultimately used to send `reject` packets to peers. @constructor @extends Error @param {Block|TX} msg @param {String} code - Reject packet code. @param {String} reason - Reject packet reason. @param {Number} score - Ban score increase (can be -1 for no reject packet). @param {Boolean} malleated @property {String} code @property {Buffer} hash @property {Number} height (will be the coinbase height if not present). @property {Number} score @property {String} message @property {Boolean} malleated
[ "An", "error", "thrown", "during", "verification", ".", "Can", "be", "either", "a", "mempool", "transaction", "validation", "error", "or", "a", "blockchain", "block", "verification", "error", ".", "Ultimately", "used", "to", "send", "reject", "packets", "to", "peers", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/protocol/errors.js#L41-L61
train
bigpipe/bigpipe.js
pagelet.js
Pagelet
function Pagelet(bigpipe) { if (!(this instanceof Pagelet)) return new Pagelet(bigpipe); var self = this; // // Create one single Fortress instance that orchestrates all iframe based client // code. This sandbox variable should never be exposed to the outside world in // order to prevent leaking. // this.sandbox = sandbox = sandbox || new Fortress(); this.bigpipe = bigpipe; // // Add an initialized method which is __always__ called when the pagelet is // either destroyed directly, errored or loaded. // this.initialized = one(function initialized() { self.broadcast('initialized'); }); }
javascript
function Pagelet(bigpipe) { if (!(this instanceof Pagelet)) return new Pagelet(bigpipe); var self = this; // // Create one single Fortress instance that orchestrates all iframe based client // code. This sandbox variable should never be exposed to the outside world in // order to prevent leaking. // this.sandbox = sandbox = sandbox || new Fortress(); this.bigpipe = bigpipe; // // Add an initialized method which is __always__ called when the pagelet is // either destroyed directly, errored or loaded. // this.initialized = one(function initialized() { self.broadcast('initialized'); }); }
[ "function", "Pagelet", "(", "bigpipe", ")", "{", "if", "(", "!", "(", "this", "instanceof", "Pagelet", ")", ")", "return", "new", "Pagelet", "(", "bigpipe", ")", ";", "var", "self", "=", "this", ";", "this", ".", "sandbox", "=", "sandbox", "=", "sandbox", "||", "new", "Fortress", "(", ")", ";", "this", ".", "bigpipe", "=", "bigpipe", ";", "this", ".", "initialized", "=", "one", "(", "function", "initialized", "(", ")", "{", "self", ".", "broadcast", "(", "'initialized'", ")", ";", "}", ")", ";", "}" ]
Representation of a single pagelet. @constructor @param {BigPipe} bigpipe The BigPipe instance that was created. @api public
[ "Representation", "of", "a", "single", "pagelet", "." ]
80fe2630d363ed2b69f85d28792a9095a4167e3b
https://github.com/bigpipe/bigpipe.js/blob/80fe2630d363ed2b69f85d28792a9095a4167e3b/pagelet.js#L27-L47
train
bigpipe/bigpipe.js
pagelet.js
shout
function shout(name) { pagelet.bigpipe.emit.apply(pagelet.bigpipe, [ name.join(':'), pagelet ].concat(Array.prototype.slice.call(arguments, 1))); return pagelet; }
javascript
function shout(name) { pagelet.bigpipe.emit.apply(pagelet.bigpipe, [ name.join(':'), pagelet ].concat(Array.prototype.slice.call(arguments, 1))); return pagelet; }
[ "function", "shout", "(", "name", ")", "{", "pagelet", ".", "bigpipe", ".", "emit", ".", "apply", "(", "pagelet", ".", "bigpipe", ",", "[", "name", ".", "join", "(", "':'", ")", ",", "pagelet", "]", ".", "concat", "(", "Array", ".", "prototype", ".", "slice", ".", "call", "(", "arguments", ",", "1", ")", ")", ")", ";", "return", "pagelet", ";", "}" ]
Broadcast the event with namespaced name. @param {String} name Event name. @returns {Pagelet} @api private
[ "Broadcast", "the", "event", "with", "namespaced", "name", "." ]
80fe2630d363ed2b69f85d28792a9095a4167e3b
https://github.com/bigpipe/bigpipe.js/blob/80fe2630d363ed2b69f85d28792a9095a4167e3b/pagelet.js#L203-L210
train
kaisellgren/ChiSquare
lib/chi-square.js
function(buffer) { var inputSize = buffer.length; // Holds an array that represents the count of various characters. var charCount = []; // Loop through the bytes and increase charCount. for (var a = 0; a < inputSize; a++) { var temp = buffer.readUInt8(a); if (charCount[temp] !== undefined) { charCount[temp]++; } else { charCount[temp] = 1; } } // The average number of times a specific character should occur. var expectedCount = inputSize / 256; var chiSquare = 0; for (var i = 0; i < 256; i++) { // Ideally this would be close to 0. a = (charCount[i] !== undefined ? charCount[i] : 0) - expectedCount; chiSquare += (a * a) / expectedCount; } return calculateChiSquareProbability(parseFloat(chiSquare.toFixed(2)), 255); }
javascript
function(buffer) { var inputSize = buffer.length; // Holds an array that represents the count of various characters. var charCount = []; // Loop through the bytes and increase charCount. for (var a = 0; a < inputSize; a++) { var temp = buffer.readUInt8(a); if (charCount[temp] !== undefined) { charCount[temp]++; } else { charCount[temp] = 1; } } // The average number of times a specific character should occur. var expectedCount = inputSize / 256; var chiSquare = 0; for (var i = 0; i < 256; i++) { // Ideally this would be close to 0. a = (charCount[i] !== undefined ? charCount[i] : 0) - expectedCount; chiSquare += (a * a) / expectedCount; } return calculateChiSquareProbability(parseFloat(chiSquare.toFixed(2)), 255); }
[ "function", "(", "buffer", ")", "{", "var", "inputSize", "=", "buffer", ".", "length", ";", "var", "charCount", "=", "[", "]", ";", "for", "(", "var", "a", "=", "0", ";", "a", "<", "inputSize", ";", "a", "++", ")", "{", "var", "temp", "=", "buffer", ".", "readUInt8", "(", "a", ")", ";", "if", "(", "charCount", "[", "temp", "]", "!==", "undefined", ")", "{", "charCount", "[", "temp", "]", "++", ";", "}", "else", "{", "charCount", "[", "temp", "]", "=", "1", ";", "}", "}", "var", "expectedCount", "=", "inputSize", "/", "256", ";", "var", "chiSquare", "=", "0", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "256", ";", "i", "++", ")", "{", "a", "=", "(", "charCount", "[", "i", "]", "!==", "undefined", "?", "charCount", "[", "i", "]", ":", "0", ")", "-", "expectedCount", ";", "chiSquare", "+=", "(", "a", "*", "a", ")", "/", "expectedCount", ";", "}", "return", "calculateChiSquareProbability", "(", "parseFloat", "(", "chiSquare", ".", "toFixed", "(", "2", ")", ")", ",", "255", ")", ";", "}" ]
Calculates a Chi-square distribution over a sequence of bytes within the Buffer. The result is a float representing the probability of how frequently a truly random sequence of bytes would exceed the calculated value. Ideally this float should have a value of 0.5. If so, the given Buffer contained random data. @param {Buffer} buffer @return {Number}
[ "Calculates", "a", "Chi", "-", "square", "distribution", "over", "a", "sequence", "of", "bytes", "within", "the", "Buffer", ".", "The", "result", "is", "a", "float", "representing", "the", "probability", "of", "how", "frequently", "a", "truly", "random", "sequence", "of", "bytes", "would", "exceed", "the", "calculated", "value", "." ]
2e7aa905f0f44a2d4be85ceb8e9e3863dc51c4b7
https://github.com/kaisellgren/ChiSquare/blob/2e7aa905f0f44a2d4be85ceb8e9e3863dc51c4b7/lib/chi-square.js#L18-L49
train
kaisellgren/ChiSquare
lib/chi-square.js
calculateChiSquareProbability
function calculateChiSquareProbability(x, df) { if (x <= 0.0 || df < 1) return 1.0; var a = 0.5 * x; if (df > 1) var y = calculateExponent(-a); var s = 2.0 * calculateNormalZProbability(-Math.sqrt(x)); if (df > 2) { x = 0.5 * (df - 1.0); var z = 0.5; if (a > BIG_X) { var e = LOG_SQRT_PI; var c = Math.log(a); while (z <= x) { e = Math.log(z) + e; s += calculateExponent(c * z - a - e); z += 1.0; } return (s); } else { e = I_SQRT_PI / Math.sqrt(a); c = 0.0; while (z <= x) { e = e * (a / z); c = c + e; z += 1.0; } return (c * y + s); } } return s; }
javascript
function calculateChiSquareProbability(x, df) { if (x <= 0.0 || df < 1) return 1.0; var a = 0.5 * x; if (df > 1) var y = calculateExponent(-a); var s = 2.0 * calculateNormalZProbability(-Math.sqrt(x)); if (df > 2) { x = 0.5 * (df - 1.0); var z = 0.5; if (a > BIG_X) { var e = LOG_SQRT_PI; var c = Math.log(a); while (z <= x) { e = Math.log(z) + e; s += calculateExponent(c * z - a - e); z += 1.0; } return (s); } else { e = I_SQRT_PI / Math.sqrt(a); c = 0.0; while (z <= x) { e = e * (a / z); c = c + e; z += 1.0; } return (c * y + s); } } return s; }
[ "function", "calculateChiSquareProbability", "(", "x", ",", "df", ")", "{", "if", "(", "x", "<=", "0.0", "||", "df", "<", "1", ")", "return", "1.0", ";", "var", "a", "=", "0.5", "*", "x", ";", "if", "(", "df", ">", "1", ")", "var", "y", "=", "calculateExponent", "(", "-", "a", ")", ";", "var", "s", "=", "2.0", "*", "calculateNormalZProbability", "(", "-", "Math", ".", "sqrt", "(", "x", ")", ")", ";", "if", "(", "df", ">", "2", ")", "{", "x", "=", "0.5", "*", "(", "df", "-", "1.0", ")", ";", "var", "z", "=", "0.5", ";", "if", "(", "a", ">", "BIG_X", ")", "{", "var", "e", "=", "LOG_SQRT_PI", ";", "var", "c", "=", "Math", ".", "log", "(", "a", ")", ";", "while", "(", "z", "<=", "x", ")", "{", "e", "=", "Math", ".", "log", "(", "z", ")", "+", "e", ";", "s", "+=", "calculateExponent", "(", "c", "*", "z", "-", "a", "-", "e", ")", ";", "z", "+=", "1.0", ";", "}", "return", "(", "s", ")", ";", "}", "else", "{", "e", "=", "I_SQRT_PI", "/", "Math", ".", "sqrt", "(", "a", ")", ";", "c", "=", "0.0", ";", "while", "(", "z", "<=", "x", ")", "{", "e", "=", "e", "*", "(", "a", "/", "z", ")", ";", "c", "=", "c", "+", "e", ";", "z", "+=", "1.0", ";", "}", "return", "(", "c", "*", "y", "+", "s", ")", ";", "}", "}", "return", "s", ";", "}" ]
Calculates the probability for the results of the Chi-square test. @param {Number} x Chi-square value. @param {Number} df Degrees of freedom. @return {Number}
[ "Calculates", "the", "probability", "for", "the", "results", "of", "the", "Chi", "-", "square", "test", "." ]
2e7aa905f0f44a2d4be85ceb8e9e3863dc51c4b7
https://github.com/kaisellgren/ChiSquare/blob/2e7aa905f0f44a2d4be85ceb8e9e3863dc51c4b7/lib/chi-square.js#L69-L111
train
kaisellgren/ChiSquare
lib/chi-square.js
calculateNormalZProbability
function calculateNormalZProbability(z) { if (z == 0.0) { var x = 0.0; } else { var y = 0.5 * Math.abs(z); // Here comes the magic. if (y >= Z_MAX * 0.5) { x = 1.0; } else if (y < 1.0) { var w = y * y; x = 0.000124818987 * w -0.001075204047; x *= w +0.005198775019; x *= w -0.019198292004; x *= w +0.059054035642; x *= w -0.151968751364; x *= w +0.319152932694; x *= w -0.531923007300; x *= w +0.797884560593; x *= y * 2.0; } else { y -= 2.0; x = -0.000045255659 * y +0.000152529290; x *= y -0.000019538132; x *= y -0.000676904986; x *= y +0.001390604284; x *= y -0.000794620820; x *= y -0.002034254874; x *= y +0.006549791214; x *= y -0.010557625006; x *= y -0.010557625006; x *= y +0.011630447319; x *= y -0.009279453341; x *= y +0.005353579108; x *= y -0.002141268741; x *= y +0.000535310849; x *= y +0.999936657524; } } return z > 0.0 ? (x + 1.0) * 0.5 : (1.0 - x) * 0.5; }
javascript
function calculateNormalZProbability(z) { if (z == 0.0) { var x = 0.0; } else { var y = 0.5 * Math.abs(z); // Here comes the magic. if (y >= Z_MAX * 0.5) { x = 1.0; } else if (y < 1.0) { var w = y * y; x = 0.000124818987 * w -0.001075204047; x *= w +0.005198775019; x *= w -0.019198292004; x *= w +0.059054035642; x *= w -0.151968751364; x *= w +0.319152932694; x *= w -0.531923007300; x *= w +0.797884560593; x *= y * 2.0; } else { y -= 2.0; x = -0.000045255659 * y +0.000152529290; x *= y -0.000019538132; x *= y -0.000676904986; x *= y +0.001390604284; x *= y -0.000794620820; x *= y -0.002034254874; x *= y +0.006549791214; x *= y -0.010557625006; x *= y -0.010557625006; x *= y +0.011630447319; x *= y -0.009279453341; x *= y +0.005353579108; x *= y -0.002141268741; x *= y +0.000535310849; x *= y +0.999936657524; } } return z > 0.0 ? (x + 1.0) * 0.5 : (1.0 - x) * 0.5; }
[ "function", "calculateNormalZProbability", "(", "z", ")", "{", "if", "(", "z", "==", "0.0", ")", "{", "var", "x", "=", "0.0", ";", "}", "else", "{", "var", "y", "=", "0.5", "*", "Math", ".", "abs", "(", "z", ")", ";", "if", "(", "y", ">=", "Z_MAX", "*", "0.5", ")", "{", "x", "=", "1.0", ";", "}", "else", "if", "(", "y", "<", "1.0", ")", "{", "var", "w", "=", "y", "*", "y", ";", "x", "=", "0.000124818987", "*", "w", "-", "0.001075204047", ";", "x", "*=", "w", "+", "0.005198775019", ";", "x", "*=", "w", "-", "0.019198292004", ";", "x", "*=", "w", "+", "0.059054035642", ";", "x", "*=", "w", "-", "0.151968751364", ";", "x", "*=", "w", "+", "0.319152932694", ";", "x", "*=", "w", "-", "0.531923007300", ";", "x", "*=", "w", "+", "0.797884560593", ";", "x", "*=", "y", "*", "2.0", ";", "}", "else", "{", "y", "-=", "2.0", ";", "x", "=", "-", "0.000045255659", "*", "y", "+", "0.000152529290", ";", "x", "*=", "y", "-", "0.000019538132", ";", "x", "*=", "y", "-", "0.000676904986", ";", "x", "*=", "y", "+", "0.001390604284", ";", "x", "*=", "y", "-", "0.000794620820", ";", "x", "*=", "y", "-", "0.002034254874", ";", "x", "*=", "y", "+", "0.006549791214", ";", "x", "*=", "y", "-", "0.010557625006", ";", "x", "*=", "y", "-", "0.010557625006", ";", "x", "*=", "y", "+", "0.011630447319", ";", "x", "*=", "y", "-", "0.009279453341", ";", "x", "*=", "y", "+", "0.005353579108", ";", "x", "*=", "y", "-", "0.002141268741", ";", "x", "*=", "y", "+", "0.000535310849", ";", "x", "*=", "y", "+", "0.999936657524", ";", "}", "}", "return", "z", ">", "0.0", "?", "(", "x", "+", "1.0", ")", "*", "0.5", ":", "(", "1.0", "-", "x", ")", "*", "0.5", ";", "}" ]
Calculates the probability for the normal z. @param {Number} z @return {Number}
[ "Calculates", "the", "probability", "for", "the", "normal", "z", "." ]
2e7aa905f0f44a2d4be85ceb8e9e3863dc51c4b7
https://github.com/kaisellgren/ChiSquare/blob/2e7aa905f0f44a2d4be85ceb8e9e3863dc51c4b7/lib/chi-square.js#L119-L166
train
WorldMobileCoin/wmcc-core
src/workers/child.js
Child
function Child(file) { if (!(this instanceof Child)) return new Child(file); EventEmitter.call(this); bindExit(); children.add(this); this.init(file); }
javascript
function Child(file) { if (!(this instanceof Child)) return new Child(file); EventEmitter.call(this); bindExit(); children.add(this); this.init(file); }
[ "function", "Child", "(", "file", ")", "{", "if", "(", "!", "(", "this", "instanceof", "Child", ")", ")", "return", "new", "Child", "(", "file", ")", ";", "EventEmitter", ".", "call", "(", "this", ")", ";", "bindExit", "(", ")", ";", "children", ".", "add", "(", "this", ")", ";", "this", ".", "init", "(", "file", ")", ";", "}" ]
Represents a child process. @alias module:workers.Child @constructor @param {String} file
[ "Represents", "a", "child", "process", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/workers/child.js#L27-L37
train
WorldMobileCoin/wmcc-core
src/workers/child.js
bindExit
function bindExit() { if (exitBound) return; exitBound = true; listenExit(() => { for (const child of children) child.destroy(); }); }
javascript
function bindExit() { if (exitBound) return; exitBound = true; listenExit(() => { for (const child of children) child.destroy(); }); }
[ "function", "bindExit", "(", ")", "{", "if", "(", "exitBound", ")", "return", ";", "exitBound", "=", "true", ";", "listenExit", "(", "(", ")", "=>", "{", "for", "(", "const", "child", "of", "children", ")", "child", ".", "destroy", "(", ")", ";", "}", ")", ";", "}" ]
Cleanup all child processes. @private
[ "Cleanup", "all", "child", "processes", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/workers/child.js#L118-L128
train
WorldMobileCoin/wmcc-core
src/workers/child.js
listenExit
function listenExit(handler) { const onSighup = () => { process.exit(1 | 0x80); }; const onSigint = () => { process.exit(2 | 0x80); }; const onSigterm = () => { process.exit(15 | 0x80); }; const onError = (err) => { if (err && err.stack) console.error(String(err.stack)); else console.error(String(err)); process.exit(1); }; process.once('exit', handler); if (process.listenerCount('SIGHUP') === 0) process.once('SIGHUP', onSighup); if (process.listenerCount('SIGINT') === 0) process.once('SIGINT', onSigint); if (process.listenerCount('SIGTERM') === 0) process.once('SIGTERM', onSigterm); if (process.listenerCount('uncaughtException') === 0) process.once('uncaughtException', onError); process.on('newListener', (name) => { switch (name) { case 'SIGHUP': process.removeListener(name, onSighup); break; case 'SIGINT': process.removeListener(name, onSigint); break; case 'SIGTERM': process.removeListener(name, onSigterm); break; case 'uncaughtException': process.removeListener(name, onError); break; } }); }
javascript
function listenExit(handler) { const onSighup = () => { process.exit(1 | 0x80); }; const onSigint = () => { process.exit(2 | 0x80); }; const onSigterm = () => { process.exit(15 | 0x80); }; const onError = (err) => { if (err && err.stack) console.error(String(err.stack)); else console.error(String(err)); process.exit(1); }; process.once('exit', handler); if (process.listenerCount('SIGHUP') === 0) process.once('SIGHUP', onSighup); if (process.listenerCount('SIGINT') === 0) process.once('SIGINT', onSigint); if (process.listenerCount('SIGTERM') === 0) process.once('SIGTERM', onSigterm); if (process.listenerCount('uncaughtException') === 0) process.once('uncaughtException', onError); process.on('newListener', (name) => { switch (name) { case 'SIGHUP': process.removeListener(name, onSighup); break; case 'SIGINT': process.removeListener(name, onSigint); break; case 'SIGTERM': process.removeListener(name, onSigterm); break; case 'uncaughtException': process.removeListener(name, onError); break; } }); }
[ "function", "listenExit", "(", "handler", ")", "{", "const", "onSighup", "=", "(", ")", "=>", "{", "process", ".", "exit", "(", "1", "|", "0x80", ")", ";", "}", ";", "const", "onSigint", "=", "(", ")", "=>", "{", "process", ".", "exit", "(", "2", "|", "0x80", ")", ";", "}", ";", "const", "onSigterm", "=", "(", ")", "=>", "{", "process", ".", "exit", "(", "15", "|", "0x80", ")", ";", "}", ";", "const", "onError", "=", "(", "err", ")", "=>", "{", "if", "(", "err", "&&", "err", ".", "stack", ")", "console", ".", "error", "(", "String", "(", "err", ".", "stack", ")", ")", ";", "else", "console", ".", "error", "(", "String", "(", "err", ")", ")", ";", "process", ".", "exit", "(", "1", ")", ";", "}", ";", "process", ".", "once", "(", "'exit'", ",", "handler", ")", ";", "if", "(", "process", ".", "listenerCount", "(", "'SIGHUP'", ")", "===", "0", ")", "process", ".", "once", "(", "'SIGHUP'", ",", "onSighup", ")", ";", "if", "(", "process", ".", "listenerCount", "(", "'SIGINT'", ")", "===", "0", ")", "process", ".", "once", "(", "'SIGINT'", ",", "onSigint", ")", ";", "if", "(", "process", ".", "listenerCount", "(", "'SIGTERM'", ")", "===", "0", ")", "process", ".", "once", "(", "'SIGTERM'", ",", "onSigterm", ")", ";", "if", "(", "process", ".", "listenerCount", "(", "'uncaughtException'", ")", "===", "0", ")", "process", ".", "once", "(", "'uncaughtException'", ",", "onError", ")", ";", "process", ".", "on", "(", "'newListener'", ",", "(", "name", ")", "=>", "{", "switch", "(", "name", ")", "{", "case", "'SIGHUP'", ":", "process", ".", "removeListener", "(", "name", ",", "onSighup", ")", ";", "break", ";", "case", "'SIGINT'", ":", "process", ".", "removeListener", "(", "name", ",", "onSigint", ")", ";", "break", ";", "case", "'SIGTERM'", ":", "process", ".", "removeListener", "(", "name", ",", "onSigterm", ")", ";", "break", ";", "case", "'uncaughtException'", ":", "process", ".", "removeListener", "(", "name", ",", "onError", ")", ";", "break", ";", "}", "}", ")", ";", "}" ]
Listen for exit. @param {Function} handler @private
[ "Listen", "for", "exit", "." ]
29c3759a175341cedae6b744c53eda628c669317
https://github.com/WorldMobileCoin/wmcc-core/blob/29c3759a175341cedae6b744c53eda628c669317/src/workers/child.js#L136-L188
train
zaim/webcolors
gulpfile.js
parsePalette
function parsePalette (palette) { var vars = { camelCased : {}, paramCased : {} }; Object.keys(palette).forEach(function (key) { var hex = color(palette[key]).hexString(); vars.camelCased[cameled(key)] = hex; vars.paramCased[dashed(key)] = hex; }); return vars; }
javascript
function parsePalette (palette) { var vars = { camelCased : {}, paramCased : {} }; Object.keys(palette).forEach(function (key) { var hex = color(palette[key]).hexString(); vars.camelCased[cameled(key)] = hex; vars.paramCased[dashed(key)] = hex; }); return vars; }
[ "function", "parsePalette", "(", "palette", ")", "{", "var", "vars", "=", "{", "camelCased", ":", "{", "}", ",", "paramCased", ":", "{", "}", "}", ";", "Object", ".", "keys", "(", "palette", ")", ".", "forEach", "(", "function", "(", "key", ")", "{", "var", "hex", "=", "color", "(", "palette", "[", "key", "]", ")", ".", "hexString", "(", ")", ";", "vars", ".", "camelCased", "[", "cameled", "(", "key", ")", "]", "=", "hex", ";", "vars", ".", "paramCased", "[", "dashed", "(", "key", ")", "]", "=", "hex", ";", "}", ")", ";", "return", "vars", ";", "}" ]
Fix palette values to full hex string
[ "Fix", "palette", "values", "to", "full", "hex", "string" ]
548d4466c653336f8c861ddedf67d432a804590e
https://github.com/zaim/webcolors/blob/548d4466c653336f8c861ddedf67d432a804590e/gulpfile.js#L17-L28
train