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

pos-print-codepage-encoder

v3.0.0

Published

A library for converting Unicode to obscure single byte codepage for use with thermal printers.

Downloads

88

Readme

CodepageEncoder

A library for converting Unicode to obscure single byte codepage for use with thermal printers. This library is internally used by esc-pos-encoder, star-prnt-encoder and receipt-printer-encoder and limited in functionality. We recommend that you use another library like iconv or iconv-lite for use with your project – unless you really, really need the codepages that are supported by this library.

Usage

First, install the package using npm:

npm install @point-of-sale/codepage-encoder --save

Then, require the package and use it like so:

let CodepageEncoder = require('@point-of-sale/codepage-encoder');
CodepageEncoder.encode('ξεσκεπάζω την ψυχοφθόρα βδελυγμία', 'cp869');

Or import it as an ES module:

import CodepageEncoder from '@point-of-sale/codepage-encoder';
CodepageEncoder.encode('ξεσκεπάζω την ψυχοφθόρα βδελυγμία', 'cp869');

Methods

The following static methods are available for you to use. You don't need to instantiate the object first.

CodepageEncoder.encode

Encode the string to the codepage you specified. The result will be a Uint8Array containing all the bytes of the string in your codepage.

CodepageEncoder.encode('ξεσκεπάζω την ψυχοφθόρα βδελυγμία', 'cp869');

Result:

Uint8Array(33) [
    232, 222, 236, 228, 222, 234, 155,
    224, 250,  32, 238, 225, 231,  32,
    246, 242, 244, 233, 243, 226, 162,
    235, 214,  32, 215, 221, 222, 229,
    242, 216, 230, 159, 214
]

See the method CodepageEncoder.getEncodings() for determining which codepages are currently supported by this library.

CodepageEncoder.autoEncode

Encode the string with the most optimal set of codepages from the candidates codepages that you specified. The result will be a array of text fragments with the name of the codepage and an Uint8Array containing all the bytes of the string in that codepage.

CodepageEncoder.autoEncode('Qwerty ψυχοφθόρα på Съешь łódź', [
    'cp437', 'cp858', 'cp860', 'cp861', 'cp863', 'cp865', 'cp852', 'cp857', 'cp855', 'cp866', 'cp869'
]);

Result:

[
    {
        codepage: 'cp437',
        bytes: Uint8Array(7) [
            81, 119, 101,
            114, 116, 121,
            32
        ]
    },
    {
        codepage: 'cp869',
        bytes: Uint8Array(11) [
            246, 242, 244, 233,
            243, 226, 162, 235,
            214,  32, 112
        ]
    },
    { 
        codepage: 'cp437', 
        bytes: Uint8Array(2) [ 
            134, 32 
        ] 
    },
    {
        codepage: 'cp855',
        bytes: Uint8Array(6) [ 
            228, 158, 168, 245, 237, 32 
        ]
    },
    { 
        codepage: 'cp852', 
        bytes: Uint8Array(4) [ 
            136, 162, 100, 171 
        ] 
    }
]

See the method CodepageEncoder.getEncodings() for determining which codepages are currently supported by this library.

CodepageEncoder.supports

Determine if the specified codepage is supported. Return a boolean.

CodepageEncoder.supports('cp1119')

Result:

true

CodepageEncoder.getEncodings

Get the currently supported encodings. Returns an array of codepage identifiers.

CodepageEncoder.getEncodings()

Result:

[
    'cp437',       'cp720',       'cp737',       'cp775',
    'cp850',       'cp851',       'cp852',       'cp853',
    'cp855',       'cp857',       'cp858',       'cp860',
    'cp861',       'cp862',       'cp863',       'cp864',
    'cp865',       'cp866',       'cp869',       'cp874',
    'cp1098',      'cp1118',      'cp1119',      'cp1125',
    'cp1162',      'cp2001',      'cp3001',      'cp3002',
    'cp3011',      'cp3012',      'cp3021',      'cp3041',
    'cp3840',      'cp3841',      'cp3843',      'cp3844',
    'cp3845',      'cp3846',      'cp3847',      'cp3848',
    'iso88591',    'iso88592',    'iso88597',    'iso885915',
    'rk1048',      'windows1250', 'windows1251', 'windows1252',
    'windows1253', 'windows1254', 'windows1255', 'windows1256',
    'windows1257', 'windows1258'
]

CodepageEncoder.getTestStrings

Get a number of example strings that can be used for the codepage you specified.

CodepageEncoder.getTestStrings('cp865')

Result:

[
    { language: 'sv', string: 'Flygande bäckasiner söka strax hwila på mjuka tuvor.' },
    { language: 'dk', string: 'Quizdeltagerne spiste jordbær med fløde' }
]

License

MIT