1.0.4 • Published 2 years ago

ascii-lookup v1.0.4

Weekly downloads
43
License
MIT
Repository
github
Last release
2 years ago

ascii-lookup

Get ASCII characters, html codes, hex codes, and decimal codes for different encodings via decimal code or hex code.

GitHub release Travis tests codecov Codacy Badge

Install

You can install via npm or yarn.

npm

npm install --save ascii-lookup

yarn

yarn add ascii-lookup

Usage

Importing

You can import using ES6 imports. There are two methods: getASCIIItemForDecimal which will return ASCII info by a given decimal, and getASCIIItemForHex which will return ASCII info by a given hex code.

import { getASCIIItemForDecimal, getASCIIItemForHex } from 'ascii-lookup';

Arguments

getASCIIItemForDecimal accepts two arguments:

ParameterTypeOptionalDescription
decnumberfalseThe ASCII decimal value
encodingstring (ASCIIEncoding enum in Typescript)trueThe type of encoding for the extended ASCII set - Default is UTF8

getASCIIItemForHex also accepts two arguments:

ParameterTypeOptionalDescription
hexstringfalseThe ASCII hex value
encodingstring (ASCIIEncoding enum in Typescript)trueThe type of encoding for the extended ASCII set - Default is UTF8

Encodings

If you are using TypeScript you can import the ASCIIEncoding enum which will provide you with every supported encoding:

Example
import { getASCIIItemForDecimal, ASCIIEncoding } from 'ascii-lookup';

getASCIIItemForDecimal(128, ASCIIEncoding.CP437);

If you are using plain JavaScript the available encodings are:

EncodingNotes
cp437
utf-8Unicode
big5Chinese
ibm866Russian
euc-jpJapanese
euc-krKorean
gb18030Chinese
iso-8859-1Latin1/Western European
iso-8859-2Latin2/Eastern European
iso-8859-3Latin3/South European
iso-8859-4Latin4/North European
iso-8859-5Latin/Cyrillic
iso-8859-6Latin/Arabic
iso-8859-7Latin/Greek
iso-8859-8Latin/Hebrew
iso-8859-10Latin6/Nordic
iso-8859-13Latin7/Baltic Rim
iso-8859-14Latin8/Celtic
iso-8859-15Latin9/Western European
iso-8859-16Latin10/South-Eastern European
koi8-rRussian
koi8-uUkrainian
macintoshx-mac-roman
x-mac-cyrillic
shift_jisJapanese
windows-874Thai
windows-1250Eastern European
windows-1251Cyrillic
windows-1252Western European
windows-1253Greek
windows-1254Turkish
windows-1255Hebrew
windows-1256Arabic
windows-1257Baltic
windows-1258Vietnamese

Result

Both getASCIIItemForDecimal and getASCIIItemForHex return an object of type ASCIIItem:

KeyTypeDescription
decnumberDecimal code
hexstringHex code
htmlstringHTML code
charstringCharacter

A type for ASCIIItem is available for import in TypeScript:

import { getASCIIItemForDecimal, ASCIIEncoding, ASCIIItem } from 'ascii-lookup';

const result: ASCIIItem = getASCIIItemForDecimal(128, ASCIIEncoding.CP437);