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

nestjs-oib-validator

v1.0.0

Published

class-validator IsOIB decorator for validating the Croatian OIB (osobni identifikacijski broj) in NestJS DTOs

Readme

nestjs-oib-validator

A class-validator decorator for validating the Croatian OIB (osobni identifikacijski broj) in NestJS DTOs.

class CreateCompanyDto {
  @IsOIB()
  oib: string;
}

Installation

npm install nestjs-oib-validator class-validator

class-validator is a peer dependency — bring your own version (>= 0.14).

Usage

In a NestJS DTO

The decorator plugs into Nest's ValidationPipe like any other class-validator rule.

// create-company.dto.ts
import { IsString } from 'class-validator';
import { IsOIB } from 'nestjs-oib-validator';

export class CreateCompanyDto {
  @IsString()
  name: string;

  @IsOIB()
  oib: string;
}
// main.ts
import { ValidationPipe } from '@nestjs/common';

app.useGlobalPipes(new ValidationPipe({ whitelist: true }));

An invalid OIB then yields a 400 Bad Request:

{
  "statusCode": 400,
  "message": ["oib must be a valid OIB"],
  "error": "Bad Request"
}

Custom message

@IsOIB({ message: 'OIB nije ispravan' })
oib: string;

Every ValidationOptions field is supported (message, groups, each, always, context).

Optional fields

Combine with @IsOptional() when the field may be absent:

@IsOptional()
@IsOIB()
oib?: string;

Outside a DTO

The underlying check is exported on its own, for services, guards or scripts:

import { isValidOib } from 'nestjs-oib-validator';

if (!isValidOib(input)) {
  throw new BadRequestException('Invalid OIB');
}

API

| Export | Description | | ----------------- | --------------------------------------------------------------------------- | | IsOIB(options?) | Property decorator; takes the standard ValidationOptions. | | isValidOib(oib) | (oib: unknown) => boolean — the check itself, with no decorator wrapping. |

Validation errors appear under the isOIB key in ValidationError.constraints.

Validation rules

A value passes only if it is a string of exactly 11 digits (/^[0-9]{11}$/) whose final digit is the correct ISO 7064 MOD 11,10 check digit. No normalisation is performed — surrounding whitespace, separators and a leading + all fail. Trim and strip formatting upstream if your input needs it.

Fail-safe behaviour

isValidOib is total: it takes unknown and returns false for anything that is not a valid OIB, including null, undefined, numbers, objects and values whose toString throws. It never throws, so it is safe to call directly on unvalidated input without a surrounding type check or try/catch:

if (!isValidOib(req.body?.oib)) {
  throw new BadRequestException('Invalid OIB');
}

The matching is ASCII-only and anchored, so non-ASCII digit forms (Arabic-Indic, full-width) are rejected and there is no super-linear input handling.

Development

npm test           # jest, rooted at src/
npm run test:cov   # with coverage
npm run typecheck  # tsc --noEmit
npm run lint       # eslint --fix       (lint:check   = no --fix, used by CI)
npm run format     # prettier --write   (format:check = no --write, used by CI)
npm run build      # tsc -> dist/ (js + .d.ts + maps)

prepublishOnly runs lint, typecheck, tests and the build, so a broken tree cannot be published.

License

MIT