MCPcopy Create free account
hub / github.com/facebook/Rapid / displayLength

Method displayLength

modules/core/LocalizationSystem.js:711–735  ·  view source on GitHub ↗

* Returns a localized representation of the given length measurement. * @param {Number} meters * @param {Boolean} isImperial true for U.S. customary units; false for metric * @return {string} Text to display

(meters, isImperial)

Source from the content-addressed store, hash-verified

709 * @return {string} Text to display
710 */
711 displayLength(meters, isImperial) {
712 const locale = this._currLocaleCode;
713 let n = meters * (isImperial ? 3.28084 : 1);
714 let unit;
715
716 if (isImperial) {
717 if (n >= 5280) {
718 n /= 5280;
719 unit = 'miles';
720 } else {
721 unit = 'feet';
722 }
723 } else {
724 if (n >= 1000) {
725 n /= 1000;
726 unit = 'kilometers';
727 } else {
728 unit = 'meters';
729 }
730 }
731
732 return this.t(`units.${unit}`, {
733 quantity: n.toLocaleString(locale, { maximumSignificantDigits: 4 })
734 });
735 }
736
737
738 /**

Callers 2

updateScaleMethod · 0.80
renderMethod · 0.80

Calls 1

tMethod · 0.95

Tested by

no test coverage detected