@ivanhanak_com/js-sort-unicode

1.2.0 • Public • Published

js-sort-unicode

NPM Weekly Downloads

This package includes a sorting function for arrays, that will sort the array containing utf8 characters.

Changelog

See the whole Changelog.

Browser support

Uses Intl.Collator API. More information here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator.

IE 11+, Chromoe 24+, Edge 12+, Firefox 29+, Opera 15+, Safari 10+

Install

Using npm:

npm install @ivanhanak_com/js-sort-unicode

Using yarn:

yarn add @ivanhanak_com/js-sort-unicode

Import

import unicodeSort from '@ivanhanak_com/js-sort-unicode';

Usage

const myArray = ["äpples", "xerox", "pear", "grapes", "ônions"];
myArray.sort(unicodeSort);
//modifies the array to be ["äpples", "grapes", "ônions", "pear", "xerox"]

Usage with multi-dimensional array

const users = [
    {
        name: "Ábel Horák",
    },
    {
        name: "Peter McCalister"
    },
    {
        name: "Gabriel Roth"
    },
    {
        name: "Čávo Malík"
    },
];

users.sort((a, b) => (
   //use the 3rd param, that is a key of an inside object
   unicodeSort(a, b, "name")
));

Package Sidebar

Install

npm i @ivanhanak_com/js-sort-unicode

Weekly Downloads

0

Version

1.2.0

License

https://www.imdb.com/title/tt0097742/

Unpacked Size

4.62 kB

Total Files

8

Last publish

Collaborators

  • ivanhanak_com