Necrotizing Pineapple Music

    @dnvgl/i18n
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.0 • Public • Published

    General information

    @dnvgl/i18n is a set of functions to support multiple languages/cultures in a browser. There is no dependency on other libraries (exception: TypeScript when using definitions). It's built on the browsers 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).

    1. Supported 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().

    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 formattedNumber = formatNumber(12486.4529, { maxPrecision: 2 }, "de-DE"); // returns "12.486,45"
    const localformattedNumber = 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)"
      ]
    }

    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(), formatMoney(), formatNumber(), formatNumberToFixed(), parseNumber(), transformToInputNumericString(), roundUsingBankersMethod()

    Datetime formatting

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

    Sorting/comparison

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

    String formating/utils

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

    Country utils

    findIso3166Country(), getIso3166Countries(), isEuropeanUnionMember(), isValidIso3166Code()

    Others

    formatIban(), getDecimalSeparator(), getMinusSign(), getSystemLocaleName(), getThousandsSeparator(), isBrowserCompatible()

    6. Changelog

    See the CHANGELOG.md file.

    Install

    npm i @dnvgl/i18n

    DownloadsWeekly Downloads

    15

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    97.8 kB

    Total Files

    152

    Last publish

    Collaborators

    • krykar
    • zile.zealo.xu
    • tomrudnv
    • pamjoslyn
    • arkchr
    • foongsheeken
    • veracitydev
    • lindblad
    • mikkels611
    • maxkow
    • yuxinbo
    • yzb
    • espenskaufel
    • grigr
    • bikash021
    • powergrid
    • oystein.bjorke