https://github.com/thatisuday/utf-info
Get encoding information of a character in UTF-8, UTF-16 and UTF-32 encodings.
https://github.com/thatisuday/utf-info
decoder encoding encodings unicode utf utf-16 utf-32 utf-8
Last synced: over 1 year ago
JSON representation
Get encoding information of a character in UTF-8, UTF-16 and UTF-32 encodings.
- Host: GitHub
- URL: https://github.com/thatisuday/utf-info
- Owner: thatisuday
- License: mit
- Created: 2019-11-13T14:42:06.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-30T19:04:48.000Z (over 3 years ago)
- Last Synced: 2025-02-06T08:48:24.303Z (over 1 year ago)
- Topics: decoder, encoding, encodings, unicode, utf, utf-16, utf-32, utf-8
- Language: JavaScript
- Homepage:
- Size: 75.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# utf-info (Unicode Character Information)
Get encoding information of a character in UTF-8, UTF-16 and UTF-32 encodings.
[](https://www.npmjs.com/package/utf-info)
[](https://www.npmjs.com/package/utf-info)
[](https://www.npmjs.com/package/utf-info)
[](https://www.npmjs.com/package/utf-info)
## Install
```js
npm install -S utf-info
```
## Use
```js
const utfInfo = require( 'utf-info' );
// syntax:
utfInfo( character, encoding );
// character => single Unicode character (string)
// encoding => valid UTF encoding (string) viz. utf-8, utf-16, and utf-32
// examples:
const result = utfInfo( '๐' ); // character `๐`
// const result = utfInfo( '\x41', 'utf-8' ); // '\x41' is ASCII escape character `A`
// const result = utfInfo( '\u0906', 'utf-16' ); // '\u0906' is Unicode escape for character `เค`
/**************
result => {
character: '๐',
codePoint: {
dec: 128522,
hex: '01F60A',
bits: 20
},
codeUnits: {
count: '2',
dec: [55357, 56842],
binary: ['1101100000111101', '1101111000001010'],
hex: ['D83D', 'DE0A'],
escape: { ascii: null, unicode: '\\uD83D\\uDE0A' }
}
}
**************/
```
## Run test
```
cd /repo/utf-info/
npm run test
fn:utfInfo suit
โ should return 0041 code point for the character A
โ should return 0906 code point for the character เค
โ should return `["D83D", "DE0A"]` UTF-16 code units for the character ๐
```