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

kanasort

v2.0.1

Published

Sort Japanese text.

Downloads

9

Readme

kanasort

Sort Japanese text.

npm Build Status Dependency Status devDependency Status node

Overview

This module was built in order to support sorting of strings containing Japanese text. It can't sort kanji though, ideally one should already have the corresponding readings at hand.

This module partially follows the specifications of JIS X 4061 as seen on Wikipedia.

The API is ready to use as-is, but is also fully customizable.

API

const kanasort = require('kanasort')

kanasort(arr: string[]) : string[]

Sorts the specified array in-place and returns the array using the default Japanese string comparison. (This is just a call to Array.prototype.sort.)

kanasort.compare(a: string, b: string)

A comparison function (comparefn) using the default Japanese string transforms that returns:

  • A negative value if a < b
  • A positive value if a > b
  • 0 if a = b.

Customizable API

For further customization, see the Customizable API.

CLI

Usage:

kanasort < input.txt > output.txt

Sorts standard input line by line.

Default transforms

The following are the transforms included by default (in order of processing):

  1. small to big kana (ぁ→あ)
  2. voiced to unvoiced (が→か)
  3. half-voiced to unvoiced (ぱ→は)
  4. katakana to hiragana (サ→さ)
  5. iteration mark variants (ヾ→ゝ)
  6. chōon to corresponding kana (かー→かあ)
  7. iteration mark application (こゝ→ここ)

In order, the weight priority of each:

  1. unvoiced < half-voiced
  2. unvoiced < voiced
  3. chōon to corresponding kana (reversed)
  4. small to big kana (reversed)
  5. iteration mark variants (reversed)
  6. iteration mark application (reversed)
  7. hiragana < katakana

Transformed matches are ordered first (and untransformed matches are ordered last) on transforms marked as 'reversed'.

Todo

JSDoc all of this so we don't have to scratch our heads.

License

MIT

See also

Thanks to minodisk/sorter for supporting my private hobby project sorting needs and for being the inspiration for this module.