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

@mmnaii/jisx0208

v1.1.0

Published

A library for conversion about the row-cell of JIS X 0208

Downloads

16

Readme

jisx0208

Description

jisx0208 provides methods about the row-cell defined by the JIS X 0208.

Requirements

Install

npm install @mmnaii/jisx0208

Examples

  • To convert a row-cell to the corresponding code of Shift_JIS:
import {rowCellToSjis} from '@mmnaii/jisx0208';

// {16, 1}, [0x88, 0x9F](Shift_JIS) : "亜"
rowCellToSjis(16, 1);// [136, 159] ([0x88, 0x9F])
  • To convert a code of EUC-JP to the corresponding row-cell:
import {eucjpToRowCell} from '@mmnaii/jisx0208';

// {84, 6}, [0xF4, 0xA6](EUC-JP) : "熙"
eucjpToRowCell(0xF4, 0xA6);// [84, 6]

Encoding

An assignment of characters to row-cells of the JIS X 0208 follows the edition 1997.

As the encoding scheme to and from which a row-cell is converted, EUC-JP and Shift_JIS are supported.

As far as a row-cell is in the range of {1, 1} to {94, 94}, the operation that is to convert a row-cell to a code of EUC-JP or Shift_JIS and to convert again the gotten code to a row-cell always results in the same original row-cell.

// Round-trip conversion

import {sjisToRowCell, rowCellToSjis, eucjpToRowCell, rowCellToEucjp} from '@mmnaii/jisx0208';

for (let row=1; row<=94; row++) {
	for (let cell=1; cell<=94; cell++) {
		assert.deepEqual([row, cell], sjisToRowCell(...rowCellToSjis(row, cell, true), true));
		assert.deepEqual([row, cell], eucjpToRowCell(...rowCellToEucjp(row, cell, true), true));
	}
}
// OK

API

jisx0208.isAssigned(row, cell)

  • row {Integer}
  • cell {Integer}
  • Returns: {Boolean}

Returns true if a character is defined at a row-cell {row, cell} by the JIS X 0208, false otherwise.

import {isAssigned} from '@mmnaii/jisx0208';

// {5, 2} : "ア"
isAssigned(5, 2);// true

// {13, 1} : "①", (CP932)
isAssigned(13, 1);// false

jisx0208.eucjpToRowCell(c1, c2, noAssert)

  • c1 {Integer} The code of the first byte of the character represented by the EUC-JP two bytes sequence
  • c2 {Integer} The code of the second byte of the character represented by the EUC-JP two bytes sequence
  • noAssert {Boolean} Skip assignment validation? Default: false
  • Returns: {Array|null}

Interpreting a two bytes sequence of codes [c1, c2] as a character represented by the EUC-JP, converts it to a row-cell of the JIS X 0208 and returns an array, of which length is 2, that contains the results in order of [row, cell]. Returns null if JIS X 0208 does not assigned a character at the converted row-cell.

A conversion from characters represented by using a single shift to row-cells is not supported.

Setting noAssert to true omits the validation whether a character is assigned at the converted row-cell. But if [c1, c2] cannot be converted to a row-cell in the range of {1, 1} to {94, 94}, returns null regardless the setting of noAssert.

The arguments c1 and c2 are converted to eight bit unsigned integers before the operation.

import {eucjpToRowCell} from '@mmnaii/jisx0208';

// [0xA5, 0xA2](EUC-JP) : "ア"
eucjpToRowCell(0xA5, 0xA2);// [5, 2]

// [0x8E, 0xB1](EUC-JP) : "ア" (HALFWIDTH KATAKANA LETTER A)
eucjpToRowCell(0x8E, 0xB1);// null
eucjpToRowCell(0x8E, 0xB1, true);// null

// [0xAD, 0xA1](EUC-JP) : Not Assigned
eucjpToRowCell(0xAD, 0xA1);// null
eucjpToRowCell(0xAD, 0xA1, true);// [13, 1]

jisx0208.sjisToRowCell(c1, c2, noAssert)

  • c1 {Integer} The code of the first byte of the character represented by the Shift_JIS two bytes sequence
  • c2 {Integer} The code of the second byte of the character represented by the Shift_JIS two bytes sequence
  • noAssert {Boolean} Skip assignment validation? Default: false
  • Returns: {Array|null}

Interpreting a two bytes sequence of codes [c1, c2] as a character represented by the Shift_JIS, converts it to a row-cell of the JIS X 0208 and returns an array, of which length is 2, that contains the results in order of [row, cell]. Returns null if JIS X 0208 does not assigned a character at the converted row-cell.

A conversion from characters included in the character set defined by the JIS X 0201 to row-cells is not supported.

Setting noAssert to true omits the validation whether a character is assigned at the converted row-cell. But if [c1, c2] cannot be converted to a row-cell in the range of {1, 1} to {94, 94}, returns null regardless the setting of noAssert.

The arguments c1 and c2 are converted to eight bit unsigned integers before the operation.

import {sjisToRowCell} from '@mmnaii/jisx0208';

// [0x83, 0x41](Shift_JIS) : "ア"
sjisToRowCell(0x83, 0x41);// [5, 2]

// [0xB1](EUC-JP) : "ア" (HALFWIDTH KATAKANA LETTER A)
sjisToRowCell(0xB1);// null

// [0x87, 0x40](CP932) : "①"
sjisToRowCell(0x87, 0x40);// null
sjisToRowCell(0x87, 0x40, true);// [13, 1]

jisx0208.rowCellToEucjp(row, cell, noAssert)

  • row {Integer}
  • cell {Integer}
  • noAssert {Boolean} Skip assignment validation? Default: false
  • Returns: {Array|null}

Encodes a character assigned at a row-cell {row, cell} in EUC-JP and returns the result, that is a two bytes sequence of codes [c1, c2], as an array, of which length is 2. Returns null if JIS X 0208 does not assigned a character at the converted row-cell.

Does not convert to characters represented by using a single shift.

Setting noAssert to true omits the validation whether a character is assigned at the row-cell {row, cell}. But if {row, cell} is not in the range of {1, 1} to {94, 94}, returns null regardless the setting of noAssert.

import {rowCellToEucjp} from '@mmnaii/jisx0208';

// {5, 2} : "ア"
rowCellToEucjp(5, 2);// [165, 162] ([0xA5, 0xA2])

// {13, 1} : "①", (CP932)
rowCellToEucjp(13, 1);// null
rowCellToEucjp(13, 1, true);// [173, 161] (0xAD, 0xA1)

jisx0208.rowCellToSjis(row, cell, noAssert)

  • row {Integer}
  • cell {Integer}
  • noAssert {Boolean} Skip assignment validation? Default: false
  • Returns: {Array|null}

Encodes a character assigned at a row-cell {row, cell} in Shift_JIS and returns the result, that is a two bytes sequence of codes [c1, c2], as an array, of which length is 2. Returns null if JIS X 0208 does not assigned a character at the converted row-cell.

Does not convert to characters included in the character set defined by the JIS X 0201.

Setting noAssert to true omits the validation whether a character is assigned at the row-cell {row, cell}. But if {row, cell} is not in the range of {1, 1} to {94, 94}, returns null regardless the setting of noAssert.

import {rowCellToSjis} from '@mmnaii/jisx0208';

// {5, 2} : "ア"
rowCellToSjis(5, 2);// [131, 65] ([0x83, 0x41])

// {13, 1} : "①", (CP932)
rowCellToSjis(13, 1);// null
rowCellToSjis(13, 1, true);// [135, 64] ([0x87, 0x40])

jisx0208.halfkanaToRowCell(code)

  • code {Integer}
  • Returns: {Array|null}

In the JIS X 0208 character set, finds a character corresponding to what the code represents by the eight bit code of the JIS X 0201, and returns the row-cell of the character as an array, of which length is 2, that contains the results in order of [row, cell].

But returns null if the code is not in the range where katakana graphic character set is assigned.

The argument code are converted to eight bit unsigned integers before the operation.

import {halfkanaToRowCell} from '@mmnaii/jisx0208';

// [0xB1](JIS X 0201(8bit), Shift_JIS) : "ア" (HALFWIDTH KATAKANA LETTER A)
halfkanaToRowCell(0xB1);// [5, 2]
// {5, 2} : "ア" (KATAKANA LETTER A)

// [0x40](JIS X 0201(8bit), Shift_JIS) ; "A"
halfkanaToRowCell(0x40);// null