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

neon-brcode

v2.0.4

Published

Node wrapper for Rust lib BRCODE

Downloads

26

Readme

neon-brcode

Node wrapper of brcode to parse and emit PIX BR Code.

Usage

  1. Install rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# or access https://rustup.rs/
  1. Install neon
npm install --global neon-cli
# OR
yarn global add neon-cli
  1. Install neon-code
npm install neon-brcode --save

Types and functions:


export interface BrCodeJson {
    payload_version: number;
    initiation_method?: number;
    merchant_account_information?: string;
    merchant_information: Array<{
        id: number;
        info: Array<{
            id: number;
            info: string;
        }>;
    }>;
    merchant_category_code: number;
    merchant_name: string;
    merchant_city: string;
    postal_code?: string;
    convenience?: String;
    convenience_fee_fixed?: String;
    convenience_fee_percentage?: String;
    currency: string;
    amount?: number;
    country_code: string;
    field_template: Array<{ reference_label: string }>;
    crc1610?: string;
    templates?: Array<{
        id: number;
        info: Array<{
            id: number;
            info: string;
        }>;
    }>;
}

function jsonToBrcode(json: BrCodeJson): string
function brcodeToJson(code: string): BrCodeJson
function brcodeIsPix(code: String): boolean 
function jsonIsPix(json: BrCodeJson): boolean
function crc16Ccitt(message: string): string
function getJsonTransactionId(json: BrCodeJson): String
function getBrcodeTransactionId(code: String): String
function getJsonAliases(json: BrCodeJson): Array<String> 
function getBrcodeAliases(code: String): Array<String> 
function getJsonMessages(json: BrCodeJson): Array<String>
function getBrcodeMessages(code: String): Array<String> 
function jsonToSvgFile(json: BrCodeJson, path: String) 
function brcodeToSvgFile(code: String, path: String)
function jsonToSvgString(json: BrCodeJson): String
function brcodeToSvgString(code: String): String 

Functions descriptions:

  • jsonToBrcode(json: BrCodeJson): string: converts a BrCodeJson into a BR Code String.
  • brcodeToJson(code: string): BrCodeJson: converts a BR Code String into a BrCodeJson.
  • brcodeIsPix(code: String): boolean: checks if BR Code String is of type Pix.
  • jsonIsPix(json: BrCodeJson): boolean: checks if BrCodeJson is of type Pix.
  • crc16Ccitt(message: string): string: generates a CRC16_CCITT for the inserted information.
  • getJsonTransactionId(json: BrCodeJson): String: returns the transactionId of a BrCodeJson.
  • getBrcodeTransactionId(code: String): String: returns the transactionId of a BR Code String.
  • getJsonAliases(json: BrCodeJson): Array<String>: returns all Pix aliases of a BrCodeJson.
  • getBrcodeAliases(code: String): Array<String>: returns all Pix aliases of a BR Code String.
  • getJsonMessages(json: BrCodeJson): Array<String>: returns all Pix messages of a BrCodeJson.
  • getBrcodeMessages(code: String): Array<String>: returns all Pix messages of a BR Code String.
  • jsonToSvgFile(json: BrCodeJson, path: String): generates a SVG file at path (must end with .svg) for BrCodeJson.
  • brcodeToSvgFile(code: String, path: String): generates a SVG file at path (must end with .svg) for BR Code String.
  • jsonToSvgString(json: BrCodeJson): String: generates a SVG string for BrCodeJson.
  • brcodeToSvgString(code: String): String: generates a SVG string for BR Code String.

Example usage

  • Test file has more usages.

Parse

const brcode = require('neon-brcode');
const code = "00020104141234567890123426580014BR.GOV.BCB.PIX0136123e4567-e12b-12d1-a456-42665544000027300012BR.COM.OUTRO011001234567895204000053039865406123.455802BR5917NOME DO RECEBEDOR6008BRASILIA61087007490062190515RP12345678-201980390012BR.COM.OUTRO01190123.ABCD.3456.WXYZ6304AD38";

brcode.brcodeToJson(code)

Output:

{
    "payload_version":1,
    "initiation_method":null,
    "merchant_information":[
        {"id":26,"info":[
            {"id":0,"info":"BR.GOV.BCB.PIX"},
            {"id":1,"info":"123e4567-e12b-12d1-a456-426655440000"}
        ]},
        {"id":27,"info":[
            {"id":0,"info":"BR.COM.OUTRO"},
            {"id":1,"info":"0123456789"}
        ]}
    ],
    "merchant_category_code":0,
    "merchant_name":"NOME DO RECEBEDOR",
    "merchant_city":"BRASILIA",
    "postal_code":"70074900",
    "currency":"986",
    "amount":123.45,
    "country_code":"BR",
    "field_template":[{"reference_label":"RP12345678-2019"}],
    "crc1610":"AD38",
    "templates":[
        {"id":80,"info":[
            {"id":0,"info":"BR.COM.OUTRO"},
            {"id":1,"info":"0123.ABCD.3456.WXYZ"}
        ]}
    ]
}

Emit

const brcode = require('neon-brcode');
const json = {
    "payload_version":1,
    "initiation_method":null,
    "merchant_information":[
        {"id":26,"info":[
            {"id":0,"info":"BR.GOV.BCB.PIX"},
            {"id":1,"info":"123e4567-e12b-12d1-a456-426655440000"}
        ]},
        {"id":27,"info":[
            {"id":0,"info":"BR.COM.OUTRO"},
            {"id":1,"info":"0123456789"}
        ]}
    ],
    "merchant_category_code":0,
    "merchant_name":"NOME DO RECEBEDOR",
    "merchant_city":"BRASILIA",
    "postal_code":"70074900",
    "currency":"986",
    "amount":123.45,
    "country_code":"BR",
    "field_template":[{"reference_label":"RP12345678-2019"}],
    "crc1610":"AD38",
    "templates":[
        {"id":80,"info":[
            {"id":0,"info":"BR.COM.OUTRO"},
            {"id":1,"info":"0123.ABCD.3456.WXYZ"}
        ]}
    ]
};

brcode.jsonToBrcode(json)

Output:

"00020104141234567890123426580014BR.GOV.BCB.PIX0136123e4567-e12b-12d1-a456-42665544000027300012BR.COM.OUTRO011001234567895204000053039865406123.455802BR5917NOME DO RECEBEDOR6008BRASILIA61087007490062190515RP12345678-201980390012BR.COM.OUTRO01190123.ABCD.3456.WXYZ6304AD38"

crc16Ccitt

const brcode = require('neon-brcode');
const unchecked_code = "00020104141234567890123426580014BR.GOV.BCB.PIX0136123e4567-e12b-12d1-a456-42665544000027300012BR.COM.OUTRO011001234567895204000053039865406123.455802BR5917NOME DO RECEBEDOR6008BRASILIA61087007490062190515RP12345678-201980390012BR.COM.OUTRO01190123.ABCD.3456.WXYZ6304";

brcode.crc16Ccitt(unchecked_code)
// "AD38"