All Downloads are FREE. Search and download functionalities are using the official Maven repository.

META-INF.resources.bower_components.globalize.src.unit.js Maven / Gradle / Ivy

There is a newer version: 0.66.0.1
Show newest version
define([
    "./core",
    "./common/runtime-bind",
    "./common/validate/parameter-presence",
    "./common/validate/parameter-type/number",
    "./common/validate/parameter-type/plain-object",
    "./common/validate/parameter-type/string",
    "./unit/formatter-fn",
    "./unit/properties",

    "./number",
    "./plural"
], function (Globalize, runtimeBind, validateParameterPresence, validateParameterTypeNumber,
             validateParameterTypePlainObject, validateParameterTypeString, unitFormatterFn,
             unitProperties) {

    /**
     * Globalize.formatUnit( value, unit, options )
     *
     * @value [Number]
     *
     * @unit [String]: The unit (e.g "second", "day", "year")
     *
     * @options [Object]
     * - form: [String] "long", "short" (default), or "narrow".
     *
     * Format units such as seconds, minutes, days, weeks, etc.
     */
    Globalize.formatUnit =
        Globalize.prototype.formatUnit = function (value, unit, options) {
            validateParameterPresence(value, "value");
            validateParameterTypeNumber(value, "value");

            return this.unitFormatter(unit, options)(value);
        };

    /**
     * Globalize.unitFormatter( unit, options )
     *
     * @unit [String]: The unit (e.g "second", "day", "year")
     *
     * @options [Object]
     * - form: [String] "long", "short" (default), or "narrow".
     *
     * - numberFormatter: [Function] a number formatter function. Defaults to Globalize
     *   `.numberFormatter()` for the current locale using the default options.
     */
    Globalize.unitFormatter =
        Globalize.prototype.unitFormatter = function (unit, options) {
            var args, form, numberFormatter, pluralGenerator, returnFn, properties;

            validateParameterPresence(unit, "unit");
            validateParameterTypeString(unit, "unit");

            validateParameterTypePlainObject(options, "options");

            options = options || {};

            args = [unit, options];
            form = options.form || "long";
            properties = unitProperties(unit, form, this.cldr);

            numberFormatter = options.numberFormatter || this.numberFormatter();
            pluralGenerator = this.pluralGenerator();
            returnFn = unitFormatterFn(numberFormatter, pluralGenerator, properties);

            runtimeBind(args, this.cldr, returnFn, [numberFormatter, pluralGenerator, properties]);

            return returnFn;
        };

    return Globalize;

});




© 2015 - 2024 Weber Informatics LLC | Privacy Policy