_id
stringlengths
2
6
title
stringlengths
0
58
partition
stringclasses
3 values
text
stringlengths
52
373k
language
stringclasses
1 value
meta_information
dict
q7600
processAliases
train
function processAliases(aliases) { const result = { long: {}, short: {} }; if (!aliases) { return result; } if (!Array.isArray(aliases)) { if (typeof aliases === 'object') { if (aliases.long && typeof aliases.long === 'object') { Object.assign(result.long, aliases.long); } if (aliases.short ...
javascript
{ "resource": "" }
q7601
getClosestNode
train
function getClosestNode (element, method, selector) { do { element = element[method] } while (element && ((selector && !matches(element, selector)) || !util.isElement(element))) return element }
javascript
{ "resource": "" }
q7602
_create
train
function _create (elements, selector) { return selector == null ? new Rye(elements) : new Rye(elements).filter(selector) }
javascript
{ "resource": "" }
q7603
createCreateStreamWrap
train
function createCreateStreamWrap(api) { return function createStreamWrap(create_stream) { return function create_stream_trace() { if (!this.stream) { Object.defineProperty(this, 'stream', { get: function () { return this._google_trace_stream; }, set: function (val) { a...
javascript
{ "resource": "" }
q7604
createStreamListenersWrap
train
function createStreamListenersWrap(api) { return function streamListenersWrap(install_stream_listeners) { return function install_stream_listeners_trace() { api.wrapEmitter(this.stream); return install_stream_listeners.apply(this, arguments); }; }; }
javascript
{ "resource": "" }
q7605
getDocWithDefault
train
function getDocWithDefault(db, id, defaultDoc) { return db.get(id).catch(function (err) { /* istanbul ignore if */ if (err.status !== 404) { throw err; } defaultDoc._id = id; return db.put(defaultDoc).catch(function (err) { /* istanbul ignore if */ if (err.status !== 409) { // co...
javascript
{ "resource": "" }
q7606
getMainDoc
train
function getMainDoc(db) { return getDocWithDefault(db, MAIN_DOC_ID, {}).then(function (doc) { if (!doc._attachments) { doc._attachments = {}; } return doc; }); }
javascript
{ "resource": "" }
q7607
calculateTotalSize
train
function calculateTotalSize(mainDoc) { var digestsToSizes = {}; // dedup by digest, since that's what Pouch does under the hood Object.keys(mainDoc._attachments).forEach(function (attName) { var att = mainDoc._attachments[attName]; digestsToSizes[att.digest] = att.length; }); var total = 0; Object...
javascript
{ "resource": "" }
q7608
synchronous
train
function synchronous(promiseFactory) { return function () { var promise = queue.then(promiseFactory); queue = promise.catch(noop); // squelch return promise; }; }
javascript
{ "resource": "" }
q7609
getDigestsToLastUsed
train
function getDigestsToLastUsed(mainDoc, lastUsedDoc) { var result = {}; // dedup by digest, use the most recent date Object.keys(mainDoc._attachments).forEach(function (attName) { var att = mainDoc._attachments[attName]; var existing = result[att.digest] || 0; result[att.digest] = Math.max(existing, ...
javascript
{ "resource": "" }
q7610
getLeastRecentlyUsed
train
function getLeastRecentlyUsed(mainDoc, lastUsedDoc) { var digestsToLastUsed = getDigestsToLastUsed(mainDoc, lastUsedDoc); var min; var minDigest; Object.keys(digestsToLastUsed).forEach(function (digest) { var lastUsed = digestsToLastUsed[digest]; if (typeof min === 'undefined' || min > lastUsed) { ...
javascript
{ "resource": "" }
q7611
scheduleFrame
train
function scheduleFrame(context, method) { method = context[method]; return requestAnimationFrame(method.bind(context)); }
javascript
{ "resource": "" }
q7612
exec
train
function exec(target, method, args, onError, stack) { try { method.apply(target, args); } catch (e) { if (onError) { onError(e, stack); } } }
javascript
{ "resource": "" }
q7613
_logWarn
train
function _logWarn(title, stack, test = false, options = {}) { if (test) { return; } const { groupCollapsed, log, trace, groupEnd } = console; if (groupCollapsed && trace && groupEnd) { groupCollapsed(title); log(options.id); trace(stack.stack); groupEnd(title); } else { warn(`${title}\n${stack.stack}...
javascript
{ "resource": "" }
q7614
train
function(id, location) { var search = "?"+ (location.search || "") + "&hid=" + id; return (location.pathname || '/') + search + (location.hash ? ("#" + location.hash) : ""); }
javascript
{ "resource": "" }
q7615
train
function(location) { if (!location.search) return; location.search = location.search.replace(/&hid=([^&]+)/gi, function(c, v) { location.hid = v; return ""; }); location.path = location.pathname + (location.search ? ("?" + location.search) : ""); location.relative = location.path + (location.hash ? (...
javascript
{ "resource": "" }
q7616
_equals
train
function _equals(a, b) { switch (typeof a) { case 'undefined': case 'boolean': case 'string': case 'number': return a === b; case 'object': if (a === null) {return b === null;} if (_isArray(a)) { i...
javascript
{ "resource": "" }
q7617
train
function (prototype) { if (!_.isObject(prototype)) return {}; if (nativeCreate) return nativeCreate(prototype); Ctor.prototype = prototype; var result = new Ctor(); Ctor.prototype = null; return result; }
javascript
{ "resource": "" }
q7618
omit
train
function omit(obj, blackList) { var newObj = {}; Object.keys(obj || {}).forEach(function (key) { if (blackList.indexOf(key) === -1) { newObj[key] = obj[key]; } }); return newObj; }
javascript
{ "resource": "" }
q7619
parseStartKey
train
function parseStartKey(key, restOfLine) { // When a new key is encountered, the rest of the line is immediately added as // its value, by calling `flushBuffer`. flushBuffer(); incrementArrayElement(key); if (stackScope && stackScope.flags.indexOf('+') > -1) key = 'value'; ...
javascript
{ "resource": "" }
q7620
getParser
train
function getParser(delimiterOrParser) { var parser; if (typeof delimiterOrParser === 'string') { parser = discernParser(delimiterOrParser, { delimiter: true }); } else if (typeof delimiterOrParser === 'function' || (typeof delimiterOrParser === 'undefined' ? 'undefined' : _typeof(delimiterOrParser)) === 'obje...
javascript
{ "resource": "" }
q7621
formattingPreflight
train
function formattingPreflight(file, format) { if (file === '') { return []; } else if (!Array.isArray(file)) { notListError(format); } return file; }
javascript
{ "resource": "" }
q7622
readDbf
train
function readDbf(filePath, opts_, cb) { var parserOptions = { map: identity }; if (typeof cb === 'undefined') { cb = opts_; } else { parserOptions = typeof opts_ === 'function' ? { map: opts_ } : opts_; } readData(filePath, parserOptions, cb); }
javascript
{ "resource": "" }
q7623
readdirFilter
train
function readdirFilter(dirPath, opts_, cb) { if (typeof cb === 'undefined') { cb = opts_; opts_ = undefined; } readdir({ async: true }, dirPath, opts_, cb); }
javascript
{ "resource": "" }
q7624
readAml
train
function readAml(filePath, opts_, cb) { var parserOptions; if (typeof cb === 'undefined') { cb = opts_; } else { parserOptions = typeof opts_ === 'function' ? { map: opts_ } : opts_; } readData(filePath, { parser: parserAml, parserOptions: parserOptions }, cb); }
javascript
{ "resource": "" }
q7625
readAmlSync
train
function readAmlSync(filePath, opts_) { var parserOptions; if (typeof opts_ !== 'undefined') { parserOptions = typeof opts_ === 'function' ? { map: opts_ } : opts_; } return readDataSync(filePath, { parser: parserAml, parserOptions: parserOptions }); }
javascript
{ "resource": "" }
q7626
readCsv
train
function readCsv(filePath, opts_, cb) { var parserOptions; if (typeof cb === 'undefined') { cb = opts_; } else { parserOptions = typeof opts_ === 'function' ? { map: opts_ } : opts_; } readData(filePath, { parser: parserCsv, parserOptions: parserOptions }, cb); }
javascript
{ "resource": "" }
q7627
readCsvSync
train
function readCsvSync(filePath, opts_) { var parserOptions; if (typeof opts_ !== 'undefined') { parserOptions = typeof opts_ === 'function' ? { map: opts_ } : opts_; } return readDataSync(filePath, { parser: parserCsv, parserOptions: parserOptions }); }
javascript
{ "resource": "" }
q7628
readJson
train
function readJson(filePath, opts_, cb) { var parserOptions; if (typeof cb === 'undefined') { cb = opts_; } else { parserOptions = typeof opts_ === 'function' ? { map: opts_ } : opts_; } readData(filePath, { parser: parserJson, parserOptions: parserOptions }, cb); }
javascript
{ "resource": "" }
q7629
readJsonSync
train
function readJsonSync(filePath, opts_) { var parserOptions; if (typeof opts_ !== 'undefined') { parserOptions = typeof opts_ === 'function' ? { map: opts_ } : opts_; } return readDataSync(filePath, { parser: parserJson, parserOptions: parserOptions }); }
javascript
{ "resource": "" }
q7630
readPsv
train
function readPsv(filePath, opts_, cb) { var parserOptions; if (typeof cb === 'undefined') { cb = opts_; } else { parserOptions = typeof opts_ === 'function' ? { map: opts_ } : opts_; } readData(filePath, { parser: parserPsv, parserOptions: parserOptions }, cb); }
javascript
{ "resource": "" }
q7631
readPsvSync
train
function readPsvSync(filePath, opts_) { var parserOptions; if (typeof opts_ !== 'undefined') { parserOptions = typeof opts_ === 'function' ? { map: opts_ } : opts_; } return readDataSync(filePath, { parser: parserPsv, parserOptions: parserOptions }); }
javascript
{ "resource": "" }
q7632
readTsv
train
function readTsv(filePath, opts_, cb) { var parserOptions; if (typeof cb === 'undefined') { cb = opts_; } else { parserOptions = typeof opts_ === 'function' ? { map: opts_ } : opts_; } readData(filePath, { parser: parserTsv, parserOptions: parserOptions }, cb); }
javascript
{ "resource": "" }
q7633
readTsvSync
train
function readTsvSync(filePath, opts_) { var parserOptions; if (typeof opts_ !== 'undefined') { parserOptions = typeof opts_ === 'function' ? { map: opts_ } : opts_; } return readDataSync(filePath, { parser: parserTsv, parserOptions: parserOptions }); }
javascript
{ "resource": "" }
q7634
readTxt
train
function readTxt(filePath, opts_, cb) { var parserOptions; if (typeof cb === 'undefined') { cb = opts_; } else { parserOptions = typeof opts_ === 'function' ? { map: opts_ } : opts_; } readData(filePath, { parser: parserTxt, parserOptions: parserOptions }, cb); }
javascript
{ "resource": "" }
q7635
readTxtSync
train
function readTxtSync(filePath, opts_) { var parserOptions; if (typeof opts_ !== 'undefined') { parserOptions = typeof opts_ === 'function' ? { map: opts_ } : opts_; } return readDataSync(filePath, { parser: parserTxt, parserOptions: parserOptions }); }
javascript
{ "resource": "" }
q7636
_getInsertionIndex
train
function _getInsertionIndex (array, element, comparer, start, end) { if (array.length === 0) { return 0; } var pivot = (start + end) >> 1; var result = comparer( { value: element, index: pivot }, { value: array[pivot], index: pivot } ); if (end - start <= 1) { r...
javascript
{ "resource": "" }
q7637
_getNumConsecutiveHits
train
function _getNumConsecutiveHits (arrayLike, predicate) { var idx = 0; var len = arrayLike.length; while (idx < len && predicate(arrayLike[idx], idx, arrayLike)) { idx++; } return idx; }
javascript
{ "resource": "" }
q7638
train
function(src, dest) { var i = 0; var len = Math.min(src.length, dest.length); while(i < len) { dest[i] = src[i]; i++; } return dest; }
javascript
{ "resource": "" }
q7639
train
function(month, year1, year2) { var leap1 = isLeap(year1 - 1); var leap2 = isLeap(year2 - 1); if(month < 5 + leap1) return 0; return leap2 - leap1; }
javascript
{ "resource": "" }
q7640
train
function() { /** * Reference to this key event. */ var key_event = this; /** * An arbitrary timestamp in milliseconds, indicating this event's * position in time relative to other events. * * @type {Number} */ this.timestam...
javascript
{ "resource": "" }
q7641
train
function(charCode) { // We extend KeyEvent KeyEvent.apply(this); /** * The Unicode codepoint of the character that would be typed by the * key pressed. * * @type {Number} */ this.charCode = charCode; // Pull keysym from char code ...
javascript
{ "resource": "" }
q7642
update_modifier_state
train
function update_modifier_state(e) { // Get state var state = Guacamole.Keyboard.ModifierState.fromKeyboardEvent(e); // Release alt if implicitly released if (guac_keyboard.modifiers.alt && state.alt === false) { guac_keyboard.release(0xFFE9); // Left alt guac_ke...
javascript
{ "resource": "" }
q7643
release_simulated_altgr
train
function release_simulated_altgr(keysym) { // Both Ctrl+Alt must be pressed if simulated AltGr is in use if (!guac_keyboard.modifiers.ctrl || !guac_keyboard.modifiers.alt) return; // Assume [A-Z] never require AltGr if (keysym >= 0x0041 && keysym <= 0x005A) retu...
javascript
{ "resource": "" }
q7644
interpret_event
train
function interpret_event() { // Peek at first event in log var first = eventLog[0]; if (!first) return null; // Keydown event if (first instanceof KeydownEvent) { var keysym = null; var accepted_events = []; // If event itself i...
javascript
{ "resource": "" }
q7645
train
function(str) { var output; try { output = opts.template(str); } catch (e) { e.message = error.badTemplate + ': ' + e.message; return this.emit('error', new PluginError('gulp-concat-filenames', e)); } i...
javascript
{ "resource": "" }
q7646
transformIntoQueryParamSchema
train
function transformIntoQueryParamSchema(processedSchema) { return _.transform( processedSchema.items.properties, (result, value, key) => { const parameter = Object.assign( { name: key }, value, { type: Array.isArray(value.type) ? value.type[0]...
javascript
{ "resource": "" }
q7647
DOTHAT
train
function DOTHAT() { if (!(this instanceof DOTHAT)) { return new DOTHAT(); } this.displayOTron = new DisplayOTron('HAT'); this.lcd = new LCD(this.displayOTron); this.backlight = new Backlight(this.displayOTron); this.barGraph = new BarGraph(this.displayOTron); this.touch = new To...
javascript
{ "resource": "" }
q7648
setAuthType
train
function setAuthType(auth_type) { var headers = { 'Content-Type': 'application/json', 'Accept': 'application/json' }; if (auth_type == 'AccessToken') { headers['Authorization'] = _config.access_token; } else if (auth_type == 'AppCredentials') { headers['x-accela-appi...
javascript
{ "resource": "" }
q7649
escapeCharacters
train
function escapeCharacters(params) { return params; var find = new Array('.','-','%','/','\\\\',':','*','\\','<','>','|','?',' ','&','#'); var replace = new Array('.0','.1','.2','.3','.4','.5','.6','.7','.8','.9','.a','.b','.c','.d','.e'); var escaped = {}; for (var param in params) { if(typ...
javascript
{ "resource": "" }
q7650
replaceCharacter
train
function replaceCharacter(search, replace, subject, count) { var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0, f = [].concat(search), r = [].concat(replace), s = subject, ra = Object.prototype.toString.call(r) === '[object Array]', sa = Object.prototype.toString.call(s) === '[object Array]', s = []....
javascript
{ "resource": "" }
q7651
buildQueryString
train
function buildQueryString(params) { var querystring = ''; for(param in params) { querystring += '&' + param + '=' + params[param]; } return querystring; }
javascript
{ "resource": "" }
q7652
makeRequest
train
function makeRequest(options, callback) { request(options, function (error, response, body){ if (error) { callback(error, null); } else if (response.statusCode == 200) { callback( null, JSON.parse(body)); } else { callback(new Error('HTTP R...
javascript
{ "resource": "" }
q7653
_setFilter
train
function _setFilter(filt) { filt = filt.trim() if (filt === 'all') this.filter = filt else if (filt in _filters) { if (this.filter !== 'all' && this.filter.indexOf(filt) < 0) this.filter.push(filt) } else this.invalid('filter', filt) }
javascript
{ "resource": "" }
q7654
_createFilter
train
function _createFilter(res) { for (var i = 0; i < res.length; ++i) { var f = res[i] if (f instanceof RegExp) custfilt.push(f) else { //console.log('--- creating regex with `' + str + '`') try { f = new RegExp(f) custfilt.push(f) } catch ...
javascript
{ "resource": "" }
q7655
_getPathKey
train
function _getPathKey (target, key, includeNonEnumerables) { if (includeNonEnumerables && key in Object(target) || _isEnumerable(target, key)) { return key; } var n = +key; var len = target && target.length; return n >= -len && n < len ? n < 0 ? n + len : n : void 0; }
javascript
{ "resource": "" }
q7656
_sorter
train
function _sorter (reader, isDescending, comparer) { if (typeof reader !== "function" || reader === identity) { reader = null; } if (typeof comparer !== "function") { comparer = _comparer; } return { isDescending: isDescending === true, compare: function (a, b) { ...
javascript
{ "resource": "" }
q7657
_merge
train
function _merge (getKeys, a, b) { return reduce([a, b], function (result, source) { forEach(getKeys(source), function (key) { result[key] = source[key]; }); return result; }, {}); }
javascript
{ "resource": "" }
q7658
trigger
train
function trigger(el, name, options){ var event, type; type = eventTypes[name]; if (!type) { throw new SyntaxError('Unknown event type: '+type); } options = options || {}; inherit(defaults, options); if (document.createEvent) { // Standard Event event = document.createEvent(type); ...
javascript
{ "resource": "" }
q7659
train
function (util) { function printable(str) { return ('' + str).replace(/\n/g, '\\n').replace(/\r/g, '\\r') } function compare(actual, expected) { var pass = actual === expected return { pass: pass, message: util.buildFailureMessage( 'toHasLinesLi...
javascript
{ "resource": "" }
q7660
train
function (/*util*/) { function compare(actual, expected) { return { pass: actual instanceof Error && ('' + actual).indexOf(expected) >= 0 } } return {compare: compare} }
javascript
{ "resource": "" }
q7661
mousewheel_handler
train
function mousewheel_handler(e) { // Determine approximate scroll amount (in pixels) var delta = e.deltaY || -e.wheelDeltaY || -e.wheelDelta; // If successfully retrieved scroll amount, convert to pixels if not // already in pixels if (delta) { // Convert to pixels ...
javascript
{ "resource": "" }
q7662
press_button
train
function press_button(button) { if (!guac_touchscreen.currentState[button]) { guac_touchscreen.currentState[button] = true; if (guac_touchscreen.onmousedown) guac_touchscreen.onmousedown(guac_touchscreen.currentState); } }
javascript
{ "resource": "" }
q7663
release_button
train
function release_button(button) { if (guac_touchscreen.currentState[button]) { guac_touchscreen.currentState[button] = false; if (guac_touchscreen.onmouseup) guac_touchscreen.onmouseup(guac_touchscreen.currentState); } }
javascript
{ "resource": "" }
q7664
move_mouse
train
function move_mouse(x, y) { guac_touchscreen.currentState.fromClientPosition(element, x, y); if (guac_touchscreen.onmousemove) guac_touchscreen.onmousemove(guac_touchscreen.currentState); }
javascript
{ "resource": "" }
q7665
finger_moved
train
function finger_moved(e) { var touch = e.touches[0] || e.changedTouches[0]; var delta_x = touch.clientX - gesture_start_x; var delta_y = touch.clientY - gesture_start_y; return Math.sqrt(delta_x*delta_x + delta_y*delta_y) >= guac_touchscreen.clickMoveThreshold; }
javascript
{ "resource": "" }
q7666
begin_gesture
train
function begin_gesture(e) { var touch = e.touches[0]; gesture_in_progress = true; gesture_start_x = touch.clientX; gesture_start_y = touch.clientY; }
javascript
{ "resource": "" }
q7667
shevchenko
train
function shevchenko(anthroponym, inflectionCase) { return anthroponymInflector.inflect(new Anthroponym(anthroponym), new InflectionCase(inflectionCase)).toObject(); }
javascript
{ "resource": "" }
q7668
dequeueBodyCallback
train
function dequeueBodyCallback(name) { // If no callbacks defined, simply return null var callbacks = bodyCallbacks[name]; if (!callbacks) return null; // Otherwise, pull off first callback, deleting the queue if empty var callback = callbacks.shift(); if (cal...
javascript
{ "resource": "" }
q7669
enqueueBodyCallback
train
function enqueueBodyCallback(name, callback) { // Get callback queue by name, creating first if necessary var callbacks = bodyCallbacks[name]; if (!callbacks) { callbacks = []; bodyCallbacks[name] = callbacks; } // Add callback to end of queue ca...
javascript
{ "resource": "" }
q7670
getLayer
train
function getLayer(index) { // Get layer, create if necessary var layer = layers[index]; if (!layer) { // Create layer based on index if (index === 0) layer = display.getDefaultLayer(); else if (index > 0) layer = display.creat...
javascript
{ "resource": "" }
q7671
findFrame
train
function findFrame(minIndex, maxIndex, timestamp) { // Do not search if the region contains only one element if (minIndex === maxIndex) return minIndex; // Split search region into two halves var midIndex = Math.floor((minIndex + maxIndex) / 2); var midTimestamp = t...
javascript
{ "resource": "" }
q7672
replayFrame
train
function replayFrame(index) { var frame = frames[index]; // Replay all instructions within the retrieved frame for (var i = 0; i < frame.instructions.length; i++) { var instruction = frame.instructions[i]; playbackTunnel.receiveInstruction(instruction.opcode, instructio...
javascript
{ "resource": "" }
q7673
seekToFrame
train
function seekToFrame(index, callback, delay) { // Abort any in-progress seek abortSeek(); // Replay frames asynchronously seekTimeout = window.setTimeout(function continueSeek() { var startIndex; // Back up until startIndex represents current state ...
javascript
{ "resource": "" }
q7674
continuePlayback
train
function continuePlayback() { // If frames remain after advancing, schedule next frame if (currentFrame + 1 < frames.length) { // Pull the upcoming frame var next = frames[currentFrame + 1]; // Calculate the real timestamp corresponding to when the next ...
javascript
{ "resource": "" }
q7675
getCmd
train
function getCmd(program, opt) { var cmd, expr; if(program==='ogr2ogr') { if(opt==='where') { expr = [ '-where ', "\"", specs.key, " IN ", "('", specs.val, "')\" ", ...
javascript
{ "resource": "" }
q7676
swaggerQueryParamsToSchema
train
function swaggerQueryParamsToSchema(queryModel) { const requiredFields = []; const transformedProperties = {}; _.forOwn(queryModel.items.properties, (value, key) => { if (value.required) { requiredFields.push(key); } transformedProperties[key] = { ...value }; if (!_.isNil(transfor...
javascript
{ "resource": "" }
q7677
generateSchemaRaw
train
function generateSchemaRaw(modelParam, opts = {}) { validate.notNil(modelParam, "modelParam is mandatory"); let models; if (_.isArray(modelParam)) { models = modelParam; } else if (_.isObject(modelParam)) { models = [modelParam]; } else { throw new Error("modelParam should be an object or an arra...
javascript
{ "resource": "" }
q7678
saveSchema
train
function saveSchema(modelParam, targetDir, opts = {}) { validate.notNil(modelParam, "modelParam is mandatory"); validate.notNil(targetDir, "targetDir is mandatory"); const yamlSchemaContainers = generateSchema(modelParam, opts); return yamlWriter.writeYamlsToFs(yamlSchemaContainers, targetDir, opts); }
javascript
{ "resource": "" }
q7679
saveNonModelSchema
train
function saveNonModelSchema(schemaParam, targetDir, opts = {}) { validate.notNil(schemaParam, "schemaParam is mandatory"); validate.notNil(targetDir, "targetDir is mandatory"); if (!Array.isArray(schemaParam)) { schemaParam = [schemaParam]; } const yamlSchemaContainers = schemaParam.map(schema => { c...
javascript
{ "resource": "" }
q7680
saveQueryParamSchema
train
function saveQueryParamSchema(schemaParam, targetDir, opts = {}) { validate.notNil(schemaParam, "schemaParam is mandatory"); validate.notNil(targetDir, "targetDir is mandatory"); if (!Array.isArray(schemaParam)) { schemaParam = [schemaParam]; } const yamlSchemaContainers = schemaParam.map(schema => { ...
javascript
{ "resource": "" }
q7681
_toInteger
train
function _toInteger (value) { var n = +value; if (n !== n) { // eslint-disable-line no-self-compare return 0; } else if (n % 1 === 0) { return n; } else { return Math.floor(Math.abs(n)) * (n < 0 ? -1 : 1); } }
javascript
{ "resource": "" }
q7682
renderStats
train
function renderStats(stats) { /** * Creates table Header if necessary * @param {string} type error or warning * @returns {string} The formatted string */ function injectHeader(type) { return (stats[type]) ? '| rule | count | visual |\n| --- | --- | --- |\n' : ''; } /** * renders templates f...
javascript
{ "resource": "" }
q7683
output
train
function output(type) { var statstype = stats[type]; return injectHeader(type) + lodash.map(statstype, function (ruleStats, ruleId) { return statsRowTemplate({ ruleId: ruleId, ruleCount: ruleStats, visual: lodash.repeat('X', lodash.min([ruleStats, 20])) }); }, '').join(''...
javascript
{ "resource": "" }
q7684
renderTemplate
train
function renderTemplate(type) { var lcType = lodash.lowerCase(type); if (lodash.size(stats[lcType])) { return statsTemplate({ title: '### ' + type, items: output(lcType) }); } else { return ''; } }
javascript
{ "resource": "" }
q7685
__send_blob
train
function __send_blob(bytes) { var binary = ""; // Produce binary string from bytes in buffer for (var i=0; i<bytes.byteLength; i++) binary += String.fromCharCode(bytes[i]); // Send as base64 stream.sendBlob(window.btoa(binary)); }
javascript
{ "resource": "" }
q7686
setBrightnessOfLed
train
function setBrightnessOfLed(callback) { var ledIndex = 8; var setBrightnessOfLedInterval = setInterval(function() { if (ledIndex >= 0) { dot3k.barGraph.setBrightnessOfLed(ledIndex, 0); ledIndex--; } else { clearInterval(setBrightnessOfLedInte...
javascript
{ "resource": "" }
q7687
_getPadding
train
function _getPadding (source, char, len) { if (!isNil(source) && type(source) !== "String") { source = String(source); } return _repeat(String(char)[0] || "", Math.ceil(len - source.length)); }
javascript
{ "resource": "" }
q7688
fetchTokensData
train
function fetchTokensData (tokenRegContract, tokenIndexes) { return (dispatch, getState) => { const { api, tokens } = getState(); const allTokens = Object.values(tokens); const tokensIndexesMap = allTokens .reduce((map, token) => { map[token.index] = token; return map; }, {}); ...
javascript
{ "resource": "" }
q7689
resize
train
function resize(newWidth, newHeight) { // Default size to zero newWidth = newWidth || 0; newHeight = newHeight || 0; // Calculate new dimensions of internal canvas var canvasWidth = Math.ceil(newWidth / CANVAS_SIZE_FACTOR) * CANVAS_SIZE_FACTOR; var canvasHeight = Math...
javascript
{ "resource": "" }
q7690
fitRect
train
function fitRect(x, y, w, h) { // Calculate bounds var opBoundX = w + x; var opBoundY = h + y; // Determine max width var resizeWidth; if (opBoundX > layer.width) resizeWidth = opBoundX; else resizeWidth = layer.width; ...
javascript
{ "resource": "" }
q7691
_mkdom
train
function _mkdom(templ, html) { var match = templ && templ.match(/^\s*<([-\w]+)/), tagName = match && match[1].toLowerCase(), rootTag = rootEls[tagName] || GENERIC, el = mkEl(rootTag) el.stub = true // replace all the yield tags with the tag inner html if (html) templ = replaceYield(...
javascript
{ "resource": "" }
q7692
update
train
function update(expressions, tag) { each(expressions, function(expr, i) { var dom = expr.dom, attrName = expr.attr, value = tmpl(expr.expr, tag), parent = expr.dom.parentNode if (expr.bool) value = value ? attrName : false else if (value == null) value = '' // leave o...
javascript
{ "resource": "" }
q7693
each
train
function each(els, fn) { for (var i = 0, len = (els || []).length, el; i < len; i++) { el = els[i] // return false -> remove current item during loop if (el != null && fn(el, i) === false) i-- } return els }
javascript
{ "resource": "" }
q7694
addChildTag
train
function addChildTag(tag, tagName, parent) { var cachedTag = parent.tags[tagName] // if there are multiple children tags having the same name if (cachedTag) { // if the parent tags property is not yet an array // create it adding the first cached tag if (!isArray(cachedTag)) // don't add the sa...
javascript
{ "resource": "" }
q7695
isWritable
train
function isWritable(obj, key) { var props = Object.getOwnPropertyDescriptor(obj, key) return typeof obj[key] === T_UNDEF || props && props.writable }
javascript
{ "resource": "" }
q7696
isInStub
train
function isInStub(dom) { while (dom) { if (dom.inStub) return true dom = dom.parentNode } return false }
javascript
{ "resource": "" }
q7697
setNamed
train
function setNamed(dom, parent, keys) { // get the key value we want to add to the tag instance var key = getNamedKey(dom), isArr, // add the node detected to a tag instance using the named property add = function(value) { // avoid to override the tag properties already set if (contains(keys,...
javascript
{ "resource": "" }
q7698
train
function(value) { // avoid to override the tag properties already set if (contains(keys, key)) return // check whether this value is an array isArr = isArray(value) // if the key was never set if (!value) // set it once on the tag instance parent[key] = dom // i...
javascript
{ "resource": "" }
q7699
isColumnReorderable
train
function isColumnReorderable() { var originalMethodFromPrototype = Object.getPrototypeOf(this).isColumnReorderable, isReorderable = originalMethodFromPrototype.call(this), groupedHeaderCellRenderer = this.grid.cellRenderers.get(CLASS_NAME), delimiter = groupedHeaderCellRenderer.delimiter; ...
javascript
{ "resource": "" }