1.3.0 • Published 11 months ago

@lacussoft/cnpj-fmt v1.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

LacusSoft :: cnpj-fmt

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

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

Browser Support

ChromeFirefoxSafariOperaEdgeIE
Latest ✔Latest ✔Latest ✔Latest ✔Latest ✔11 ✔

Installation

# using NPM
$ npm install --save @lacussoft/cnpj-fmt

# using Bun
$ bun add @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
  }
})
1.2.0

1 year ago

1.2.2

11 months ago

1.3.0

11 months ago

1.2.1

11 months ago

1.1.1

4 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago