Language: English / Español
Dominican Republic Utils (hence, dr-utils) is a JavaScript library built with TypeScript for utilities relevant to the Dominican Republic, such as Cedula, RNC, NCF and Phone Number validation and formatting.
There are Cedulas/RNC that give false negatives (i.e. a valid cedula fails validation) due to them not matching the algorithm. It is very likely the Dominican Government / DGII may have started issuing new cedulas with another algorithm that's not Luhn's (mod 10) or have exceptions with an unknown (not public) condition (unless it's random). The calculated rate of failure using the public RNC database is about 0.01% chance, which is very low but not zero.
# Using NPM
$ npm i dr-utils
# Using Yarn
$ yarn add dr-utils
# Using PNPM
$ pnpm add dr-utils
# Using Bun
$ bun add dr-utilsimport { validateCedula } from 'dr-utils'
const cedula = '40220579912'
const isCedulaValid = validateCedula(cedula) // trueimport { validateRNC } from 'dr-utils'
const rnc = '130500292'
const isRNCValid = validateRNC(rnc) // trueimport { validateNCF } from 'dr-utils'
const ncf = 'E319123402392'
const isNCFValid = validateNCF(ncf) // trueimport { validatePhoneNumber } from 'dr-utils'
const isPhoneNumberOneValid = validatePhoneNumber('8092201111') // true
const isPhoneNumberTwoValid = validatePhoneNumber('+1 (781) 575 4238') // falseimport { formatCedula } from 'dr-utils'
const withDashes = formatCedula('40220579912') // 402-2057991-2
const withoutDashes = formatCedula('402-2057991-2', 'without-dashes') // 40220579912import { formatRNC } from 'dr-utils'
const withDashes = formatRNC('130500292') // 130-50029-2
const withoutDashes = formatRNC('130-50029-2', 'without-dashes') // 130500292import { formatPhoneNumber } from 'dr-utils'
const phoneNumber = '8092201111'
const formatted = formatPhoneNumber(phoneNumber) // (809) 220-1111
const formattedInternational = formatPhoneNumber(phoneNumber, true) // +18092201111You can get the municipalities for a given province like this:
import { getMunicipiosByProvincia, Provincias } from 'dr-utils'
const municipios = getMunicipiosByProvincia(Provincias.LA_ALTAGRACIA)
console.log(municipios)
// [
// 'Higüey',
// 'San Rafael del Yuma',
// ]On the other hand, if you have a municipality and would like to know what province it's in, you can do:
import { getProvinciaByMunicipio } from 'dr-utils'
const provincia = getProvinciaByMunicipio('Sabana Grande de Boyá')
console.log(provincia) // "Monte Plata"You can also check the full list of provinces and municipalities by importing the Provincias and MunicipiosPorProvincia constants.
See CONTRIBUTING
See LICENSE