_id
stringlengths
2
6
title
stringlengths
0
58
partition
stringclasses
3 values
text
stringlengths
52
373k
language
stringclasses
1 value
meta_information
dict
q58000
getActiveFilters
train
function getActiveFilters (req, selectedFilters, data, modelName, cb) { if (!req) { throw new Error('req is required.'); } if (!selectedFilters || !Array.isArray(selectedFilters) || !selectedFilters.length) { throw new Error('selectedFilters is required and must be of type Array and cannot be empty.'); } if (typeof modelName !== 'string' || !modelName.length) { throw new Error('modelName is required and must be of type String and cannot be empty.'); } if (!(!Object.is(data, null) && !Array.isArray(data) && data === Object(data))) { throw new Error('data is required and must be of type Object.'); } linz.api.model.list(req, modelName, function (err, list) { if (err) { return cb(err); } if (!Object.keys(list.filters).length) { return cb(null); } var activeFilters = {}; async.each(selectedFilters, function (fieldName, filtersDone) { // call the filter binder to render active filter form controls with form value added list.filters[fieldName].filter.bind(fieldName, data, function (filterErr, result) { if (filterErr) { return filtersDone(filterErr); } activeFilters[fieldName] = { label: list.filters[fieldName].label, controls: result } return filtersDone(null); }); }, function (filterErr) { return cb(filterErr, activeFilters); }); }); }
javascript
{ "resource": "" }
q58001
setTabId
train
function setTabId (sections) { sections.forEach(function (section, sectionIndex) { if (!Array.isArray(section)) { return; } section.forEach(function (tab, tabIndex) { // Replace white space from tab.label with "-", make it lowercase and add the index number at the end. // sectionIndex and tabIndex number are added at the end to make the tabID unique in case when more then one tab have the same label (title) tab.tabId = (tab.label).replace(/\s+/g, '-').toLowerCase() + '-' + sectionIndex + '-' + tabIndex; }); }); }
javascript
{ "resource": "" }
q58002
renderCell
train
function renderCell (record, field, model, cb) { let fieldName = (typeof field === 'object') ? field.fieldName : field, renderer = (model.schema.tree[fieldName] && model.schema.tree[fieldName].ref && linz.api.model.getObjectIdFromRefField(record[fieldName]) instanceof linz.mongoose.Types.ObjectId) ? 'reference' : (record[fieldName] && linz.api.model.getObjectIdFromRefField(record[fieldName]) instanceof linz.mongoose.Types.ObjectId && linz.mongoose.models[record[fieldName].ref]) ? 'referenceValue' : 'text'; // Users can supply their own renderer fields (use it if provided). (field.renderer || cellRenderers[renderer])(record[fieldName], record, fieldName, model, function (err, value) { if (err) { return cb(err); } return cb(null, { label: field.label ? field.label : model.linz.formtools.labels[fieldName], value: value }); }); }
javascript
{ "resource": "" }
q58003
getOffset
train
function getOffset(offset) { var symbol = offset.charAt(0); var time = offset.substring(1).split(':'); var hours = Number.parseInt(time[0], 10) * 60; var minutes = Number.parseInt(time[1], 10); var total = Number.parseInt(symbol + (hours + minutes)); return total; }
javascript
{ "resource": "" }
q58004
getConfig
train
function getConfig(options) { const profileOptions = { baseUrl: get('pod.url'), headers: { 'user-agent': `yodata/client (https://yodata.io)`, 'x-api-key': get('pod.secret') }, hooks: { beforeRequest: [ logRequest ], afterResponse: [ parseResponseData ] } } return defaults(options, profileOptions) }
javascript
{ "resource": "" }
q58005
defaultRenderer
train
function defaultRenderer (data, callback) { linz.api.views.renderPartial('action-record', data, (err, html) => { if (err) { return callback(err); } return callback(null, html); }); }
javascript
{ "resource": "" }
q58006
getContext
train
async function getContext(target, contextOptions) { if (isURL(target)) { const cdef = await got(target) .then(response => { const contentType = response.headers["content-type"] switch (contentType) { case 'application/x-yaml': case 'application/x-yml': return yaml.load(response.body) case 'application/json': case 'application/ld+json': return JSON.parse(response.body) default: throw new Error(`context type not recognized ${contentType}`) } }) return new Context(cdef, contextOptions) } else { return loadContext(target, contextOptions) } }
javascript
{ "resource": "" }
q58007
form
train
function form (req, modelName, callback, formDsl) { const formFn = () => new Promise((resolve, reject) => { const formLabels = labels(modelName); const schema = get(modelName, true).schema; if (formDsl && typeof formDsl === 'function') { return resolve(pluginHelpers.formSettings(req, schema, clone(formDsl()), formLabels)); } if (formDsl) { return resolve(pluginHelpers.formSettings(req, schema, clone(formDsl), formLabels)); } // Get the form get(modelName, true).getForm(req, (err, decoratedForm) => { if (err) { return reject(err); } return resolve(decoratedForm); }); }); formFn() .then((result) => callback(null, result)) .catch(callback); }
javascript
{ "resource": "" }
q58008
formAsPromise
train
function formAsPromise (req, modelName, formDsl) { return new Promise((resolve, reject) => { form(req, modelName, (err, decoratedForm) => { if (err) { return reject(err); } return resolve(decoratedForm); }, formDsl); }); }
javascript
{ "resource": "" }
q58009
list
train
function list (req, modelName, callback) { return get(modelName, true).getList(req, callback); }
javascript
{ "resource": "" }
q58010
permissions
train
function permissions (user, modelName, callback) { return get(modelName, true).getPermissions(user, callback); }
javascript
{ "resource": "" }
q58011
overview
train
function overview (req, modelName, callback) { return get(modelName, true).getOverview(req, callback); }
javascript
{ "resource": "" }
q58012
labels
train
function labels (modelName, callback) { if (callback) { return get(modelName, true).getLabels(callback); } return get(modelName, true).getLabels(); }
javascript
{ "resource": "" }
q58013
titleField
train
function titleField (modelName, field, callback) { // Make this a no-op unless the field being evaluated is `'title'`. if (field !== 'title') { return callback(null, field); } if (get(modelName, true).schema.paths[field]) { return callback(null, field); } model(modelName, (err, opts) => { if (err) { return callback(err); } return callback(null, opts.title); }); }
javascript
{ "resource": "" }
q58014
compileContext
train
async function compileContext(target, contextOptions) { const context = await getContext(target, contextOptions) return async function (data/** @param {object} */) { return context.map(data) } }
javascript
{ "resource": "" }
q58015
getMaxPackageNameLength
train
function getMaxPackageNameLength (packages) { return Object .keys(packages) .reduce((max, name) => Math.max(max, name.length), 0); }
javascript
{ "resource": "" }
q58016
padding
train
function padding (packageName, maxLength) { const length = packageName.length; return (length < maxLength) ? " ".repeat(maxLength - length) : ""; }
javascript
{ "resource": "" }
q58017
createServer
train
function createServer(port, f) { f = f || noop; http.createServer(handler).listen(port, f); return statusHelper.changeStatus; }
javascript
{ "resource": "" }
q58018
runKaba
train
function runKaba (opts, isVerbose) { try { const logger = new Logger(kleur.bgYellow.black(" kaba ")); logger.log("kaba started"); const start = process.hrtime(); const cliConfig = new CliConfig(opts); /** @type {Kaba} kaba */ const kaba = require(`${process.cwd()}/kaba.js`); const buildConfig = kaba.getBuildConfig(cliConfig); const scss = new SassRunner(buildConfig, cliConfig); const webpack = new WebpackRunner(buildConfig); Promise.all([scss.run(), webpack.run()]) .then( ([scssOk, webpackOk]) => { const failed = (false === scssOk || false === webpackOk); const status = failed ? kleur.red("failed") : kleur.green("succeeded"); logger.logWithDuration(`kaba ${status}`, process.hrtime(start)); process.exit(failed ? 1 : 0); } ) .catch( (...args) => console.log("something broke", args) ); if (cliConfig.isWatch()) { const exitCallback = () => { scss.stop(); webpack.stop(); }; process.on("exit", exitCallback); process.on("SIGINT", exitCallback); process.on("SIGUSR1", exitCallback); process.on("SIGUSR2", exitCallback); } } catch (e) { if (/cannot find module.*?kaba\.js/i.test(e.message)) { console.log(`${kleur.red("Error")}: Could not find ${kleur.yellow("kaba.js")}`); } else { console.log(kleur.red(`Run Error: ${e.message}`)); } if (isVerbose) { console.error(e); } process.exit(1); } }
javascript
{ "resource": "" }
q58019
sendRecursively
train
function sendRecursively(event, currentState, isUnhandledPass) { var log = this.enableLogging, eventName = isUnhandledPass ? 'unhandledEvent' : event, action = currentState[eventName], contexts, sendRecursiveArguments, actionArguments; contexts = [].slice.call(arguments, 3); // Test to see if the action is a method that // can be invoked. Don't blindly check just for // existence, because it is possible the state // manager has a child state of the given name, // and we should still raise an exception in that // case. if (typeof action === 'function') { if (log) { if (isUnhandledPass) { Ember.Logger.log(`STATEMANAGER: Unhandled event '${event}' being sent to state ${currentState.get('path')}.`); } else { Ember.Logger.log(`STATEMANAGER: Sending event '${event}' to state ${currentState.get('path')}.`); } } actionArguments = contexts; if (isUnhandledPass) { actionArguments.unshift(event); } actionArguments.unshift(this); return action.apply(currentState, actionArguments); } else { var parentState = get(currentState, 'parentState'); if (parentState) { sendRecursiveArguments = contexts; sendRecursiveArguments.unshift(event, parentState, isUnhandledPass); return sendRecursively.apply(this, sendRecursiveArguments); } else if (!isUnhandledPass) { return sendEvent.call(this, event, contexts, true); } } }
javascript
{ "resource": "" }
q58020
sendEvent
train
function sendEvent(eventName, sendRecursiveArguments, isUnhandledPass) { sendRecursiveArguments.unshift(eventName, this.get('currentState'), isUnhandledPass); return sendRecursively.apply(this, sendRecursiveArguments); }
javascript
{ "resource": "" }
q58021
changeEntireFormValue
train
function changeEntireFormValue ({model, nextValue, prevValue}) { return { value: immutableOnce(recursiveClean(nextValue, model)), valueChangeSet: getChangeSet(prevValue, nextValue) } }
javascript
{ "resource": "" }
q58022
changeNestedFormValue
train
function changeNestedFormValue ({bunsenId, formValue, model, value}) { const segments = bunsenId.split('.') const lastSegment = segments.pop() const isEmpty = _.isEmpty(value) && (Array.isArray(value) || _.isObject(value)) && !(value instanceof File) // Make sure form value is immutable formValue = immutableOnce(formValue) if (isArrayItem(lastSegment)) { return setProperty({bunsenId, formValue, value}) } if (_.includes([null, undefined, ''], value) || isEmpty) { return unsetProperty({bunsenId, formValue, value}) } if (!_.isEqual(value, _.get(formValue, bunsenId))) { return setProperty({bunsenId, formValue, value}) } return { value: formValue, valueChangeSet: new Map() } }
javascript
{ "resource": "" }
q58023
unsetProperty
train
function unsetProperty ({bunsenId, formValue, value}) { const valueChangeSet = new Map() valueChangeSet.set(bunsenId, { value, type: 'unset' }) return { value: unset(formValue, bunsenId), valueChangeSet } }
javascript
{ "resource": "" }
q58024
train
function (state, action) { // Apply coniditions to view cells let normalized let view if (state.unnormalizedModel) { normalized = normalizeModelAndView({ model: state.unnormalizedModel, view: action.view }) view = evaluateViewConditions(normalized.view, state.value) } else { view = evaluateViewConditions(state.baseView, state.value) normalized = { view, model: state.model } } const newState = { baseView: normalized.view, lastAction: CHANGE_VIEW, unnormalizedView: action.view, view } if (!_.isEqual(state.baseModel, normalized.model)) { Object.assign(newState, { baseModel: normalized.model, model: evaluateConditions(normalized.model, state.value, undefined, state.value) }) } return _.defaults(newState, state) }
javascript
{ "resource": "" }
q58025
getCounts
validation
function getCounts(langs = []) { return { langs: langs.length, modelLangs: langs.filter(({ models }) => models && !!models.length).length, models: langs.map(({ models }) => (models ? models.length : 0)).reduce((a, b) => a + b, 0), } }
javascript
{ "resource": "" }
q58026
className
validation
function className(node, value){ var klass = node.className || '', svg = klass && klass.baseVal !== undefined if (value === undefined) return svg ? klass.baseVal : klass svg ? (klass.baseVal = value) : (node.className = value) }
javascript
{ "resource": "" }
q58027
deserializeValue
validation
function deserializeValue(value) { try { return value ? value == "true" || ( value == "false" ? false : value == "null" ? null : +value + "" == value ? +value : /^[\[\{]/.test(value) ? $.parseJSON(value) : value ) : value } catch(e) { return value } }
javascript
{ "resource": "" }
q58028
getHighlightOptions
validation
function getHighlightOptions(config, arg) { let lang = ''; if (rLang.test(arg)) { arg = arg.replace(rLang, (match, _lang) => { lang = _lang; return ''; }); } let line_number = config.line_number; if (rLineNumber.test(arg)) { arg = arg.replace(rLineNumber, (match, _line_number) => { line_number = _line_number === 'true'; return ''; }); } let first_line = 1; if (rFirstLine.test(arg)) { arg = arg.replace(rFirstLine, (match, _first_line) => { first_line = _first_line; return ''; }); } let mark = []; if (rMark.test(arg)) { arg = arg.replace(rMark, (match, _mark) => { mark = _mark.split(',').reduce(function getMarkedLines(prev, cur) { if (/-/.test(cur)) { let a = Number(cur.substr(0, cur.indexOf('-'))); let b = Number(cur.substr(cur.indexOf('-') + 1)); if (b < a) { // switch a & b const temp = a; a = b; b = temp; } for (; a <= b; a++) { prev.push(a); } return prev; } prev.push(Number(cur)); return prev; }, []); return ''; }); } let caption = ''; if (rCaptionUrlTitle.test(arg)) { const match = arg.match(rCaptionUrlTitle); caption = `<span>${match[1]}</span><a href="${match[2]}${match[3]}">${match[4]}</a>`; } else if (rCaptionUrl.test(arg)) { const match = arg.match(rCaptionUrl); caption = `<span>${match[1]}</span><a href="${match[2]}${match[3]}">link</a>`; } else if (rCaption.test(arg)) { const match = arg.match(rCaption); caption = `<span>${match[1]}</span>`; } return { lang, firstLine: first_line, caption, gutter: line_number, hljs: config.hljs, mark, tab: config.tab_replace, autoDetect: config.auto_detect }; }
javascript
{ "resource": "" }
q58029
pipeStream
validation
function pipeStream(...args) { const src = args.shift(); return new Promise((resolve, reject) => { let stream = src.on('error', reject); let target; while ((target = args.shift()) != null) { stream = stream.pipe(target).on('error', reject); } stream.on('finish', resolve); stream.on('end', resolve); stream.on('close', resolve); }); }
javascript
{ "resource": "" }
q58030
formatNunjucksError
validation
function formatNunjucksError(err, input) { const match = err.message.match(/Line (\d+), Column \d+/); if (!match) return err; const errLine = parseInt(match[1], 10); if (isNaN(errLine)) return err; // trim useless info from Nunjucks Error const splited = err.message.replace('(unknown path)', '').split('\n'); const e = new Error(); e.name = 'Nunjucks Error'; e.line = errLine; e.location = splited[0]; e.type = splited[1].trim(); e.message = getContext(input.split(/\r?\n/), errLine, e.location, e.type).join('\n'); return e; }
javascript
{ "resource": "" }
q58031
validation
function (event, context, responseStatus, physicalResourceId, responseData, reason) { return new Promise((resolve, reject) => { const https = require('https'); const { URL } = require('url'); var responseBody = JSON.stringify({ Status: responseStatus, Reason: reason, PhysicalResourceId: physicalResourceId || context.logStreamName, StackId: event.StackId, RequestId: event.RequestId, LogicalResourceId: event.LogicalResourceId, Data: responseData }); const parsedUrl = new URL(event.ResponseURL || defaultResponseURL); const options = { hostname: parsedUrl.hostname, port: 443, path: parsedUrl.pathname + parsedUrl.search, method: 'PUT', headers: { 'Content-Type': '', 'Content-Length': responseBody.length } }; https.request(options) .on('error', reject) .on('response', res => { res.resume(); if (res.statusCode >= 400) { reject(new Error(`Server returned error ${res.statusCode}: ${res.statusMessage}`)); } else { resolve(); } }) .end(responseBody, 'utf8'); }); }
javascript
{ "resource": "" }
q58032
getAdopter
validation
async function getAdopter(name) { try { const policyResponse = await ecr.getRepositoryPolicy({ repositoryName: name }).promise(); const policy = JSON.parse(policyResponse.policyText); // Search the policy for an adopter marker return (policy.Statement || []).find((x) => x.Action === markerStatement.Action) || {}; } catch (e) { if (e.code !== 'RepositoryPolicyNotFoundException') { throw e; } return {}; } }
javascript
{ "resource": "" }
q58033
calculateLineHeight
validation
function calculateLineHeight(model, columnWidths) { var padding = this.internal.__cell__.padding; var fontSize = this.internal.__cell__.table_font_size; var scaleFactor = this.internal.scaleFactor; return Object.keys(model) .map(function (value) {return typeof value === 'object' ? value.text : value}) .map(function (value) { return this.splitTextToSize(value, columnWidths[value] - padding - padding) }, this) .map(function (value) { return this.getLineHeightFactor() * value.length * fontSize / scaleFactor + padding + padding }, this) .reduce(function (pv, cv) { return Math.max(pv, cv) }, 0); }
javascript
{ "resource": "" }
q58034
makeWorker
validation
function makeWorker(script) { var URL = window.URL || window.webkitURL; var Blob = window.Blob; var Worker = window.Worker; if (!URL || !Blob || !Worker || !script) { return null; } var blob = new Blob([script]); var worker = new Worker(URL.createObjectURL(blob)); return worker; }
javascript
{ "resource": "" }
q58035
monkeyPatch
validation
function monkeyPatch() { return { transform: (code, id) => { var file = id.split('/').pop() // Only one define call per module is allowed by requirejs so // we have to remove calls that other libraries make if (file === 'FileSaver.js') { code = code.replace(/define !== null\) && \(define.amd != null/g, '0') } else if (file === 'html2canvas.js') { code = code.replace(/&&\s+define.amd/g, '&& define.amd && false') } return code } } }
javascript
{ "resource": "" }
q58036
rawjs
validation
function rawjs(opts) { opts = opts || {} return { transform: (code, id) => { var variable = opts[id.split('/').pop()] if (!variable) return code var keepStr = '/*rollup-keeper-start*/window.tmp=' + variable + ';/*rollup-keeper-end*/' return code + keepStr }, transformBundle: (code) => { for (var file in opts) { var r = new RegExp(opts[file] + '\\$\\d+', 'g') code = code.replace(r, opts[file]) } var re = /\/\*rollup-keeper-start\*\/.*\/\*rollup-keeper-end\*\//g return code.replace(re, '') } } }
javascript
{ "resource": "" }
q58037
validation
function (tagName, opt) { var el = document.createElement(tagName); if (opt.className) el.className = opt.className; if (opt.innerHTML) { el.innerHTML = opt.innerHTML; var scripts = el.getElementsByTagName('script'); for (var i = scripts.length; i-- > 0;) { scripts[i].parentNode.removeChild(scripts[i]); } } for (var key in opt.style) { el.style[key] = opt.style[key]; } return el; }
javascript
{ "resource": "" }
q58038
tr_init
validation
function tr_init() { l_desc.dyn_tree = dyn_ltree; l_desc.stat_desc = StaticTree.static_l_desc; d_desc.dyn_tree = dyn_dtree; d_desc.stat_desc = StaticTree.static_d_desc; bl_desc.dyn_tree = bl_tree; bl_desc.stat_desc = StaticTree.static_bl_desc; bi_buf = 0; bi_valid = 0; last_eob_len = 8; // enough lookahead for inflate // Initialize the first block of the first file: init_block(); }
javascript
{ "resource": "" }
q58039
_tr_tally
validation
function _tr_tally(dist, // distance of matched string lc // match length-MIN_MATCH or unmatched char (if dist==0) ) { var out_length, in_length, dcode; that.pending_buf[d_buf + last_lit * 2] = (dist >>> 8) & 0xff; that.pending_buf[d_buf + last_lit * 2 + 1] = dist & 0xff; that.pending_buf[l_buf + last_lit] = lc & 0xff; last_lit++; if (dist === 0) { // lc is the unmatched char dyn_ltree[lc * 2]++; } else { matches++; // Here, lc is the match length - MIN_MATCH dist--; // dist = match distance - 1 dyn_ltree[(Tree._length_code[lc] + LITERALS + 1) * 2]++; dyn_dtree[Tree.d_code(dist) * 2]++; } if ((last_lit & 0x1fff) === 0 && level > 2) { // Compute an upper bound for the compressed length out_length = last_lit * 8; in_length = strstart - block_start; for (dcode = 0; dcode < D_CODES; dcode++) { out_length += dyn_dtree[dcode * 2] * (5 + Tree.extra_dbits[dcode]); } out_length >>>= 3; if ((matches < Math.floor(last_lit / 2)) && out_length < Math.floor(in_length / 2)) return true; } return (last_lit === lit_bufsize - 1); // We avoid equality with lit_bufsize because of wraparound at 64K // on 16 bit machines and because stored blocks are restricted to // 64K-1 bytes. }
javascript
{ "resource": "" }
q58040
compress_block
validation
function compress_block(ltree, dtree) { var dist; // distance of matched string var lc; // match length or unmatched char (if dist === 0) var lx = 0; // running index in l_buf var code; // the code to send var extra; // number of extra bits to send if (last_lit !== 0) { do { dist = ((that.pending_buf[d_buf + lx * 2] << 8) & 0xff00) | (that.pending_buf[d_buf + lx * 2 + 1] & 0xff); lc = (that.pending_buf[l_buf + lx]) & 0xff; lx++; if (dist === 0) { send_code(lc, ltree); // send a literal byte } else { // Here, lc is the match length - MIN_MATCH code = Tree._length_code[lc]; send_code(code + LITERALS + 1, ltree); // send the length // code extra = Tree.extra_lbits[code]; if (extra !== 0) { lc -= Tree.base_length[code]; send_bits(lc, extra); // send the extra length bits } dist--; // dist is now the match distance - 1 code = Tree.d_code(dist); send_code(code, dtree); // send the distance code extra = Tree.extra_dbits[code]; if (extra !== 0) { dist -= Tree.base_dist[code]; send_bits(dist, extra); // send the extra distance bits } } // literal or match pair ? // Check that the overlay between pending_buf and d_buf+l_buf is // ok: } while (lx < last_lit); } send_code(END_BLOCK, ltree); last_eob_len = ltree[END_BLOCK * 2 + 1]; }
javascript
{ "resource": "" }
q58041
copy_block
validation
function copy_block(buf, // the input data len, // its length header // true if block header must be written ) { bi_windup(); // align on byte boundary last_eob_len = 8; // enough lookahead for inflate if (header) { put_short(len); put_short(~len); } that.pending_buf.set(window.subarray(buf, buf + len), that.pending); that.pending += len; }
javascript
{ "resource": "" }
q58042
_tr_stored_block
validation
function _tr_stored_block(buf, // input block stored_len, // length of input block eof // true if this is the last block for a file ) { send_bits((STORED_BLOCK << 1) + (eof ? 1 : 0), 3); // send block type copy_block(buf, stored_len, true); // with header }
javascript
{ "resource": "" }
q58043
validation
function (style) { var rxRgb = /rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/; var rxRgba = /rgba\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*([\d.]+)\s*\)/; var rxTransparent = /transparent|rgba\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*0+\s*\)/; var r, g, b, a; if (style.isCanvasGradient === true) { style = style.getColor(); } if (!style) { return { r: 0, g: 0, b: 0, a: 0, style: style }; } if (rxTransparent.test(style)) { r = 0; g = 0; b = 0; a = 0; } else { var matches = rxRgb.exec(style); if (matches !== null) { r = parseInt(matches[1]); g = parseInt(matches[2]); b = parseInt(matches[3]); a = 1; } else { matches = rxRgba.exec(style); if (matches !== null) { r = parseInt(matches[1]); g = parseInt(matches[2]); b = parseInt(matches[3]); a = parseFloat(matches[4]); } else { a = 1; if (typeof style === "string" && style.charAt(0) !== '#') { var rgbColor = new RGBColor(style); if (rgbColor.ok) { style = rgbColor.toHex(); } else { style = '#000000'; } } if (style.length === 4) { r = style.substring(1, 2); r += r; g = style.substring(2, 3); g += g; b = style.substring(3, 4); b += b; } else { r = style.substring(1, 3); g = style.substring(3, 5); b = style.substring(5, 7); } r = parseInt(r, 16); g = parseInt(g, 16); b = parseInt(b, 16); } } } return { r: r, g: g, b: b, a: a, style: style }; }
javascript
{ "resource": "" }
q58044
validation
function (y) { if (this.pageWrapYEnabled) { this.lastBreak = 0; var manualBreaks = 0; var autoBreaks = 0; for (var i = 0; i < this.pageBreaks.length; i++) { if (y >= this.pageBreaks[i]) { manualBreaks++; if (this.lastBreak === 0) { autoBreaks++; } var spaceBetweenLastBreak = this.pageBreaks[i] - this.lastBreak; this.lastBreak = this.pageBreaks[i]; var pagesSinceLastBreak = Math.floor(spaceBetweenLastBreak / this.pageWrapY); autoBreaks += pagesSinceLastBreak; } } if (this.lastBreak === 0) { var pagesSinceLastBreak = Math.floor(y / this.pageWrapY) + 1; autoBreaks += pagesSinceLastBreak; } return autoBreaks + manualBreaks; } else { return this.pdf.internal.getCurrentPageInfo().pageNumber; } }
javascript
{ "resource": "" }
q58045
validation
function (ax, ay, bx, by, cx, cy, dx, dy) { var tobx = bx - ax; var toby = by - ay; var tocx = cx - bx; var tocy = cy - by; var todx = dx - cx; var tody = dy - cy; var precision = 40; var d, i, px, py, qx, qy, rx, ry, tx, ty, sx, sy, x, y, minx, miny, maxx, maxy, toqx, toqy, torx, tory, totx, toty; for (i = 0; i < (precision + 1); i++) { d = i / precision; px = ax + d * tobx; py = ay + d * toby; qx = bx + d * tocx; qy = by + d * tocy; rx = cx + d * todx; ry = cy + d * tody; toqx = qx - px; toqy = qy - py; torx = rx - qx; tory = ry - qy; sx = px + d * toqx; sy = py + d * toqy; tx = qx + d * torx; ty = qy + d * tory; totx = tx - sx; toty = ty - sy; x = sx + d * totx; y = sy + d * toty; if (i == 0) { minx = x; miny = y; maxx = x; maxy = y; } else { minx = Math.min(minx, x); miny = Math.min(miny, y); maxx = Math.max(maxx, x); maxy = Math.max(maxy, y); } } return new Rectangle(Math.round(minx), Math.round(miny), Math.round(maxx - minx), Math.round(maxy - miny)); }
javascript
{ "resource": "" }
q58046
validation
function (pageInfo) { var pageNumber = pageInfo !== undefined ? pageInfo.pageNumber : 1; //set current y position to old margin var oldPosition = renderer.y; //render all child nodes of the header element renderer.y = renderer.pdf.internal.pageSize.getHeight() - renderer.pdf.margins_doc.bottom; renderer.pdf.margins_doc.bottom -= footerHeight; //check if we have to add page numbers var spans = footer.getElementsByTagName('span'); for (var i = 0; i < spans.length; ++i) { //if we find some span element with class pageCounter, set the page if ((" " + spans[i].className + " ").replace(/[\n\t]/g, " ").indexOf(" pageCounter ") > -1) { spans[i].innerHTML = pageNumber; } //if we find some span element with class totalPages, set a variable which is replaced after rendering of all pages if ((" " + spans[i].className + " ").replace(/[\n\t]/g, " ").indexOf(" totalPages ") > -1) { spans[i].innerHTML = '###jsPDFVarTotalPages###'; } } //render footer content DrillForContent(footer, renderer, elementHandlers); //set bottom margin to previous height including the footer height renderer.pdf.margins_doc.bottom += footerHeight; //important for other plugins (e.g. table) to start rendering at correct position after header renderer.y = oldPosition; }
javascript
{ "resource": "" }
q58047
getFont
validation
function getFont(fontName, fontStyle, options) { var key = undefined, fontNameLowerCase; options = options || {}; fontName = fontName !== undefined ? fontName : fonts[activeFontKey].fontName; fontStyle = fontStyle !== undefined ? fontStyle : fonts[activeFontKey].fontStyle; fontNameLowerCase = fontName.toLowerCase(); if (fontmap[fontNameLowerCase] !== undefined && fontmap[fontNameLowerCase][fontStyle] !== undefined) { key = fontmap[fontNameLowerCase][fontStyle]; } else if (fontmap[fontName] !== undefined && fontmap[fontName][fontStyle] !== undefined) { key = fontmap[fontName][fontStyle]; } else { if (options.disableWarning === false) { console.warn("Unable to look up font label for font '" + fontName + "', '" + fontStyle + "'. Refer to getFontList() for available fonts."); } } if (!key && !options.noFallback) { key = fontmap['times'][fontStyle]; if (key == null) { key = fontmap['times']['normal']; } } return key; }
javascript
{ "resource": "" }
q58048
calculateFontSpace
validation
function calculateFontSpace(text, formObject, fontSize) { var font = scope.internal.getFont(formObject.fontName, formObject.fontStyle); var width = scope.getStringUnitWidth(text, { font: font, fontSize: parseFloat(fontSize), charSpace: 0 }) * parseFloat(fontSize); var height = scope.getStringUnitWidth("3", { font: font, fontSize: parseFloat(fontSize), charSpace: 0 }) * parseFloat(fontSize) * 1.5; return { height: height, width: width }; }
javascript
{ "resource": "" }
q58049
YesPushDown
validation
function YesPushDown(formObject) { var xobj = createFormXObject(formObject); var stream = []; var fontKey = scope.internal.getFont(formObject.fontName, formObject.fontStyle).id; var encodedColor = scope.__private__.encodeColorString(formObject.color); var calcRes = calculateX(formObject, formObject.caption); stream.push("0.749023 g"); stream.push("0 0 " + f2(AcroFormAppearance.internal.getWidth(formObject)) + " " + f2(AcroFormAppearance.internal.getHeight(formObject)) + " re"); stream.push("f"); stream.push("BMC"); stream.push("q"); stream.push("0 0 1 rg"); stream.push("/" + fontKey + " " + f2(calcRes.fontSize) + " Tf " + encodedColor); stream.push("BT"); stream.push(calcRes.text); stream.push("ET"); stream.push("Q"); stream.push("EMC"); xobj.stream = stream.join("\n"); return xobj; }
javascript
{ "resource": "" }
q58050
OffPushDown
validation
function OffPushDown(formObject) { var xobj = createFormXObject(formObject); var stream = []; stream.push("0.749023 g"); stream.push("0 0 " + f2(AcroFormAppearance.internal.getWidth(formObject)) + " " + f2(AcroFormAppearance.internal.getHeight(formObject)) + " re"); stream.push("f"); xobj.stream = stream.join("\n"); return xobj; }
javascript
{ "resource": "" }
q58051
createDefaultAppearanceStream
validation
function createDefaultAppearanceStream(formObject) { // Set Helvetica to Standard Font (size: auto) // Color: Black var fontKey = scope.internal.getFont(formObject.fontName, formObject.fontStyle).id; var encodedColor = scope.__private__.encodeColorString(formObject.color); var fontSize = formObject.fontSize; var result = '/' + fontKey + ' ' + fontSize + ' Tf ' + encodedColor; return result; }
javascript
{ "resource": "" }
q58052
splitLongWord
validation
function splitLongWord(word, widths_array, firstLineMaxLen, maxLen) { var answer = []; // 1st, chop off the piece that can fit on the hanging line. var i = 0, l = word.length, workingLen = 0; while (i !== l && workingLen + widths_array[i] < firstLineMaxLen) { workingLen += widths_array[i]; i++; } // this is first line. answer.push(word.slice(0, i)); // 2nd. Split the rest into maxLen pieces. var startOfLine = i; workingLen = 0; while (i !== l) { if (workingLen + widths_array[i] > maxLen) { answer.push(word.slice(startOfLine, i)); workingLen = 0; startOfLine = i; } workingLen += widths_array[i]; i++; } if (startOfLine !== i) { answer.push(word.slice(startOfLine, i)); } return answer; }
javascript
{ "resource": "" }
q58053
splitParagraphIntoLines
validation
function splitParagraphIntoLines(text, maxlen, options) { // at this time works only on Western scripts, ones with space char // separating the words. Feel free to expand. if (!options) { options = {}; } var line = [], lines = [line], line_length = options.textIndent || 0, separator_length = 0, current_word_length = 0, word, widths_array, words = text.split(' '), spaceCharWidth = getCharWidthsArray.apply(this, [' ', options])[0], i, l, tmp, lineIndent; if (options.lineIndent === -1) { lineIndent = words[0].length + 2; } else { lineIndent = options.lineIndent || 0; } if (lineIndent) { var pad = Array(lineIndent).join(" "), wrds = []; words.map(function (wrd) { wrd = wrd.split(/\s*\n/); if (wrd.length > 1) { wrds = wrds.concat(wrd.map(function (wrd, idx) { return (idx && wrd.length ? "\n" : "") + wrd; })); } else { wrds.push(wrd[0]); } }); words = wrds; lineIndent = getStringUnitWidth.apply(this, [pad, options]); } for (i = 0, l = words.length; i < l; i++) { var force = 0; word = words[i]; if (lineIndent && word[0] == "\n") { word = word.substr(1); force = 1; } widths_array = getCharWidthsArray.apply(this, [word, options]); current_word_length = getArraySum(widths_array); if (line_length + separator_length + current_word_length > maxlen || force) { if (current_word_length > maxlen) { // this happens when you have space-less long URLs for example. // we just chop these to size. We do NOT insert hiphens tmp = splitLongWord.apply(this, [word, widths_array, maxlen - (line_length + separator_length), maxlen]); // first line we add to existing line object line.push(tmp.shift()); // it's ok to have extra space indicator there // last line we make into new line object line = [tmp.pop()]; // lines in the middle we apped to lines object as whole lines while (tmp.length) { lines.push([tmp.shift()]); // single fragment occupies whole line } current_word_length = getArraySum(widths_array.slice(word.length - (line[0] ? line[0].length : 0))); } else { // just put it on a new line line = [word]; } // now we attach new line to lines lines.push(line); line_length = current_word_length + lineIndent; separator_length = spaceCharWidth; } else { line.push(word); line_length += separator_length + current_word_length; separator_length = spaceCharWidth; } } if (lineIndent) { var postProcess = function postProcess(ln, idx) { return (idx ? pad : '') + ln.join(" "); }; } else { var postProcess = function postProcess(ln) { return ln.join(" "); }; } return lines.map(postProcess); }
javascript
{ "resource": "" }
q58054
bi_flush
validation
function bi_flush() { if (bi_valid == 16) { put_short(bi_buf); bi_buf = 0; bi_valid = 0; } else if (bi_valid >= 8) { put_byte(bi_buf & 0xff); bi_buf >>>= 8; bi_valid -= 8; } }
javascript
{ "resource": "" }
q58055
GifWriterOutputLZWCodeStream
validation
function GifWriterOutputLZWCodeStream(buf, p, min_code_size, index_stream) { buf[p++] = min_code_size; var cur_subblock = p++; // Pointing at the length field. var clear_code = 1 << min_code_size; var code_mask = clear_code - 1; var eoi_code = clear_code + 1; var next_code = eoi_code + 1; var cur_code_size = min_code_size + 1; // Number of bits per code. var cur_shift = 0; // We have at most 12-bit codes, so we should have to hold a max of 19 // bits here (and then we would write out). var cur = 0; function emit_bytes_to_buffer(bit_block_size) { while (cur_shift >= bit_block_size) { buf[p++] = cur & 0xff; cur >>= 8; cur_shift -= 8; if (p === cur_subblock + 256) { // Finished a subblock. buf[cur_subblock] = 255; cur_subblock = p++; } } } function emit_code(c) { cur |= c << cur_shift; cur_shift += cur_code_size; emit_bytes_to_buffer(8); } // I am not an expert on the topic, and I don't want to write a thesis. // However, it is good to outline here the basic algorithm and the few data // structures and optimizations here that make this implementation fast. // The basic idea behind LZW is to build a table of previously seen runs // addressed by a short id (herein called output code). All data is // referenced by a code, which represents one or more values from the // original input stream. All input bytes can be referenced as the same // value as an output code. So if you didn't want any compression, you // could more or less just output the original bytes as codes (there are // some details to this, but it is the idea). In order to achieve // compression, values greater then the input range (codes can be up to // 12-bit while input only 8-bit) represent a sequence of previously seen // inputs. The decompressor is able to build the same mapping while // decoding, so there is always a shared common knowledge between the // encoding and decoder, which is also important for "timing" aspects like // how to handle variable bit width code encoding. // // One obvious but very important consequence of the table system is there // is always a unique id (at most 12-bits) to map the runs. 'A' might be // 4, then 'AA' might be 10, 'AAA' 11, 'AAAA' 12, etc. This relationship // can be used for an effecient lookup strategy for the code mapping. We // need to know if a run has been seen before, and be able to map that run // to the output code. Since we start with known unique ids (input bytes), // and then from those build more unique ids (table entries), we can // continue this chain (almost like a linked list) to always have small // integer values that represent the current byte chains in the encoder. // This means instead of tracking the input bytes (AAAABCD) to know our // current state, we can track the table entry for AAAABC (it is guaranteed // to exist by the nature of the algorithm) and the next character D. // Therefor the tuple of (table_entry, byte) is guaranteed to also be // unique. This allows us to create a simple lookup key for mapping input // sequences to codes (table indices) without having to store or search // any of the code sequences. So if 'AAAA' has a table entry of 12, the // tuple of ('AAAA', K) for any input byte K will be unique, and can be our // key. This leads to a integer value at most 20-bits, which can always // fit in an SMI value and be used as a fast sparse array / object key. // Output code for the current contents of the index buffer. var ib_code = index_stream[0] & code_mask; // Load first input index. var code_table = { }; // Key'd on our 20-bit "tuple". emit_code(clear_code); // Spec says first code should be a clear code. // First index already loaded, process the rest of the stream. for (var i = 1, il = index_stream.length; i < il; ++i) { var k = index_stream[i] & code_mask; var cur_key = ib_code << 8 | k; // (prev, k) unique tuple. var cur_code = code_table[cur_key]; // buffer + k. // Check if we have to create a new code table entry. if (cur_code === undefined) { // We don't have buffer + k. // Emit index buffer (without k). // This is an inline version of emit_code, because this is the core // writing routine of the compressor (and V8 cannot inline emit_code // because it is a closure here in a different context). Additionally // we can call emit_byte_to_buffer less often, because we can have // 30-bits (from our 31-bit signed SMI), and we know our codes will only // be 12-bits, so can safely have 18-bits there without overflow. // emit_code(ib_code); cur |= ib_code << cur_shift; cur_shift += cur_code_size; while (cur_shift >= 8) { buf[p++] = cur & 0xff; cur >>= 8; cur_shift -= 8; if (p === cur_subblock + 256) { // Finished a subblock. buf[cur_subblock] = 255; cur_subblock = p++; } } if (next_code === 4096) { // Table full, need a clear. emit_code(clear_code); next_code = eoi_code + 1; cur_code_size = min_code_size + 1; code_table = { }; } else { // Table not full, insert a new entry. // Increase our variable bit code sizes if necessary. This is a bit // tricky as it is based on "timing" between the encoding and // decoder. From the encoders perspective this should happen after // we've already emitted the index buffer and are about to create the // first table entry that would overflow our current code bit size. if (next_code >= (1 << cur_code_size)) ++cur_code_size; code_table[cur_key] = next_code++; // Insert into code table. } ib_code = k; // Index buffer to single input k. } else { ib_code = cur_code; // Index buffer to sequence in code table. } } emit_code(ib_code); // There will still be something in the index buffer. emit_code(eoi_code); // End Of Information. // Flush / finalize the sub-blocks stream to the buffer. emit_bytes_to_buffer(1); // Finish the sub-blocks, writing out any unfinished lengths and // terminating with a sub-block of length 0. If we have already started // but not yet used a sub-block it can just become the terminator. if (cur_subblock + 1 === p) { // Started but unused. buf[cur_subblock] = 0; } else { // Started and used, write length and additional terminator block. buf[cur_subblock] = p - cur_subblock - 1; buf[p++] = 0; } return p; }
javascript
{ "resource": "" }
q58056
mapArrayBufferViews
validation
function mapArrayBufferViews(ary) { return ary.map(function(chunk) { if (chunk.buffer instanceof ArrayBuffer) { var buf = chunk.buffer; // if this is a subarray, make a copy so we only // include the subarray region from the underlying buffer if (chunk.byteLength !== buf.byteLength) { var copy = new Uint8Array(chunk.byteLength); copy.set(new Uint8Array(buf, chunk.byteOffset, chunk.byteLength)); buf = copy.buffer; } return buf; } return chunk; }); }
javascript
{ "resource": "" }
q58057
promptUser
validation
function promptUser() { return inquirer.prompt([ { type: "list", name: "env", message: "Where does your code run?", default: ["browser"], choices: [ { name: "Browser", value: "browser" }, { name: "Node", value: "node" } ] }, { type: "checkbox", name: "images", message: "Which ImageTypes should be supported?", default: ["jpeg_support", 'bmp_support', 'gif_support', 'webp_support'], choices: [ { name: "Jpeg", value: "jpeg_support" }, { name: "Bmp", value: "bmp_support" }, { name: "Gif", value: "gif_support" }, { name: "WebP", value: "webp_support" } ] }, { type: "checkbox", name: "modules", message: "Additional Modules", default: ['acroform', 'annotations', 'arabic', 'autoprint', 'context2d', 'fileloading', 'filters', 'html', 'javascript', 'outline', 'setlanguage', 'svg', 'total_pages', 'utf8', 'viewerpreferences', 'xmp_metadata' ], choices: [ { name: "Acroform", value: "acroform" }, { name: "Annotations", value: "annotations" }, { name: "Arabic Parser", value: "arabic" }, { name: "Autoprint", value: "autoprint" }, { name: "Context2d", value: "context2d" }, { name: "File Loading", value: "fileloading" }, { name: "Filters", value: "filters" }, { name: "HTML", value: "html" }, { name: "Javascript", value: "javascript" }, { name: "Outline", value: "outline" }, { name: "Language-Tagging", value: "setlanguage" }, { name: "SVG", value: "svg" }, { name: "TotalPages", value: "total_pages" }, { name: "Unicode", value: "utf8" }, { name: "ViewerPreferences", value: "viewerpreferences" }, { name: "XMP Metadata", value: "xmp_metadata" } ] } ]).then(result => { console.log(generateFileList([...result.images, ...result.modules])); }); }
javascript
{ "resource": "" }
q58058
validation
function (imgData) { var doc = new jsPDF(); doc.addImage(imgData, 'JPEG', 10, 10, 50, 50); doc.addImage(imgData, 'JPEG', 70, 10, 100, 120); doc.save('output.pdf'); }
javascript
{ "resource": "" }
q58059
parseId
validation
function parseId(url) { if (is.empty(url)) { return null; } const regex = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/; return url.match(regex) ? RegExp.$2 : url; }
javascript
{ "resource": "" }
q58060
isSameException
validation
function isSameException(ex1, ex2) { if (isOnlyOneTruthy(ex1, ex2)) return false; ex1 = ex1.values[0]; ex2 = ex2.values[0]; if (ex1.type !== ex2.type || ex1.value !== ex2.value) return false; // in case both stacktraces are undefined, we can't decide so default to false if (isBothUndefined(ex1.stacktrace, ex2.stacktrace)) return false; return isSameStacktrace(ex1.stacktrace, ex2.stacktrace); }
javascript
{ "resource": "" }
q58061
isSameStacktrace
validation
function isSameStacktrace(stack1, stack2) { if (isOnlyOneTruthy(stack1, stack2)) return false; var frames1 = stack1.frames; var frames2 = stack2.frames; // Exit early if stacktrace is malformed if (frames1 === undefined || frames2 === undefined) return false; // Exit early if frame count differs if (frames1.length !== frames2.length) return false; // Iterate through every frame; bail out if anything differs var a, b; for (var i = 0; i < frames1.length; i++) { a = frames1[i]; b = frames2[i]; if (a.filename !== b.filename || a.lineno !== b.lineno || a.colno !== b.colno || a['function'] !== b['function']) return false; } return true; }
javascript
{ "resource": "" }
q58062
fill
validation
function fill(obj, name, replacement, track) { if (obj == null) return; var orig = obj[name]; obj[name] = replacement(orig); obj[name].__raven__ = true; obj[name].__orig__ = orig; if (track) { track.push([obj, name, orig]); } }
javascript
{ "resource": "" }
q58063
safeJoin
validation
function safeJoin(input, delimiter) { if (!isArray(input)) return ''; var output = []; for (var i = 0; i < input.length; i++) { try { output.push(String(input[i])); } catch (e) { output.push('[value cannot be serialized]'); } } return output.join(delimiter); }
javascript
{ "resource": "" }
q58064
notifyHandlers
validation
function notifyHandlers(stack, isWindowError) { var exception = null; if (isWindowError && !TraceKit.collectWindowErrors) { return; } for (var i in handlers) { if (handlers.hasOwnProperty(i)) { try { handlers[i].apply(null, [stack].concat(_slice.call(arguments, 2))); } catch (inner) { exception = inner; } } } if (exception) { throw exception; } }
javascript
{ "resource": "" }
q58065
traceKitWindowOnError
validation
function traceKitWindowOnError(msg, url, lineNo, colNo, ex) { var stack = null; // If 'ex' is ErrorEvent, get real Error from inside var exception = utils.isErrorEvent(ex) ? ex.error : ex; // If 'msg' is ErrorEvent, get real message from inside var message = utils.isErrorEvent(msg) ? msg.message : msg; if (lastExceptionStack) { TraceKit.computeStackTrace.augmentStackTraceWithInitialElement(lastExceptionStack, url, lineNo, message); processLastException(); } else if (exception && utils.isError(exception)) { // non-string `exception` arg; attempt to extract stack trace // New chrome and blink send along a real error object // Let's just report that like a normal error. // See: https://mikewest.org/2013/08/debugging-runtime-errors-with-window-onerror stack = TraceKit.computeStackTrace(exception); notifyHandlers(stack, true); } else { var location = { url: url, line: lineNo, column: colNo }; var name = undefined; var groups; if ({}.toString.call(message) === '[object String]') { var groups = message.match(ERROR_TYPES_RE); if (groups) { name = groups[1]; message = groups[2]; } } location.func = UNKNOWN_FUNCTION; stack = { name: name, message: message, url: getLocationHref(), stack: [location] }; notifyHandlers(stack, true); } if (_oldOnerrorHandler) { return _oldOnerrorHandler.apply(this, arguments); } return false; }
javascript
{ "resource": "" }
q58066
report
validation
function report(ex, rethrow) { var args = _slice.call(arguments, 1); if (lastExceptionStack) { if (lastException === ex) { return; // already caught by an inner catch block, ignore } else { processLastException(); } } var stack = TraceKit.computeStackTrace(ex); lastExceptionStack = stack; lastException = ex; lastArgs = args; // If the stack trace is incomplete, wait for 2 seconds for // slow slow IE to see if onerror occurs or not before reporting // this exception; otherwise, we will end up with an incomplete // stack trace setTimeout(function () { if (lastException === ex) { processLastException(); } }, stack.incomplete ? 2000 : 0); if (rethrow !== false) { throw ex; // re-throw to propagate to the top level (and cause window.onerror) } }
javascript
{ "resource": "" }
q58067
augmentStackTraceWithInitialElement
validation
function augmentStackTraceWithInitialElement(stackInfo, url, lineNo, message) { var initial = { url: url, line: lineNo }; if (initial.url && initial.line) { stackInfo.incomplete = false; if (!initial.func) { initial.func = UNKNOWN_FUNCTION; } if (stackInfo.stack.length > 0) { if (stackInfo.stack[0].url === initial.url) { if (stackInfo.stack[0].line === initial.line) { return false; // already in stack trace } else if (!stackInfo.stack[0].line && stackInfo.stack[0].func === initial.func) { stackInfo.stack[0].line = initial.line; return false; } } } stackInfo.stack.unshift(initial); stackInfo.partial = true; return true; } else { stackInfo.incomplete = true; } return false; }
javascript
{ "resource": "" }
q58068
computeStackTrace
validation
function computeStackTrace(ex, depth) { var stack = null; depth = depth == null ? 0 : +depth; try { stack = computeStackTraceFromStackProp(ex); if (stack) { return stack; } } catch (e) { if (TraceKit.debug) { throw e; } } try { stack = computeStackTraceByWalkingCallerChain(ex, depth + 1); if (stack) { return stack; } } catch (e) { if (TraceKit.debug) { throw e; } } return { name: ex.name, message: ex.message, url: getLocationHref() }; }
javascript
{ "resource": "" }
q58069
_promiseRejectionHandler
validation
function _promiseRejectionHandler(event) { this._logDebug('debug', 'Raven caught unhandled promise rejection:', event); this.captureException(event.reason, { mechanism: { type: 'onunhandledrejection', handled: false } }); }
javascript
{ "resource": "" }
q58070
captureException
validation
function captureException(ex, options) { options = objectMerge$1({ trimHeadFrames: 0 }, options ? options : {}); if (isErrorEvent$1(ex) && ex.error) { // If it is an ErrorEvent with `error` property, extract it to get actual Error ex = ex.error; } else if (isDOMError$1(ex) || isDOMException$1(ex)) { // If it is a DOMError or DOMException (which are legacy APIs, but still supported in some browsers) // then we just extract the name and message, as they don't provide anything else // https://developer.mozilla.org/en-US/docs/Web/API/DOMError // https://developer.mozilla.org/en-US/docs/Web/API/DOMException var name = ex.name || (isDOMError$1(ex) ? 'DOMError' : 'DOMException'); var message = ex.message ? name + ': ' + ex.message : name; return this.captureMessage(message, objectMerge$1(options, { // neither DOMError or DOMException provide stack trace and we most likely wont get it this way as well // but it's barely any overhead so we may at least try stacktrace: true, trimHeadFrames: options.trimHeadFrames + 1 })); } else if (isError$1(ex)) { // we have a real Error object ex = ex; } else if (isPlainObject$1(ex)) { // If it is plain Object, serialize it manually and extract options // This will allow us to group events based on top-level keys // which is much better than creating new group when any key/value change options = this._getCaptureExceptionOptionsFromPlainObject(options, ex); ex = new Error(options.message); } else { // If none of previous checks were valid, then it means that // it's not a DOMError/DOMException // it's not a plain Object // it's not a valid ErrorEvent (one with an error property) // it's not an Error // So bail out and capture it as a simple message: return this.captureMessage(ex, objectMerge$1(options, { stacktrace: true, // if we fall back to captureMessage, default to attempting a new trace trimHeadFrames: options.trimHeadFrames + 1 })); } // Store the raw exception object for potential debugging and introspection this._lastCapturedException = ex; // TraceKit.report will re-raise any exception passed to it, // which means you have to wrap it in try/catch. Instead, we // can wrap it here and only re-raise if TraceKit.report // raises an exception different from the one we asked to // report on. try { var stack = tracekit.computeStackTrace(ex); this._handleStackInfo(stack, options); } catch (ex1) { if (ex !== ex1) { throw ex1; } } return this; }
javascript
{ "resource": "" }
q58071
_breadcrumbEventHandler
validation
function _breadcrumbEventHandler(evtName) { var self = this; return function (evt) { // reset keypress timeout; e.g. triggering a 'click' after // a 'keypress' will reset the keypress debounce so that a new // set of keypresses can be recorded self._keypressTimeout = null; // It's possible this handler might trigger multiple times for the same // event (e.g. event propagation through node ancestors). Ignore if we've // already captured the event. if (self._lastCapturedEvent === evt) return; self._lastCapturedEvent = evt; // try/catch both: // - accessing evt.target (see getsentry/raven-js#838, #768) // - `htmlTreeAsString` because it's complex, and just accessing the DOM incorrectly // can throw an exception in some circumstances. var target; try { target = htmlTreeAsString$1(evt.target); } catch (e) { target = '<unknown>'; } self.captureBreadcrumb({ category: 'ui.' + evtName, // e.g. ui.click, ui.input message: target }); }; }
javascript
{ "resource": "" }
q58072
_captureUrlChange
validation
function _captureUrlChange(from, to) { var parsedLoc = parseUrl$1(this._location.href); var parsedTo = parseUrl$1(to); var parsedFrom = parseUrl$1(from); // because onpopstate only tells you the "new" (to) value of location.href, and // not the previous (from) value, we need to track the value of the current URL // state ourselves this._lastHref = to; // Use only the path component of the URL if the URL matches the current // document (almost all the time when using pushState) if (parsedLoc.protocol === parsedTo.protocol && parsedLoc.host === parsedTo.host) to = parsedTo.relative; if (parsedLoc.protocol === parsedFrom.protocol && parsedLoc.host === parsedFrom.host) from = parsedFrom.relative; this.captureBreadcrumb({ category: 'navigation', data: { to: to, from: from } }); }
javascript
{ "resource": "" }
q58073
_isRepeatData
validation
function _isRepeatData(current) { var last = this._lastData; if (!last || current.message !== last.message || // defined for captureMessage current.transaction !== last.transaction // defined for captureException/onerror ) return false; // Stacktrace interface (i.e. from captureMessage) if (current.stacktrace || last.stacktrace) { return isSameStacktrace$1(current.stacktrace, last.stacktrace); } else if (current.exception || last.exception) { // Exception interface (i.e. from captureException/onerror) return isSameException$1(current.exception, last.exception); } return true; }
javascript
{ "resource": "" }
q58074
getDecimalPlaces
validation
function getDecimalPlaces(value) { var match = "".concat(value).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/); if (!match) { return 0; } return Math.max(0, // Number of digits right of decimal point. (match[1] ? match[1].length : 0) - ( // Adjust for scientific notation. match[2] ? +match[2] : 0)); }
javascript
{ "resource": "" }
q58075
round
validation
function round(number, step) { if (step < 1) { var places = getDecimalPlaces(step); return parseFloat(number.toFixed(places)); } return Math.round(number / step) * step; }
javascript
{ "resource": "" }
q58076
RangeTouch
validation
function RangeTouch(target, options) { _classCallCheck(this, RangeTouch); if (is.element(target)) { // An Element is passed, use it directly this.element = target; } else if (is.string(target)) { // A CSS Selector is passed, fetch it from the DOM this.element = document.querySelector(target); } if (!is.element(this.element) || !is.empty(this.element.rangeTouch)) { return; } this.config = Object.assign({}, defaults, options); this.init(); }
javascript
{ "resource": "" }
q58077
setup
validation
function setup(target) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var targets = null; if (is.empty(target) || is.string(target)) { targets = Array.from(document.querySelectorAll(is.string(target) ? target : 'input[type="range"]')); } else if (is.element(target)) { targets = [target]; } else if (is.nodeList(target)) { targets = Array.from(target); } else if (is.array(target)) { targets = target.filter(is.element); } if (is.empty(targets)) { return null; } var config = Object.assign({}, defaults, options); if (is.string(target) && config.watch) { // Create an observer instance var observer = new MutationObserver(function (mutations) { Array.from(mutations).forEach(function (mutation) { Array.from(mutation.addedNodes).forEach(function (node) { if (!is.element(node) || !matches(node, target)) { return; } // eslint-disable-next-line no-unused-vars var range = new RangeTouch(node, config); }); }); }); // Pass in the target node, as well as the observer options observer.observe(document.body, { childList: true, subtree: true }); } return targets.map(function (t) { return new RangeTouch(t, options); }); }
javascript
{ "resource": "" }
q58078
toggleListener
validation
function toggleListener(element, event, callback) { var _this = this; var toggle = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; var passive = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true; var capture = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false; // Bail if no element, event, or callback if (!element || !('addEventListener' in element) || is$1.empty(event) || !is$1.function(callback)) { return; } // Allow multiple events var events = event.split(' '); // Build options // Default to just the capture boolean for browsers with no passive listener support var options = capture; // If passive events listeners are supported if (supportsPassiveListeners) { options = { // Whether the listener can be passive (i.e. default never prevented) passive: passive, // Whether the listener is a capturing listener or not capture: capture }; } // If a single node is passed, bind the event listener events.forEach(function (type) { if (_this && _this.eventListeners && toggle) { // Cache event listener _this.eventListeners.push({ element: element, type: type, callback: callback, options: options }); } element[toggle ? 'addEventListener' : 'removeEventListener'](type, callback, options); }); }
javascript
{ "resource": "" }
q58079
on
validation
function on(element) { var events = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; var callback = arguments.length > 2 ? arguments[2] : undefined; var passive = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true; var capture = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false; toggleListener.call(this, element, events, callback, true, passive, capture); }
javascript
{ "resource": "" }
q58080
once
validation
function once(element) { var _this2 = this; var events = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; var callback = arguments.length > 2 ? arguments[2] : undefined; var passive = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true; var capture = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false; var onceCallback = function onceCallback() { off(element, events, onceCallback, passive, capture); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } callback.apply(_this2, args); }; toggleListener.call(this, element, events, onceCallback, true, passive, capture); }
javascript
{ "resource": "" }
q58081
unbindListeners
validation
function unbindListeners() { if (this && this.eventListeners) { this.eventListeners.forEach(function (item) { var element = item.element, type = item.type, callback = item.callback, options = item.options; element.removeEventListener(type, callback, options); }); this.eventListeners = []; } }
javascript
{ "resource": "" }
q58082
getDeep
validation
function getDeep(object, path) { return path.split('.').reduce(function (obj, key) { return obj && obj[key]; }, object); }
javascript
{ "resource": "" }
q58083
extend
validation
function extend() { var target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; for (var _len = arguments.length, sources = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { sources[_key - 1] = arguments[_key]; } if (!sources.length) { return target; } var source = sources.shift(); if (!is$1.object(source)) { return target; } Object.keys(source).forEach(function (key) { if (is$1.object(source[key])) { if (!Object.keys(target).includes(key)) { Object.assign(target, _defineProperty({}, key, {})); } extend(target[key], source[key]); } else { Object.assign(target, _defineProperty({}, key, source[key])); } }); return extend.apply(void 0, [target].concat(sources)); }
javascript
{ "resource": "" }
q58084
createElement
validation
function createElement(type, attributes, text) { // Create a new <element> var element = document.createElement(type); // Set all passed attributes if (is$1.object(attributes)) { setAttributes(element, attributes); } // Add text node if (is$1.string(text)) { element.innerText = text; } // Return built element return element; }
javascript
{ "resource": "" }
q58085
insertAfter
validation
function insertAfter(element, target) { if (!is$1.element(element) || !is$1.element(target)) { return; } target.parentNode.insertBefore(element, target.nextSibling); }
javascript
{ "resource": "" }
q58086
insertElement
validation
function insertElement(type, parent, attributes, text) { if (!is$1.element(parent)) { return; } parent.appendChild(createElement(type, attributes, text)); }
javascript
{ "resource": "" }
q58087
emptyElement
validation
function emptyElement(element) { if (!is$1.element(element)) { return; } var length = element.childNodes.length; while (length > 0) { element.removeChild(element.lastChild); length -= 1; } }
javascript
{ "resource": "" }
q58088
getAttributesFromSelector
validation
function getAttributesFromSelector(sel, existingAttributes) { // For example: // '.test' to { class: 'test' } // '#test' to { id: 'test' } // '[data-test="test"]' to { 'data-test': 'test' } if (!is$1.string(sel) || is$1.empty(sel)) { return {}; } var attributes = {}; var existing = extend({}, existingAttributes); sel.split(',').forEach(function (s) { // Remove whitespace var selector = s.trim(); var className = selector.replace('.', ''); var stripped = selector.replace(/[[\]]/g, ''); // Get the parts and value var parts = stripped.split('='); var _parts = _slicedToArray(parts, 1), key = _parts[0]; var value = parts.length > 1 ? parts[1].replace(/["']/g, '') : ''; // Get the first character var start = selector.charAt(0); switch (start) { case '.': // Add to existing classname if (is$1.string(existing.class)) { attributes.class = "".concat(existing.class, " ").concat(className); } else { attributes.class = className; } break; case '#': // ID selector attributes.id = selector.replace('#', ''); break; case '[': // Attribute selector attributes[key] = value; break; default: break; } }); return extend(existing, attributes); }
javascript
{ "resource": "" }
q58089
toggleClass
validation
function toggleClass(element, className, force) { if (is$1.nodeList(element)) { return Array.from(element).map(function (e) { return toggleClass(e, className, force); }); } if (is$1.element(element)) { var method = 'toggle'; if (typeof force !== 'undefined') { method = force ? 'add' : 'remove'; } element.classList[method](className); return element.classList.contains(className); } return false; }
javascript
{ "resource": "" }
q58090
hasClass
validation
function hasClass(element, className) { return is$1.element(element) && element.classList.contains(className); }
javascript
{ "resource": "" }
q58091
matches$1
validation
function matches$1(element, selector) { function match() { return Array.from(document.querySelectorAll(selector)).includes(this); } var matches = match; return matches.call(element, selector); }
javascript
{ "resource": "" }
q58092
trapFocus
validation
function trapFocus() { var element = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; var toggle = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; if (!is$1.element(element)) { return; } var focusable = getElements.call(this, 'button:not(:disabled), input:not(:disabled), [tabindex]'); var first = focusable[0]; var last = focusable[focusable.length - 1]; var trap = function trap(event) { // Bail if not tab key or not fullscreen if (event.key !== 'Tab' || event.keyCode !== 9) { return; } // Get the current focused element var focused = document.activeElement; if (focused === last && !event.shiftKey) { // Move focus to first element that can be tabbed if Shift isn't used first.focus(); event.preventDefault(); } else if (focused === first && event.shiftKey) { // Move focus to last element that can be tabbed if Shift is used last.focus(); event.preventDefault(); } }; toggleListener.call(this, this.elements.container, 'keydown', trap, toggle, false); }
javascript
{ "resource": "" }
q58093
setFocus
validation
function setFocus() { var element = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; var tabFocus = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; if (!is$1.element(element)) { return; } // Set regular focus element.focus({ preventScroll: true }); // If we want to mimic keyboard focus via tab if (tabFocus) { toggleClass(element, this.config.classNames.tabFocus); } }
javascript
{ "resource": "" }
q58094
repaint
validation
function repaint(element) { setTimeout(function () { try { toggleHidden(element, true); element.offsetHeight; // eslint-disable-line toggleHidden(element, false); } catch (e) {// Do nothing } }, 0); }
javascript
{ "resource": "" }
q58095
check
validation
function check(type, provider, playsinline) { var canPlayInline = browser.isIPhone && playsinline && support.playsinline; var api = support[type] || provider !== 'html5'; var ui = api && support.rangeInput && (type !== 'video' || !browser.isIPhone || canPlayInline); return { api: api, ui: ui }; }
javascript
{ "resource": "" }
q58096
setAspectRatio
validation
function setAspectRatio(input) { if (!this.isVideo) { return {}; } var ratio = getAspectRatio.call(this, input); var _ref = is$1.array(ratio) ? ratio : [0, 0], _ref2 = _slicedToArray(_ref, 2), w = _ref2[0], h = _ref2[1]; var padding = 100 / w * h; this.elements.wrapper.style.paddingBottom = "".concat(padding, "%"); // For Vimeo we have an extra <div> to hide the standard controls and UI if (this.isVimeo && this.supported.ui) { var height = 240; var offset = (height - padding) / (height / 50); this.media.style.transform = "translateY(-".concat(offset, "%)"); } else if (this.isHTML5) { this.elements.wrapper.classList.toggle(this.config.classNames.videoFixedRatio, ratio !== null); } return { padding: padding, ratio: ratio }; }
javascript
{ "resource": "" }
q58097
getQualityOptions
validation
function getQualityOptions() { // Get sizes from <source> elements return html5.getSources.call(this).map(function (source) { return Number(source.getAttribute('size')); }).filter(Boolean); }
javascript
{ "resource": "" }
q58098
closest
validation
function closest(array, value) { if (!is$1.array(array) || !array.length) { return null; } return array.reduce(function (prev, curr) { return Math.abs(curr - value) < Math.abs(prev - value) ? curr : prev; }); }
javascript
{ "resource": "" }
q58099
replaceAll
validation
function replaceAll() { var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; var find = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; var replace = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ''; return input.replace(new RegExp(find.toString().replace(/([.*+?^=!:${}()|[\]/\\])/g, '\\$1'), 'g'), replace.toString()); }
javascript
{ "resource": "" }