Source: polyfill/Intl/Format.js

// Licensed Materials - Property of IBM
//
// IBM Watson Analytics
//
// (C) Copyright IBM Corp. 2018
//
// US Government Users Restricted Rights - Use, duplication or
// disclosure restricted by GSA ADP Schedule Contract with IBM Corp.

module.exports = ( function( ObjectPolyfill, bcp47 )
{
"use strict";
/*global navigator*/

/**
 * These classes are NOT a polyfill, and are not meant to be!
 * They provide a poor man's fallback for the Intl formatters, for non-compliant environments.
 */

var LOCALE = ( function( navigator )
{
    try
    {
        return bcp47.getCanonicalLocales( ( navigator && ( navigator.language || navigator.userLanguage ) ) || "en-US" )[ 0 ];
    }
    catch ( ex )
    {
        return "en-US";
    }
}( typeof navigator !== "undefined" ? navigator : null ) );


/**
 * Base class for objects that perform formatting based on locale and options
 * @class module:barejs/polyfill/Intl~Format
 * @param _locales
 * @param _options
 */
function Format( _locales, _options )
{
    // We can't accept custom locales since we don't polyfill any culture data.
    // Always format using the environment locale(!)
    ObjectPolyfill.defineProperties( this,
    {
        _locale: { value: LOCALE },
        _options: { value: _options }
    } );
}

ObjectPolyfill.defineProperties( Format.prototype,
/** @lends module:barejs/polyfill/Intl~Format# */
{
    _locale: { value: null },
    _options: { value: null },

    /**
     * Get the resolvedOptions
     * @function
     * @return {Object} The options
     */
    resolvedOptions:
    {
        value: function resolvedOptions()
        {
            // Create a new object with a locale on it, and copy the options to it.
            return Object.assign( { locale: this._locale }, this._options );
        }
    },

    /**
     * Format a value
     * @param {any} _value
     * @return {String} The formatted value.
     */
    format:
    {
        enumerable: true,
        value: function( _value )
        {
            return _value ? _value.toLocaleString() : "";
        }
    }
} );

return ObjectPolyfill.defineProperty( Format, "envLocale", { value: LOCALE } );

}( require( "../Object" ), require( "./bcp47" ) ) );