dependabot[bot] dab7914eab
Bump @justinribeiro/lite-youtube from 0.9.0 to 0.9.1 in /build/javascript (#273)
* Commit updated Javascript packages

* Bump preact from 10.5.4 to 10.5.5 in /build/javascript (#265)

* Trying a new github workflow to install javascript packages

* Bump tailwindcss from 1.9.2 to 1.9.4 in /build/javascript (#266)

Bumps [tailwindcss](https://github.com/tailwindlabs/tailwindcss) from 1.9.2 to 1.9.4.
- [Release notes](https://github.com/tailwindlabs/tailwindcss/releases)
- [Changelog](https://github.com/tailwindlabs/tailwindcss/blob/master/CHANGELOG.md)
- [Commits](https://github.com/tailwindlabs/tailwindcss/compare/v1.9.2...v1.9.4)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Commit updated Javascript packages

* Bump preact from 10.5.4 to 10.5.5 in /build/javascript

Bumps [preact](https://github.com/preactjs/preact) from 10.5.4 to 10.5.5.
- [Release notes](https://github.com/preactjs/preact/releases)
- [Commits](https://github.com/preactjs/preact/compare/10.5.4...10.5.5)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: Gabe Kangas <gabek@real-ity.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Owncast <owncast@owncast.online>

* Bump @justinribeiro/lite-youtube in /build/javascript

Bumps [@justinribeiro/lite-youtube](https://github.com/justinribeiro/lite-youtube) from 0.9.0 to 0.9.1.
- [Release notes](https://github.com/justinribeiro/lite-youtube/releases)
- [Commits](https://github.com/justinribeiro/lite-youtube/commits)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: Owncast <owncast@owncast.online>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Gabe Kangas <gabek@real-ity.com>
2020-10-20 15:15:56 -07:00

81 lines
2.3 KiB
JavaScript

/*jshint node:true */
"use strict";
var minimalDesc = ['h', 'min', 's', 'ms', 'μs', 'ns'];
var verboseDesc = ['hour', 'minute', 'second', 'millisecond', 'microsecond', 'nanosecond'];
var convert = [60*60, 60, 1, 1e6, 1e3, 1];
module.exports = function (source, opts) {
var verbose, precise, i, spot, sourceAtStep, valAtStep, decimals, strAtStep, results, totalSeconds;
verbose = false;
precise = false;
if (opts) {
verbose = opts.verbose || false;
precise = opts.precise || false;
}
if (!Array.isArray(source) || source.length !== 2) {
return '';
}
if (typeof source[0] !== 'number' || typeof source[1] !== 'number') {
return '';
}
// normalize source array due to changes in node v5.4+
if (source[1] < 0) {
totalSeconds = source[0] + source[1] / 1e9;
source[0] = parseInt(totalSeconds);
source[1] = parseFloat((totalSeconds % 1).toPrecision(9)) * 1e9;
}
results = '';
// foreach unit
for (i = 0; i < 6; i++) {
spot = i < 3 ? 0 : 1; // grabbing first or second spot in source array
sourceAtStep = source[spot];
if (i !== 3 && i !== 0) {
sourceAtStep = sourceAtStep % convert[i-1]; // trim off previous portions
}
if (i === 2) {
sourceAtStep += source[1]/1e9; // get partial seconds from other portion of the array
}
valAtStep = sourceAtStep / convert[i]; // val at this unit
if (valAtStep >= 1) {
if (verbose) {
valAtStep = Math.floor(valAtStep); // deal in whole units, subsequent laps will get the decimal portion
}
if (!precise) {
// don't fling too many decimals
decimals = valAtStep >= 10 ? 0 : 2;
strAtStep = valAtStep.toFixed(decimals);
} else {
strAtStep = valAtStep.toString();
}
if (strAtStep.indexOf('.') > -1 && strAtStep[strAtStep.length-1] === '0') {
strAtStep = strAtStep.replace(/\.?0+$/,''); // remove trailing zeros
}
if (results) {
results += ' '; // append space if we have a previous value
}
results += strAtStep; // append the value
// append units
if (verbose) {
results += ' '+verboseDesc[i];
if (strAtStep !== '1') {
results += 's';
}
} else {
results += ' '+minimalDesc[i];
}
if (!verbose) {
break; // verbose gets as many groups as necessary, the rest get only one
}
}
}
return results;
};