Giter VIP home page Giter VIP logo

angular-ecmascript-intl's Introduction

Angular ECMAScript Intl

codecov

Contains pipes to transform internationalization data using Intl.* browser APIs.

Getting started

Install the package:

npm install angular-ecmascript-intl --save

Import the pipes individually as per usage, or import the IntlModule to import all pipes at once.

By default, all pipes will use the browser default locale. If you want to override it, you can provide the INTL_LOCALES injection token:

import { NgModule } from "@angular/core";
import { INTL_LOCALES } from "angular-ecmascript-intl";

@NgModule({
  providers: [
    {
      provide: INTL_LOCALES,
      useValue: "de-DE",
    },
  ],
})
export class MyModule {}

Also, every pipe accepts the locale option.

Now you can use the pipes, see below.

Pipes

Date pipe

Use the date pipe like the following:

{{myDate | intlDate: options}}

The input date can be one of the following:

  • Date object
  • number (UNIX timestamp)
  • string (will be parsed by new Date() constructor)
  • null
  • undefined

The following options are supported:

With the INTL_DATE_PIPE_DEFAULT_OPTIONS injection token you can specify default options.

Decimal pipe

Use the decimal pipe like the following:

{{1.24 | intlDecimal: options}}

The input can be one of the following:

  • number
  • string (must be parseable as number)
  • null
  • undefined

The following options are supported:

With the INTL_DECIMAL_PIPE_DEFAULT_OPTIONS injection token you can specify default options.

Percent pipe

Use the percent pipe like the following:

{{0.24 | intlPercent: options}}

The input can be one of the following:

  • number
  • string (must be parseable as number)
  • null
  • undefined

The following options are supported:

With the INTL_PERCENT_PIPE_DEFAULT_OPTIONS injection token you can specify default options.

Currency pipe

Use the currency pipe like the following:

{{1.24 | intlCurrency: 'USD': options}}

The input can be one of the following:

  • number
  • string (must be parseable as number)
  • null
  • undefined

The currency code parameter is required and must be a valid ISO 4217 currency code. If you want to transform a decimal number instead, use the intlDecimal pipe.

The following additional options are supported:

With the INTL_CURRENCY_PIPE_DEFAULT_OPTIONS injection token you can specify default options.

Language pipe

Use the language pipe like the following:

{{'en-US' | intlLanguage: options}}

The input can be one of the following:

  • string (must be a BCP 47 IETF language tag)
  • null
  • undefined

The following option is supported:

With the INTL_LANGUAGE_PIPE_DEFAULT_OPTIONS injection token you can specify default options.

Country pipe

Use the country pipe like the following:

{{'US' | intlCountry: options}}

The input can be one of the following:

  • string (must be two-letter ISO 639-1 language code or a three-letter ISO 639-2 language code)
  • null
  • undefined

Unit pipe

Use the unit pipe like the following:

{{1.2 | intlUnit: 'hour': options}}

The input can be one of the following:

  • number
  • string (must be parseable as number)
  • null
  • undefined

The unit parameter is required, see the specification for a full list of possible values. If you want to transform a decimal number instead, use the intlDecimal pipe.

The following additional options are supported:

With the INTL_UNIT_PIPE_DEFAULT_OPTIONS injection token you can specify default options.

List pipe

Use the list pipe like the following:

{{['my', 'items'] | intlList: options}}

The input can be one of the following:

  • Iterable of strings
  • null
  • undefined

The following options are supported:

With the INTL_LIST_PIPE_DEFAULT_OPTIONS injection token you can specify default options.

Relative Time (timeago) pipe

The relative time format will format the input date compared to the current date in a "timeago" format. Every minute, the value will be updated automatically.

Use the relative time pipe like the following:

{{myDate | intlRelativeTime: options}}

The input date can be one of the following:

  • Date object
  • number (UNIX timestamp)
  • string (will be parsed by new Date() constructor)
  • null
  • undefined

The following options are supported:

With the INTL_RELATIVE_TIME_PIPE_DEFAULT_OPTIONS injection token you can specify default options.

Browser compatibility

This library supports the latest major version of the following browsers:

  • Chrome
  • Firefox
  • Safari

For each of those browsers, unit tests are being performed regularly.

In case you need to support older versions of that browsers, see the below table with the minimum required browser version for each pipe:

Pipe Chrome Firefox Safari
Date 24 29 10
Number 24 29 10
Percent 24 29 10
Currency 24 29 10
Language 81 86 14.1
Country 81 86 14.1
Unit 77 78 14.1
List 72 78 14.1
Relative Time 71 65 14

Angular compatibility table

Angular angular-ecmascript-intl
17 3.x
16 2.x
15 1.x

Background

For more context, see the following GitHub issue

angular-ecmascript-intl's People

Contributors

json-derulo avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

ecanavesio

angular-ecmascript-intl's Issues

Offer TypeScript format functions

Description
Angular offers TypeScript functions to make the logic of their i18n pipes available also in TypeScript code, i.e. the formatDate() function. It would be useful to have such functions available also for the pipes in this package.

Proposed Solution
For each pipe, there is a TypeScript function exposed, which performs the base logic of the pipe, i.e. intlFormatDate().

Alternatives considered
There might be workarounds like constructing or injecting the pipe, but this is not good practice and could cause issues.

Angular v16

Angular v16 released about a month ago. Could you please update the lib accordingly?

Missing export of INTL_RELATIVE_TIME_PIPE_DEFAULT_OPTIONS in "angular-ecmascript-intl"

When trying to inject INTL_RELATIVE_TIME_PIPE_DEFAULT_OPTIONS token in App Module providers.

Output:
Error: Module not found: Error: Package path ./lib/relative-time/relative-time-pipe-default-options is not exported from package /home/addiel/Documents/Proyectos/plaza_frontend/node_modules/angular-ecmascript-intl (see exports field in /home/addiel/Documents/Proyectos/plaza_frontend/node_modules/angular-ecmascript-intl/package.json)

Screenshot from 2024-04-09 15-15-14

export should be below export * from './lib/relative-time/relative-time.pipe';

My Angular's version is 17.3.3 and Angular Intl latest 3.0.0

New duration pipe

Description

Developers may want to display localized durations to the user.

Proposed Solution

Add a duration pipe based on the Intl.DurationFormat browser API

Alternatives considered

none

Additional context

Currently only supported by Safari, need to wait for Chrome and Firefox support

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • chore(deps): lock file maintenance

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/build-and-deploy.yml
  • actions/checkout v4
  • JamesIves/github-pages-deploy-action v4
  • actions/checkout v4
  • codecov/codecov-action v4
.github/workflows/verify-build.yml
  • actions/checkout v4
  • actions/checkout v4
  • actions/checkout v4
  • codecov/codecov-action v4
  • actions/checkout v4
  • actions/checkout v4
  • actions/checkout v4
  • macos 14
npm
package.json
  • @angular/animations ~17.3.0
  • @angular/cdk ~17.3.0
  • @angular/common ~17.3.0
  • @angular/compiler ~17.3.0
  • @angular/core ~17.3.0
  • @angular/forms ~17.3.0
  • @angular/material ~17.3.0
  • @angular/material-experimental ~17.3.0
  • @angular/platform-browser ~17.3.0
  • @angular/platform-browser-dynamic ~17.3.0
  • @angular/router ~17.3.0
  • marked ^12.0.0
  • ngx-markdown ^17.0.0
  • prismjs ^1.29.0
  • rxjs ~7.8.0
  • tslib ^2.3.0
  • zone.js ~0.14.2
  • @angular-devkit/build-angular ~17.3.0
  • @angular-eslint/builder ^17.0.0
  • @angular-eslint/eslint-plugin ^17.0.0
  • @angular-eslint/eslint-plugin-template ^17.0.0
  • @angular-eslint/schematics ^17.0.0
  • @angular-eslint/template-parser ^17.0.0
  • @angular/cli ~17.3.0
  • @angular/compiler-cli ~17.3.0
  • @eslint/js ^9.2.0
  • @types/jasmine ~5.1.0
  • cpy-cli ^5.0.0
  • dayjs ^1.11.7
  • eslint ^8.53.0
  • eslint-config-prettier ^9.0.0
  • eslint-plugin-deprecation ^2.0.0
  • globals ^15.1.0
  • jasmine-core ~5.1.0
  • karma ~6.4.0
  • karma-chrome-launcher ~3.2.0
  • karma-coverage ~2.2.0
  • karma-firefox-launcher ^2.1.2
  • karma-jasmine ~5.1.0
  • karma-jasmine-html-reporter ~2.1.0
  • karma-safarinative-launcher ^1.1.0
  • ng-packagr ~17.3.0
  • prettier ~3.2.0
  • prettier-plugin-organize-imports ^3.2.3
  • typescript ~5.4.0
  • typescript-eslint ^7.0.0
projects/angular-ecmascript-intl/package.json
  • tslib ^2.3.0
  • @angular/common >=17
  • @angular/core >=17

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.