function matches( element, selector ) { const ep = Element.prototype; // modern browsers support `matches` but IE11 and older safari support it as `matchesSelector` with a prefix const matcher = ep.matches || ep.webkitMatchesSelector || ep.mozMatchesSelector || ep.msMatchesSelector; if ( ! matcher ) { return false; } return matcher.call( element, selector ); }
function generateBinArgs( name ) { if ( Object.prototype.hasOwnProperty.call( config.codemodArgs, name ) ) { // Is the codemod defined in the codemodArgs object? return config.codemodArgs[ name ]; } if ( getLocalCodemodFileNames().includes( name ) ) { return [ `--transform=${ transformsDir }/${ name }.js` ]; } throw new Error( `"${ name }" is an unrecognized codemod.` ); }
expect( LSTMTimeStep.prototype.trainInputOutput.mock.calls[0][0] ).toEqual({ input: [42, 44, 53, 64].map((value) => Float32Array.from([value])), output: [75, 83].map((value) => Float32Array.from([value])), });
// format a parsed object into a url string function urlFormat(obj) { // ensure it's an object, and not a string url. // If it's an obj, this is a no-op. // this way, you can call url_format() on strings // to clean up potentially wonky urls. if (util.isString(obj)) obj = urlParse(obj); if (!(obj instanceof Url)) return Url.prototype.format.call(obj); return obj.format(); }
beforeEach(() => { utils.stubWidgets(sandbox); testContainer = utils.getTestContainer(sandbox); options = { logProvider: new LogProvider(testContainer.screen), layoutConfig: { getPosition: sandbox.stub() }, parent: testContainer }; sandbox.stub(StreamView.prototype, "log"); });
// monkey-patch the array prototype because these are tests and IDGAF Object.defineProperty(Array.prototype, 'last', { value: function() { return this[this.length - 1] }, enumberable: false })
const getDateObject = (dateString) => { const date = new Date(dateString) // Thanks to https://stackoverflow.com/questions/1353684/detecting-an-invalid-date-date-instance-in-javascript if (Object.prototype.toString.call(date) === '[object Date]' && isNaN(date.getTime())) { throw new Error(`invalid date string ${dateString}`) } return date }
it('should return validation error if event body is invalid', async () => { const incident = generateIncident('1') sinon.stub(IncidentsStore.prototype, 'get').returns(incident) sinon.stub(IncidentsStore.prototype, 'update').returns() sinon.stub(IncidentUpdatesStore.prototype, 'create').returns() sinon.stub(IncidentUpdatesStore.prototype, 'query').returns() return await handle({ params: { incidentid: '1' }, body: { status: '' } }, null, (error, result) => { assert(error.match(/invalid/)) }) })
// Mimic commander syntax errors (with offsets) for consistency /* eslint-disable no-console */ const exitWithError = function () { const args = Array.prototype.slice.call(arguments); console.error(); console.error(...[" "].concat(args)); console.error(); process.exit(1); // eslint-disable-line no-process-exit }
it('should return error on exception thrown', async () => { sinon.stub(IncidentsStore.prototype, 'get').throws() sinon.stub(IncidentsStore.prototype, 'update').returns() sinon.stub(IncidentUpdatesStore.prototype, 'create').returns() sinon.stub(IncidentUpdatesStore.prototype, 'query').returns() return await handle({ params: { incidentid: '1' } }, null, (error, result) => { assert(error.match(/Error/)) }) })
function getNormalizedKey(key) { const normalizedKey = getNormalizedKeyAttributeValue(key); if (key !== normalizedKey) { this.debugSection('Input', `Mapping key '${key}' to '${normalizedKey}'`); } // Use key definition to ensure correct key is displayed when Shift modifier is active if (Object.prototype.hasOwnProperty.call(keyDefinitionMap, normalizedKey)) { return keyDefinitionMap[normalizedKey]; } return normalizedKey; }
/** * Returns `true` if `v` is a DOM File instance, `false` otherwise. * * @param {any} v - instance to analyze * @returns {boolean} `true` if `v` is a DOM File instance */ function isFile( v ) { return v && Object.prototype.toString.call( v ) === '[object File]'; }
export function dump(obj) { let out = ''; for (const key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { out += `${key}: ${obj[key]}\n`; } } return out; }
// monkey-patch the array prototype because these are tests and IDGAF Object.defineProperty(Array.prototype, 'last', { value: function() { return this[this.length - 1] }, enumberable: false })