get currentDependencies() { let allDependencies = self.filteredProjects.reduce((accum, project) => { let dependencies = project.packageJson && project.packageJson.dependencies ? Object.entries({ ...project.packageJson.dependencies }).map(([a]) => a) : []; accum = [...accum, ...dependencies]; return accum; }, []); const grouped = Object.entries(countBy(allDependencies)).map(([name, count]) => ({ name, count })); const unique = uniqBy(grouped, a => a.name); const sorted = orderBy(unique, ['count', 'name'], ['desc', 'asc']); return sorted; }
getAllOrders() .then(orders => { let supporters = orders.map(nodeToSupporter).sort((a, b) => b.totalDonations - a.totalDonations); // Deduplicating supporters with multiple orders supporters = uniqBy(supporters, 'slug'); if (!Array.isArray(supporters)) { throw new Error('Supporters data is not an array.'); } for (const item of supporters) { for (const key of REQUIRED_KEYS) { if (!item || typeof item !== 'object') { throw new Error(`Supporters: ${JSON.stringify(item)} is not an object.`); } if (!(key in item)) { throw new Error(`Supporters: ${JSON.stringify(item)} doesn't include ${key}.`); } } } // Write the file return asyncWriteFile(absoluteFilename, JSON.stringify(supporters, null, 2)).then(() => console.log(`Fetched 1 file: ${filename}`) ); }) .catch(error => { console.error('utilities/fetch-supporters:', error); });
const addTag = (tags, t) => { tags.unshift(t) return uniqBy(tags, 'tag') }
// LOGS USER OUT app.get('/logout', mw.LoggedIn, async (req, res) => { try { let { id, username } = req.session, user = { id, username }, oldUsers = req.cookies.users ? JSON.parse(req.cookies.users) : [], users = [] oldUsers.map(o => users.push(o)) let final = uniqBy([user, ...users], 'id') res.cookie('users', `${JSON.stringify(final)}`) let u = { isOnline: 'no', lastOnline: new Date().getTime(), } await db.query('UPDATE users SET ? WHERE id=?', [u, id]) let url = req.session.reset() ? '/login' : '/' res.redirect(url) } catch (error) { console.log(error) } })
prev, dataKey, uniqBy([...previousData, ...fetchMoreData], 'id') ); },
componentWillReceiveProps(nextProps) { if (this.props.errors !== nextProps.errors) { this.setState({ errors: uniqBy(union(this.state.errors, nextProps.errors), 'id') }); } }
componentWillReceiveProps(nextProps) { if (!this.isSame(nextProps)) { const errors = isEmpty(nextProps.errors) ? [] : uniqBy(union(this.state.errors, nextProps.errors), 'id'); // if (isEmpty(nextProps.errors)) remove(errors, (error) => error.id === 'settings-manager.request.error.database.exist'); this.setState({ errors }); } if (isEmpty(nextProps.errors)) { this.setState({ errors: [] }); } }
componentDidMount () { this.props.data.subscribeToMore({ document: PresenceSubscription, variables: {}, updateQuery: (prev, {subscriptionData}) => { const result = { users: prev.users } if(subscriptionData.data.onPresence.presence.status === 'LEFT') { result.users = differenceBy(prev.users, [subscriptionData.data.onPresence], x => x.id) if(subscriptionData.data.onPresence.id === this.state.id) this.setState({id: undefined, alias: undefined}) return result } result.users = uniqBy(prev.users.concat([subscriptionData.data.onPresence]), x => x.id) return result } }) }
async statusPackages(options: Object) { const table = new this.helpers.Table({ head: ['project', 'changes', 'branch', 'path', 'npm'] }) let packages = await this.getAllPackages() if (options.scope) { packages = this.matchPackages(packages, this.helpers.split(options.scope, ',')) } const repositories = await this.processRepositories(uniqBy(packages.map(p => p.project), project => project.path), options) const packagesRemote: Map<Package, Package> = new Map() await this.helpers.parallel('Getting remote details', packages.map(pkg => ({ title: pkg.path === pkg.project.path ? `${pkg.project.org}/${pkg.project.name}` : `${pkg.project.org}/${pkg.project.name}/${pkg.name}`, // eslint-disable-next-line arrow-parens callback: async () => { packagesRemote.set(pkg, await this.getNodePackageState(pkg)) }, }))) for (let i = 0, length = packages.length; i < length; i++) { const pkg = packages[i] const repository = repositories.get(pkg.project) const packageRemote = packagesRemote.get(pkg) invariant(repository && packageRemote) table.push(this.getRow(pkg.project, pkg, packageRemote, repository)) } this.log(table.show()) }
(uniqBy(roles, 'id') || []).reduce((prev, curr) => { return prev.concat(curr.resources || []); }, [])
/** * Returns a list of all groups of which a given player is a member. */ async function getPlayerGroups(playerId, pagination = { limit: 10000, offset: 0 }) { if (!playerId) { throw new BadRequestError(`Invalid player id.`); } // Find all memberships for the player const memberships = await Membership.findAll({ where: { playerId }, include: [{ model: Group }] }); // Extract all the unique groups from the memberships, and format them. const groups = uniqBy(memberships, (m: any) => m.group.id) .slice(pagination.offset, pagination.offset + pagination.limit) .map(p => p.group) .sort((a, b) => b.score - a.score) .map(format); const completeGroups = await attachMembersCount(groups); return completeGroups; }
const uniqueUsernames = uniqBy(usernames, u => playerService.standardize(u));