export default function makeContentLinksSafe( post, dom ) { const links = toArray( dom.querySelectorAll( 'a[href]' ) ); forEach( links, ( link ) => { // only accept links that are to http or https sites if ( ! safeLinkRe.test( link.href ) ) { link.removeAttribute( 'href' ); } } ); return post; }
/** * * @param values * @returns {number} */ export function max(values: Record<string, number> | number[]): number { return Math.max(...toArray(values)); }
function getAggregate(database, collection) { return pipeline => { return new Promise((resolve, reject) => { database.collection(collection).aggregate(pipeline, (error, cursor) => { if (error) { return reject(error); } return resolve(cursor.toArray()); }); }); }; }
function getMaxSeq(nodeID) { return brokers.reduce((seq, { broker }) => { if (!broker) return seq; let n = broker.registry.nodes.toArray().find(n => n.id == nodeID); return (n && n.seq && n.seq > seq) ? n.seq : seq; }, 0); }
it('properly overrides files', async () => { const gfsAdapter = new GridFSBucketAdapter(databaseURI); await gfsAdapter.createFile('myFileName', 'a simple file'); await gfsAdapter.createFile('myFileName', 'an overrided simple file'); const data = await gfsAdapter.getFileData('myFileName'); expect(data.toString('utf8')).toBe('an overrided simple file'); const bucket = await gfsAdapter._getBucket(); const documents = await bucket.find({ filename: 'myFileName' }).toArray(); expect(documents.length).toBe(2); await gfsAdapter.deleteFile('myFileName'); await expectMissingFile(gfsAdapter, 'myFileName'); });
test("fn.toArray", t => { const fn = $.toArray t.deepEqual(fn([]), [], "keeps `[]` as is") t.deepEqual(fn(null), [], "converts `null` to empty array") t.deepEqual(fn(undefined), [], "converts `undefined` to empty array") t.deepEqual(fn(-1), [-1], "converts `-1` to `[-1]`") t.deepEqual(fn(0), [0], "converts `0` to `[0]`") t.deepEqual(fn(1), [1], "converts `1` to `[1]`") t.deepEqual(fn("foo"), ["foo"]) t.deepEqual(fn(["foo"]), ["foo"]) t.end() })
function permutations(obj, n) { if (typeof obj == 'string') obj = toArray(obj); n = n ? n : obj.length; // make n copies of keys/indices const nInds = []; //TODO: WHAT for (let j = 0, nInds = []; j < n; j++) { nInds.push(keys(obj)); } // get product of the indices, then filter to remove the same key twice let arrangements = product(nInds).filter(pair => pair[0] !== pair[1]); return map(arrangements, indices => map(indices, i => obj[i])); }
router.get('/apis/spider', async (ctx) => { const items = await ctx.torrentdb.collection('spider').find().sort({_id:-1}).limit(100).toArray() ctx.body = { items: items, code: 0 } })
async deleteFile(filename: string) { const bucket = await this._getBucket(); const documents = await bucket.find({ filename }).toArray(); if (documents.length === 0) { throw new Error('FileNotFound'); } return Promise.all( documents.map((doc) => { return bucket.delete(doc._id); }) ); }
aggregate(pipeline, { maxTimeMS, readPreference, hint, explain } = {}) { return this._mongoCollection .aggregate(pipeline, { maxTimeMS, readPreference, hint, explain }) .toArray(); }
/** * Gets all given bits that are missing from the bitfield. * @param {BitFieldResolvable} bits Bit(s) to check for * @param {...*} hasParams Additional parameters for the has method, if any * @returns {string[]} */ missing(bits, ...hasParams) { if (!Array.isArray(bits)) bits = new this.constructor(bits).toArray(false); return bits.filter(p => !this.has(p, ...hasParams)); }
/** * Bind preview frame links. */ function enablePreviewLinks( selector ) { var anchors = toArray( document.querySelectorAll( selector ? selector : 'a' ) ); anchors.forEach( function( element ) { if( /^(http|www)/gi.test( element.getAttribute( 'href' ) ) ) { element.addEventListener( 'click', onPreviewLinkClicked, false ); } } ); }
async getMetadata(filename) { const bucket = await this._getBucket(); const files = await bucket.find({ filename }).toArray(); if (files.length === 0) { return {}; } const { metadata } = files[0]; return { metadata }; }
/** * Unbind preview frame links. */ function disablePreviewLinks() { var anchors = toArray( document.querySelectorAll( 'a' ) ); anchors.forEach( function( element ) { if( /^(http|www)/gi.test( element.getAttribute( 'href' ) ) ) { element.removeEventListener( 'click', onPreviewLinkClicked, false ); } } ); }
async deleteFile(filename) { const bucket = await this._getBucket(); const documents = await bucket.find({ filename }).toArray(); if (documents.length === 0) { throw new Error('FileNotFound'); } return Promise.all(documents.map(doc => { return bucket.delete(doc._id); })); }