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 🙏

© 2026 – Pkg Stats / Ryan Hefner

cnj-br

v0.3.5

Published

Utilities for the Brazilian CNJ (Conselho Nacional de Justiça) processo numbering system.

Readme

cnj-br

npm build Maintainability issues license

Parse, validate, format, and inspect Brazilian CNJ processo numbers.

Install

pnpm add cnj-br
# or
npm i cnj-br
# or
yarn add cnj-br

Usage

The Cnj class is an ergonomic entry point. Pass it a formatted or digit-only processo number; it parses and validates in the constructor.

import { Cnj } from 'cnj-br'

const cnj = new Cnj('0000001-45.2024.8.26.0001')
// or: new Cnj('00000014520248260001')

cnj.format()                      // '0000001-45.2024.8.26.0001'
cnj.raw                           // '00000014520248260001'
cnj.segmentInfo                   // { code: 'TJ', name: 'Justiça Estadual' }
cnj.components                    // { sequentialNumber, checkDigits, year, segment, court, originUnit }

JSON.stringify(cnj)               // serializes the components

For form validation, use the static helpers - they don't throw.

Cnj.isValid('0000001-45.2024.8.26.0001')  // true
Cnj.isValid('garbage')                     // false

const cnj = Cnj.safeParse(userInput)       // Cnj | null
if (cnj) {
    // use cnj.format(), cnj.segmentInfo, etc.
}

Functional API

If you only need a single operation and don't want to instantiate a class, use the standalone functions.

import {
    parse,
    format,
    mask,
    calculateCheckDigits,
    hasValidCheckDigits,
    getSegmentInfo,
} from 'cnj-br'

parse('0000001-45.2024.8.26.0001')         // Processo.Components | null
format(components)                          // formatted string
format(components, { formatted: false })    // 20-digit string

calculateCheckDigits({                      // returns '45'
    sequentialNumber: '0000001',
    year: '2024',
    segment: '8',
    court: '26',
    originUnit: '0001',
})
hasValidCheckDigits(components)             // boolean

getSegmentInfo('8')   // { code: 'TJ', name: 'Justiça Estadual' }
getSegmentInfo(8)     // same - number or string both work
getSegmentInfo('99')  // null

mask is a progressive input formatter — feed it the raw digits the user has typed so far and it returns the canonical formatted prefix. Useful for <input onChange> handlers.

mask('00000014520')          // '0000001-45.20'
mask('00000014520248260001') // '0000001-45.2024.8.26.0001'

Error handling

There are three ways to handle invalid input - pick the one that fits your call site.

import { Cnj, InvalidProcessoError } from 'cnj-br'

// 1. Constructor throws
try {
    const cnj = new Cnj(input)
} catch (err) {
    if (err instanceof InvalidProcessoError) {
        // ...
    }
}

// 2. isValid returns a boolean
if (Cnj.isValid(input)) { /* ... */ }

// 3. safeParse returns Cnj | null
const cnj = Cnj.safeParse(input)
if (cnj) { /* ... */ }

Components

parse() and cnj.components return the processo broken into its six parts:

namespace Processo {
    interface Components {
        sequentialNumber: string  // NNNNNNN — 7 digits, sequential within (year, court)
        checkDigits: string       // DD      — 2 digits, ISO 7064 mod 97-10
        year: string              // AAAA    — 4 digits, year the case was filed
        segment: string           // J       — 1 digit, justice segment (1-9)
        court: string             // TR      — 2 digits, court within the segment
        originUnit: string        // OOOO    — 4 digits, originating unit
    }
}

Segment digits map to their relative entity: 1 STF, 2 CNJ, 3 STJ, 4 Justiça Federal, 5 Justiça do Trabalho, 6 Justiça Eleitoral, 7 Justiça Militar da União, 8 Justiça Estadual, 9 Justiça Militar Estadual.

About the format

The CNJ processo number follows the pattern NNNNNNN-DD.AAAA.J.TR.OOOO defined by Resolução nº 65/2008 do CNJ. The two check digits are computed with ISO 7064 mod 97-10 over the other 18 digits, which is what hasValidCheckDigits verifies.

Contributing

Contributions are welcome — see CONTRIBUTING.md.

License

MIT