How to use the intl-format-cache.default function in intl-format-cache

To help you get started, we’ve selected a few intl-format-cache examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github stelace / stelace / plugins / email / util / i18n.js View on Github external
}

  const customFormats = {}
  if (numberFormat) {
    customFormats.number = numberFormat
  }

  let additionalOptions

  if (timezone) {
    // https://github.com/formatjs/formatjs/tree/master/packages/intl-messageformat#formatters
    // customize formatters to be able to render dates to a specific timezone
    additionalOptions = {
      formatters: {
        getNumberFormat: memoizeIntlConstructor(Intl.NumberFormat),
        getPluralRules: memoizeIntlConstructor(Intl.PluralRules),

        getDateTimeFormat (locales, intlOptions) {
          return {
            format (date) {
              if (!(date instanceof Date)) throw new Error('Invalid valid date passed to format')

              const zone = momentTimezone.tz.zone(timezone)
              if (!zone) throw new Error('Invalid timezone')

              const clonedDate = new Date(date.getTime())
              const fromOffset = clonedDate.getTimezoneOffset()
              const toOffset = zone.parse(clonedDate)

              const newDate = new Date(clonedDate.getTime() - (toOffset - fromOffset) * 60 * 1000)
              return new Intl.DateTimeFormat(locales, intlOptions).format(newDate)
            }
github stelace / stelace / plugins / email / util / i18n.js View on Github external
}
  }

  const customFormats = {}
  if (numberFormat) {
    customFormats.number = numberFormat
  }

  let additionalOptions

  if (timezone) {
    // https://github.com/formatjs/formatjs/tree/master/packages/intl-messageformat#formatters
    // customize formatters to be able to render dates to a specific timezone
    additionalOptions = {
      formatters: {
        getNumberFormat: memoizeIntlConstructor(Intl.NumberFormat),
        getPluralRules: memoizeIntlConstructor(Intl.PluralRules),

        getDateTimeFormat (locales, intlOptions) {
          return {
            format (date) {
              if (!(date instanceof Date)) throw new Error('Invalid valid date passed to format')

              const zone = momentTimezone.tz.zone(timezone)
              if (!zone) throw new Error('Invalid timezone')

              const clonedDate = new Date(date.getTime())
              const fromOffset = clonedDate.getTimezoneOffset()
              const toOffset = zone.parse(clonedDate)

              const newDate = new Date(clonedDate.getTime() - (toOffset - fromOffset) * 60 * 1000)
              return new Intl.DateTimeFormat(locales, intlOptions).format(newDate)
github rsamec / react-pathjs-chart / app.js View on Github external
} else if (defaults.hasOwnProperty(name)) {
                    opts[name] = defaults[name];
                }

                return opts;
            }, {});
        }
    },

    propTypes        : typesSpec,
    contextTypes     : typesSpec,
    childContextTypes: typesSpec,

    getNumberFormat  : intl$format$cache$$["default"](Intl.NumberFormat),
    getDateTimeFormat: intl$format$cache$$["default"](Intl.DateTimeFormat),
    getMessageFormat : intl$format$cache$$["default"](intl$messageformat$$["default"]),
    getRelativeFormat: intl$format$cache$$["default"](intl$relativeformat$$["default"]),

    getChildContext: function () {
        var context = this.context;
        var props   = this.props;

        return {
            locales:  props.locales  || context.locales,
            formats:  props.formats  || context.formats,
            messages: props.messages || context.messages
        };
    },

    formatDate: function (date, options) {
        date = new Date(date);
        assertIsDate(date, 'A date or timestamp must be provided to formatDate()');
github onap / sdc / openecomp-ui / src / nfvo-utils / i18n / i18n.js View on Github external
* or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */
import IntlObj from 'intl';
import IntlMessageFormatObj from 'intl-messageformat';
import IntlRelativeFormatObj from 'intl-relativeformat';
import createFormatCacheObj from 'intl-format-cache';
import i18nJson from 'i18nJson';
/*
 Intl libs are using out dated transpailer from ecmascript6.
 *  TODO: As soon as they fix it, remove this assignments!!!
 * */
var Intl = window.Intl || IntlObj.default,
    IntlMessageFormat = IntlMessageFormatObj.default,
    IntlRelativeFormat = IntlRelativeFormatObj.default,
    createFormatCache = createFormatCacheObj.default;

/*extract locale*/
var _locale = window.localStorage && localStorage.getItem('user_locale');
if (!_locale) {
    if (window.navigator) {
        _locale = navigator.language || navigator.userLanguage;

        //For now removing the dashes from the language.
        let indexOfDash = _locale.indexOf('-');
        if (-1 !== indexOfDash) {
            _locale = _locale.substr(0, indexOfDash);
        }
    }
    if (!_locale) {
        _locale = 'en';
    }
github rsamec / react-pathjs-chart / app.js View on Github external
if (obj.hasOwnProperty(name)) {
                    opts[name] = obj[name];
                } else if (defaults.hasOwnProperty(name)) {
                    opts[name] = defaults[name];
                }

                return opts;
            }, {});
        }
    },

    propTypes        : typesSpec,
    contextTypes     : typesSpec,
    childContextTypes: typesSpec,

    getNumberFormat  : intl$format$cache$$["default"](Intl.NumberFormat),
    getDateTimeFormat: intl$format$cache$$["default"](Intl.DateTimeFormat),
    getMessageFormat : intl$format$cache$$["default"](intl$messageformat$$["default"]),
    getRelativeFormat: intl$format$cache$$["default"](intl$relativeformat$$["default"]),

    getChildContext: function () {
        var context = this.context;
        var props   = this.props;

        return {
            locales:  props.locales  || context.locales,
            formats:  props.formats  || context.formats,
            messages: props.messages || context.messages
        };
    },

    formatDate: function (date, options) {
github rsamec / react-pathjs-chart / app.js View on Github external
opts[name] = obj[name];
                } else if (defaults.hasOwnProperty(name)) {
                    opts[name] = defaults[name];
                }

                return opts;
            }, {});
        }
    },

    propTypes        : typesSpec,
    contextTypes     : typesSpec,
    childContextTypes: typesSpec,

    getNumberFormat  : intl$format$cache$$["default"](Intl.NumberFormat),
    getDateTimeFormat: intl$format$cache$$["default"](Intl.DateTimeFormat),
    getMessageFormat : intl$format$cache$$["default"](intl$messageformat$$["default"]),
    getRelativeFormat: intl$format$cache$$["default"](intl$relativeformat$$["default"]),

    getChildContext: function () {
        var context = this.context;
        var props   = this.props;

        return {
            locales:  props.locales  || context.locales,
            formats:  props.formats  || context.formats,
            messages: props.messages || context.messages
        };
    },

    formatDate: function (date, options) {
        date = new Date(date);
github rsamec / react-pathjs-chart / app.js View on Github external
opts[name] = defaults[name];
                }

                return opts;
            }, {});
        }
    },

    propTypes        : typesSpec,
    contextTypes     : typesSpec,
    childContextTypes: typesSpec,

    getNumberFormat  : intl$format$cache$$["default"](Intl.NumberFormat),
    getDateTimeFormat: intl$format$cache$$["default"](Intl.DateTimeFormat),
    getMessageFormat : intl$format$cache$$["default"](intl$messageformat$$["default"]),
    getRelativeFormat: intl$format$cache$$["default"](intl$relativeformat$$["default"]),

    getChildContext: function () {
        var context = this.context;
        var props   = this.props;

        return {
            locales:  props.locales  || context.locales,
            formats:  props.formats  || context.formats,
            messages: props.messages || context.messages
        };
    },

    formatDate: function (date, options) {
        date = new Date(date);
        assertIsDate(date, 'A date or timestamp must be provided to formatDate()');
        return this._format('date', date, options);

intl-format-cache

A memoizer factory for Intl format constructors.

BSD-3-Clause
Latest version published 4 years ago

Package Health Score

80 / 100
Full package analysis

Popular intl-format-cache functions