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

@avalontechsv/idsv

v1.1.0

Published

Validate common identity numbers in El Salvador

Downloads

49

Readme

idSV-js

codecov

Esta documentación tambien está disponible en español.

Introduction

idSV is a tool for validation and formatting of common identity numbers in El Salvador, such as DUI and NIT.

Important notice

Since December 17th, 2021, DUIs are valid NITs for natural persons, so any DUI is a valid NIT. This means that you can use the same number for both validations in the context of a natural person (i.e. a person with a DUI).

Legal entities are not affected by this change, so you should still use the NIT validation for them.

There is also an option to override this functionality in the library when required.

Installation

You can install the package via npm:

npm install @avalontechsv/idsv

Usage

Validation

import { isValidDUI, isValidNIT } from "@avalontechsv/idsv";

// Validate a DUI
// Properly formatted DUIs, with or without dashes or spaces at the beginning or end, are valid.
isValidDUI("00000000-0"); // true
isValidDUI("000000000"); // true
isValidDUI(" 00000000-0 "); // true

// Also, the library pads the DUI with zeros to the left if it's shorter than 9 digits. This is useful for validating DUIs that are stored in a database as integers.
isValidDUI("00"); // true

// Validate a NIT
// Properly formatted DUIs and NITs, with or without dashes or spaces at the beginning or end, are valid.
isValidNIT("00000000-0"); // true
isValidNIT("0000-000000-000-0"); // true

// DUIs are valid NITs by default, but you can override this behavior passing false as the second parameter.
isValidNIT("00000000-0", false); // false

// Also, the library pads the NIT with zeros to the left if it's shorter than 14 digits. This is useful for validating NITs that are stored in a database as integers.
isValidNIT("00"); // true

Formatting

import { formatDUI, formatNIT } from "@avalontechsv/idsv";

// Format a DUI
// Same as validation, but it returns the formatted DUI instead of a boolean.
formatDUI("00000000-0"); // '00000000-0'
formatDUI("000000000"); // '00000000-0'
formatDUI(" 00000000-0 "); // '00000000-0'
formatDUI("00"); // '00000000-0'

// Invalid DUIs throw an error.
formatDUI("00000000-1"); // Error: Invalid DUI

// Format a NIT
// Same as validation, but it returns the formatted NIT instead of a boolean. By default, valid DUIs are also valid NITs, but you can override this behavior passing false as the second parameter.

formatNIT("00000001-8"); // '00000001-8' (DUI)
formatNIT("0000-000000-000-0"); // '0000-000000-000-0'
formatNIT(" 0000-000000-000-0 "); // '0000-000000-000-0'

formatNIT("00000001-8", false); // Throws an error because '00000001-8' is a valid DUI but not a valid NIT.

// Invalid NITs throw an error.
formatNIT("0000-000000-000-1"); // Error: Invalid NIT

Testing

You can run the tests with npm:

npm run test

Other languages

This library is also available in other languages:

  • PHP (installable via Composer)

License

This package is open-sourced software licensed under the GNU General Public License v3.0.