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

@fogine/gs1-128-encoder

v1.4.1

Published

Encode GS1-128 string like (91)124578912345(92)5435479

Downloads

2

Readme

GS1-128 Encoder

This module encodes GS1-128 string (e.g. "(90)1234567890") to bits (e.g. "110100111..."), weights (e.g. "211232411..."), code array (e.g. [105, 102, 90, ...]) or string for barcode font. And also provides code 128 encoder.

NPM

This module does not provide barcode rendering feature.

This is inspired by code-128-encoder.

Usage

This module is ES6 style module and provides following functions. The default of this es6 module is an object with functions.

import {encodeToBits} from "gs1-128-encoder";
encodeToBits('(90)1234');

import gs1_128_encoder from "gs1-128-encoder";
gs1_128_encoder.encodeToBits('(90)1234');

Functions

Argument of functions are GS1-128 HRI string, which is shaped with following format:

"(90)123456789" // with '()' for AI
"90123456789"   // without '()' for AI (only for single application)
"(91)12(92)01"  // multiple application
"(21)00ABC00a"  // of course you can use application with alphabet data

encodeToBits

This function encodes GS1-128 HRI string to bits string for rendering barcode.

Code:

import {encodeToBits} from "gs1-128-encoder";

console.log(encodeToBits('(90)1234567890'));

Output:

1101001110011110101110110111101101011001110010001011000111000101101100001010011011110110101111001001100011101011

encodeToWeights

This function encodes GS1-128 HRI string to weights string for rendering barcode.

The first digit of output string is width of leftmost bar of barcode. The second digit is width of blank and the third digit is width of next bar.

Code:

import {encodeToWeights} from "gs1-128-encoder";

console.log(encodeToWeights('(90)1234567890'));

Output:

2112324111312141211122321311233311212411122141211142122331112

encodeToCodeArray

This function encodes GS1-128 HRI string to array of CODE128 code number.

Code:

import {encodeToCodeArray} from "gs1-128-encoder";

console.log(encodeToCodeArray('(90)1234567890'));

Output:

[ 105, 102, 90, 12, 34, 56, 78, 90, 83, 106 ]

encodeForBarcodeFont

This function encodes GS1-128 HRI string to string for barcode font. code-128-encoder also includes fonts using the same mapping.

Code:

import {encodeForBarcodeFont} from "gs1-128-encoder";

console.log(encodeForBarcodeFont('(90)1234567890'));

Output:

ÒÏz,BXnzsÓ

Code 128 Encoding

This module also provide code 128 encoder submodule.

Code 128 encoder has the same signature functions as main functions. See Functions.

import {code128} from "gs1-128-encoder";

console.log(code128.encodeForBarcodeFont('String to encode'));

code128.FNC1, code128.FNC2, code128.FNC3, code128.FNC4A, code128.FNC4B are available as special characters for FNCn. FNC4A is for type A and FNC4B is for type B.

import {code128} from "gs1-128-encoder";

console.log(code128.encodeForBarcodeFont(`\x00${code128.FNC1}${code128.FNC2}${code128.FNC3}${code128.FNC4A}`));
console.log(code128.encodeForBarcodeFont(`a${code128.FNC1}${code128.FNC2}${code128.FNC3}${code128.FNC4B}`));

License

Copyright 2017 TANAKA Koichi (https://github.com/MugeSo/)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.