UNPKG

mattermost-redux

Version:

Common code (API client, Redux stores, logic, utility functions) for building a Mattermost client

36 lines (35 loc) 1.41 kB
"use strict"; // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. Object.defineProperty(exports, "__esModule", { value: true }); exports.teamListToMap = teamListToMap; exports.sortTeamsWithLocale = sortTeamsWithLocale; exports.filterTeamsStartingWithTerm = filterTeamsStartingWithTerm; const constants_1 = require("../constants"); function teamListToMap(teamList) { const teams = {}; for (let i = 0; i < teamList.length; i++) { teams[teamList[i].id] = teamList[i]; } return teams; } function sortTeamsWithLocale(locale) { return (a, b) => { if (a.display_name !== b.display_name) { return a.display_name.toLowerCase().localeCompare(b.display_name.toLowerCase(), locale || constants_1.General.DEFAULT_LOCALE, { numeric: true }); } return a.name.toLowerCase().localeCompare(b.name.toLowerCase(), locale || constants_1.General.DEFAULT_LOCALE, { numeric: true }); }; } function filterTeamsStartingWithTerm(teams, term) { const lowercasedTerm = term.toLowerCase(); return teams.filter((team) => { if (!team) { return false; } const name = team.name?.toLowerCase(); const displayName = team.display_name?.toLowerCase(); return name.startsWith(lowercasedTerm) || displayName.startsWith(lowercasedTerm); }); }