export function decodeEntities( text ) { // Bypass decode if text doesn't include entities if ( 'string' !== typeof text || -1 === text.indexOf( '&' ) ) { return text; } return decode( text ); }
exports.reduce( qs.replace( '?', '' ).split( '&' ), function ( obj, pair ) { var i = pair.indexOf( '=' ); var key = pair.slice( 0, i ); var val = pair.slice( ++i ); obj[ key ] = decodeURIComponent( val ); return obj; }, {} )
/** * Remove an item from an array */ export function remove(arr, item) { if (arr.length) { const index = arr.indexOf(item) if (index > -1) { return arr.splice(index, 1) } } }
async testConnection() { try { return await this.pool.query('SELECT $1::int AS number', ['1']); } catch (e) { if (e.toString().indexOf('no pg_hba.conf entry for host') !== -1) { throw new Error(`Please use CUBEJS_DB_SSL=true to connect: ${e.toString()}`); } throw e; } }
event.dispatcher.on(event.step.after, (step) => { if (config.methods.indexOf(step.helperMethod) < 0) return; // skip non-actions recorder.add('auto-delay', async () => { if (store.debugMode) return; // no need to delay in debug log(`Delaying for ${config.delayAfter}ms`); return new Promise((resolve) => { setTimeout(resolve, config.delayAfter); }); }); });
describe('#seeInSource, #grabSource', () => { it('should check for text to be in HTML source', () => I.amOnPage('/') .then(() => I.seeInSource('<title>TestEd Beta 2.0</title>')) .then(() => I.dontSeeInSource('<meta'))); it('should grab the source', () => I.amOnPage('/') .then(() => I.grabSource()) .then(source => assert.notEqual(source.indexOf('<title>TestEd Beta 2.0</title>'), -1, 'Source html should be retrieved'))); });
function simplifyObject(object) { return Object.keys(object) .filter(k => k.indexOf('_') !== 0) .filter(k => typeof object[k] !== 'function') .filter(k => typeof object[k] !== 'object') .reduce((obj, key) => { obj[key] = object[key]; return obj; }, {}); }
function truncate(msg, gap = 0) { if (msg.indexOf('\n') > 0) { return msg; // don't cut multi line steps } const width = (process.stdout.columns || 200) - gap - 4; if (msg.length > width) { msg = msg.substr(0, width - 1) + figures.ellipsis; } return msg; }
// copy opts to run Object.keys(options) .filter(key => copyOptions.indexOf(key) > -1) .forEach((key) => { childOpts[key] = options[key]; });
function getFrom(str, startToken, endToken) { var start = str.indexOf(startToken) + startToken.length; if (start < startToken.length) return ""; var lastHalf = str.substring(start); var end = lastHalf.indexOf(endToken); if (end === -1) { throw Error( "Could not find endTime `" + endToken + "` in the given string." ); } return lastHalf.substring(0, end); }
/** * Joins a list of files to a valid glob pattern */ const flattenFiles = (list) => { const pattern = list.join(','); return pattern.indexOf(',') > -1 ? `{${pattern}}` : pattern; }
customValidator(value) { if (value && value.length) { const base64ImageLength = Buffer.byteLength(value.substring(value.indexOf(',') + 1), 'base64'); if (base64ImageLength > MAX_SIZE_PROFILE_PICTURE) { throw new Error('Profile picture too big'); } } }
resetExcludedStep( stepName ) { const index = Flows.excludedSteps.indexOf( stepName ); if ( index > -1 ) { Flows.excludedSteps.splice( index, 1 ); } }
describe('#seeInSource, #grabSource', () => { it('should check for text to be in HTML source', () => wd.amOnPage('/') .then(() => wd.seeInSource('<title>TestEd Beta 2.0</title>')) .then(() => wd.dontSeeInSource('<meta'))); it('should grab the source', () => wd.amOnPage('/') .then(() => wd.grabSource()) .then(source => assert.notEqual(source.indexOf('<title>TestEd Beta 2.0</title>'), -1, 'Source html should be retrieved'))); });
customValidator(value) { if (value && value.length) { const base64ImageLength = Buffer.byteLength(value.substring(value.indexOf(',') + 1), 'base64'); if (base64ImageLength > MAX_SIZE_PROFILE_PICTURE) { throw new Error('Profile picture too big'); } } }