ShowHiddenChannels: New screen for showing hidden channels (#460)

Co-authored-by: Ven <vendicated@riseup.net>
This commit is contained in:
Nuckyz 2023-02-01 08:11:05 -03:00 committed by GitHub
parent 8f4e8d0a9b
commit 369d179bbf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 366 additions and 77 deletions

View file

@ -16,6 +16,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { moment } from "@webpack/common";
// Utils for readable text transformations eg: `toTitle(fromKebab())`
// Case style to words
@ -34,3 +36,26 @@ export const wordsToPascal = (words: string[]) =>
words.map(w => w[0].toUpperCase() + w.slice(1)).join("");
export const wordsToTitle = (words: string[]) =>
words.map(w => w[0].toUpperCase() + w.slice(1)).join(" ");
/**
* Forms milliseconds into a human readable string link "1 day, 2 hours, 3 minutes and 4 seconds"
* @param ms Milliseconds
* @param short Whether to use short units like "d" instead of "days"
*/
export function formatDuration(ms: number, short: boolean = false) {
const dur = moment.duration(ms);
return (["years", "months", "weeks", "days", "hours", "minutes", "seconds"] as const).reduce((res, unit) => {
const x = dur[unit]();
if (x > 0 || res.length) {
if (res.length)
res += unit === "seconds" ? " and " : ", ";
const unitStr = short
? unit[0]
: x === 1 ? unit.slice(0, -1) : unit;
res += `${x} ${unitStr}`;
}
return res;
}, "").replace(/((,|and) \b0 \w+)+$/, "") || "now";
}