1.2.0 • Published 4 years ago

@ivanhanak_com/js-sort-unicode v1.2.0

Weekly downloads
-
License
https://www.imdb....
Repository
github
Last release
4 years ago

js-sort-unicode

npm.io 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")
));