@lacussoft/cnpj-fmt
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

LacusSoft :: cnpj-fmt

NPM Latest Version Downloads Count Bundle Size Test Status Last Update Date Project License

Basic function to format CNPJ strings (Brazilian ID document).

Browser Support

Chrome Firefox Safari Opera Edge IE
Latest Latest Latest Latest Latest 11

Installation

$ npm install @lacussoft/cnpj-fmt

Import

// ES Modules
import cnpjFmt from '@lacussoft/cnpj-fmt'

// Common JS
const cnpjFmt = require('@lacussoft/cnpj-fmt')

or import it through your HTML file, using CDN:

<script src="https://cdn.jsdelivr.net/npm/@lacussoft/cnpj-fmt@latest/dist/cnpj-fmt.min.js"></script>

Usage

const cnpj = '03603568000195'

cnpjFmt(cnpj)       // returns '03.603.568/0001-95'

cnpjFmt(cnpj, {     // returns '03.603.***/****-**'
  hidden: true
})

cnpjFmt(cnpj, {     // returns '03603568|0001_95'
  delimiters: {
    dot: '',
    slash: '|',
    dash: '_'
  }
})

Formatting options

cnpjFmt(cnpj, {
  delimiters: {
    dot: '.',       // string to replace the dot characters
    slash: '/',     // string to replace the slash character
    dash: '-',      // string to replace the dash character
  },
  escape: false,    // boolean to define if the result should be HTML escaped
  hidden: false,    // boolean to define if digits should be hidden
  hiddenKey: '*',   // string to replace hidden digits
  hiddenRange: {
    start: 5,       // starting index of the numeric sequence to be hidden (min 0)
    end: 13,        // ending index of the numeric sequence to be hidden (max 13)
  },
  onFail(value) {   // fallback function to be invoked in case a non-14-digits is passed
    return value
  }
})

/@lacussoft/cnpj-fmt/

    Package Sidebar

    Install

    npm i @lacussoft/cnpj-fmt

    Weekly Downloads

    4

    Version

    1.1.1

    License

    MIT

    Unpacked Size

    55.9 kB

    Total Files

    9

    Last publish

    Collaborators

    • juliolmuller