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

META-INF.resources.bower_components.globalize.dist.globalize-runtime.message.js Maven / Gradle / Ivy

There is a newer version: 1.2.2.1-jre17
Show newest version
/**
 * Globalize Runtime v1.2.3
 *
 * http://github.com/jquery/globalize
 *
 * Copyright jQuery Foundation and other contributors
 * Released under the MIT license
 * http://jquery.org/license
 *
 * Date: 2017-03-17T01:41Z
 */
/*!
 * Globalize Runtime v1.2.3 2017-03-17T01:41Z Released under the MIT license
 * http://git.io/TrdQbw
 */
(function (root, factory) {

    // UMD returnExports
    if (typeof define === "function" && define.amd) {

        // AMD
        define([
            "../globalize-runtime"
        ], factory);
    } else if (typeof exports === "object") {

        // Node, CommonJS
        module.exports = factory(require("../globalize-runtime"));
    } else {

        // Extend global
        factory(root.Globalize);
    }
}(this, function (Globalize) {

    var runtimeKey = Globalize._runtimeKey,
        validateParameterType = Globalize._validateParameterType;


    /**
     * Function inspired by jQuery Core, but reduced to our use case.
     */
    var isPlainObject = function (obj) {
        return obj !== null && "" + obj === "[object Object]";
    };


    var validateParameterTypeMessageVariables = function (value, name) {
        validateParameterType(
            value,
            name,
            value === undefined || isPlainObject(value) || Array.isArray(value),
            "Array or Plain Object"
        );
    };


    var messageFormatterFn = function (formatter) {
        return function messageFormatter(variables) {
            if (typeof variables === "number" || typeof variables === "string") {
                variables = [].slice.call(arguments, 0);
            }
            validateParameterTypeMessageVariables(variables, "variables");
            return formatter(variables);
        };
    };


    Globalize._messageFormatterFn = messageFormatterFn;
    /* jshint ignore:start */
    Globalize._messageFormat = (function () {
        var number = function (value, offset) {
            if (isNaN(value)) throw new Error("'" + value + "' isn't a number.");
            return value - (offset || 0);
        };
        var plural = function (value, offset, lcfunc, data, isOrdinal) {
            if ({}.hasOwnProperty.call(data, value)) return data[value]();
            if (offset) value -= offset;
            var key = lcfunc(value, isOrdinal);
            if (key in data) return data[key]();
            return data.other();
        };
        var select = function (value, data) {
            if ({}.hasOwnProperty.call(data, value)) return data[value]();
            return data.other()
        };

        return {number: number, plural: plural, select: select};
    }());
    /* jshint ignore:end */
    Globalize._validateParameterTypeMessageVariables = validateParameterTypeMessageVariables;

    Globalize.messageFormatter =
        Globalize.prototype.messageFormatter = function (/* path */) {
            return Globalize[
                runtimeKey("messageFormatter", this._locale, [].slice.call(arguments, 0))
                ];
        };

    Globalize.formatMessage =
        Globalize.prototype.formatMessage = function (path /* , variables */) {
            return this.messageFormatter(path).apply({}, [].slice.call(arguments, 1));
        };

    return Globalize;


}));




© 2015 - 2024 Weber Informatics LLC | Privacy Policy