Socket
Book a DemoInstallSign in
Socket

@onigoetz/intl-formatters

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@onigoetz/intl-formatters

This package provides simple implementations for Messageformat using the Intl API.

1.0.0-rc.2
latest
npmnpm
Version published
Maintainers
0
Created
Source

This package provides simple implementations for Messageformat using the Intl API.

Features

How to use

These formatters are best used in conjunction with @onigoetz/messageformat. However they are fully Typed and you may use them for any other use.

import { parse, createRenderer } from "@onigoetz/messageformat";
import {
  dateFormatter,
  numberFormatter,
  pluralGenerator,
} from "@onigoetz/intl-formatters";

// Parse the MessageFormat to a renderable format
const parsed = parse("{test, plural, offset:3 one{one test} other {# test} }");

// Create a localized renderer
const render = createRenderer(
  "en",
  (locale: T, type) => pluralGenerator(locale, { type }),
  (locale: T, options, value: number) =>
    numberFormatter(locale, options)(value),
  (locale: T, options, value: Date) => dateFormatter(locale, options)(value)
);

render(parsed, { test: 4 }); // => "one test"
render(parsed, { test: 7 }); // => "4 test"

For NodeJS

If you do some generation using NodeJS and wish to use locales other than en. I strongly suggest you look at the following page : https://nodejs.org/api/intl.html#intl_providing_icu_data_at_runtime This page explains how to make sure you have all the right locales loaded to make your formatting.

Browser Support

Intl Base API (Dates, Numbers, Currencies, Relative Time)

'Can I use' table

Plurals

'Can I use' table

FAQs

Package last updated on 11 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.