From 920fc07cb9377539e9169b51b2e7f1d2d60976a1 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 26 Mar 2022 12:36:19 -0500 Subject: add formatAttributes --- src/web/src/lib/util.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src') diff --git a/src/web/src/lib/util.js b/src/web/src/lib/util.js index 86bd6977..32c55090 100644 --- a/src/web/src/lib/util.js +++ b/src/web/src/lib/util.js @@ -34,6 +34,20 @@ export const getDirectoryName = (fullPath) => { return path; } +export const formatAttributes = ({ bitRate, isVariableBitRate, bitDepth, sampleRate }) => { + const isLossless = !!sampleRate && !!bitDepth; + + if (isLossless) { + return `${bitDepth}/${sampleRate/1000}kHz`; + } + + if (isVariableBitRate) { + return `${bitRate}kbps, VBR` + } + + return bitRate ? `${bitRate}kbps` : '' +} + /* https://www.npmjs.com/package/js-file-download * * Copyright 2017 Kenneth Jiang -- cgit v1.2.3