npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@dnvgl/i18n

v1.16.1

Published

A set of functions to support multiple languages/cultures in a browser or Node.js

Downloads

1,167

Readme

General information

@dnvgl/i18n is a set of functions to support multiple languages/cultures in a browser or Node.js. There is no dependency on other libraries (exception: TypeScript when using definitions). It's built on the ECMAScript native solutions like for example Intl API.

The purpose of this library is to provide all needed functionalities to support multiple languages/cultures in the web application. All functions have been designed to be simple and easy to use, that is why some native API are wrapped. This library was in use two years (commercial use by DNV company) before its open-source release (2021-04-13).

The biggest advantage about the library is that it supports any language, using the culture of the browser.

1. Supported environments

Browsers:

  • Chrome (+ mobile): last 2 versions
  • Firefox (+ mobile): last 2 versions
  • Safari (+ mobile): v14* or newer
  • Edge: last 2 versions

There is a build-in function to check it: isBrowserCompatible().

* - formatCountry() and formatCurrency() require Safari 14.1 (desktop) or 14.5 (mobile)

Node.js:

  • v14 or newer

2. Installation

Using npm:

npm install @dnvgl/i18n

Using yarn:

yarn add @dnvgl/i18n

3. Usage

Import functions or types from @dnvgl/i18n, example:

import { sort, formatNumber } from '@dnvgl/i18n';

const sortedItems = sort(["Z", "a", "A", "z", "ś"], "asc", "pl-PL"); // returns ["a", "A", "ś", "z", "Z"]
const numberFormattedInSpecificCulture = formatNumber(12486.4529, { maxPrecision: 2 }, "de-DE"); // returns "12.486,45"
const numberFormattedInLocalCulture = formatNumber(12486.4529); // returns "12 486,4529" using local browser culture (in this case 'pl-PL'); any culture can be supported out of the box

Module system

Library supports esm modules tree shaking by default.

Testing in Jest

Jest does not support esm modules, and @dnvgl/i18n uses them. In order to test your application with Jest you have to add the following to your package.json:

"jest": {
  "transformIgnorePatterns": [
    "/node_modules/(?!@dnvgl/i18n)"
  ]
}

When there is another package that requires ES6 only then the pattern is:
"/node_modules/(?!(PACKAGE_1|PACKAGE_2))", e.g. "/node_modules/(?!(@dnvgl/i18n|another-package))"

TypeScript

Library provides a built-in ts definition.

4. Contributing

See the CONTRIBUTING.md file.

5. Documentation

See full details in the DOCUMENTATION.md file.

Number formatting/parsing/utils

formatInteger(), formatNumber(), formatNumberToFixed(), parseNumber(), transformToInputNumericString(), roundUsingHalfAwayFromZero(), getDecimalSeparator(), getMinusSign(), getThousandsSeparator(), createNumberFormat()

Datetime formatting

formatDate(), formatDatePart(), formatDateToISO(), formatRelativeTime(), formatMonth(), formatTime(), getDateFnsFormat(), getDayJsFormat(), getMomentFormat()

Sorting/comparison

compareBooleans(), compareDates(), compareNumbers(), compareNumbersAlike(), compareStrings(), compareStringsFactory(), sort(), sortBy(), sortByInplace(), sortInplace()

String formatting/utils

capitalizeFirstLetter(), formatString(), lowercaseFirstLetter(), normalizeForSearching(), plural()

Country utils

findIso3166Country(), formatCountry(), getIso3166Countries(), getStatesOfUsa(), isEuropeanUnionMember(), isValidIso3166Code()

Currency utils

findIso4217Currency(), findIso4217CurrencyForIso3166Country(), formatCurrency(), getIso4217Currencies(), getCurrencySymbol(), isValidIso4217Code()

Financial utils

formatMoney(), formatIban(), getCountryCodeFromBic(), getCountryCodeFromIban(), roundUsingBankersMethod()

Others

getSystemLocaleName(), isBrowserCompatible()

6. Changelog

See the CHANGELOG.md file.