Skip to content

Commit 4650dc6

Browse files
committed
Upload
0 parents  commit 4650dc6

219 files changed

Lines changed: 681043 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Dominican document validation
2+
3+
This package offers a simple and efficient way to validate Dominican Republic ID numbers. Perfect for developers who need to ensure the validity of identity documents in their applications. It checks the format and integrity of the ID number according to official rules.
4+
5+
# Installation
6+
7+
you can install the package using:
8+
9+
```sh
10+
npm install do-validator
11+
```
12+
13+
# Use
14+
15+
```sh
16+
import validateDominicanDocument from 'do-validator';
17+
18+
const validation = validateDominicanDocument('12345678901');
19+
20+
console.log(validation);
21+
```
22+
# API
23+
```sh
24+
validateDominicanDocument(document)
25+
```
26+
27+
Validates a Dominican identity card number.
28+
29+
### Parameters
30+
document (string): The identity card number to validate 11 characters without special characters.
31+
32+
### Return
33+
boolean: true if the ID number is valid, false otherwise.
34+
35+
# Example
36+
```sh
37+
import validateDominicanDocument from 'do-validator';
38+
39+
const validId = 'YOUR_DOMINICAN_DOCUMENT';
40+
const invalidId = '12345678901';
41+
42+
console.log(validateDominicanDocument(validId)); // true
43+
console.log(validateDominicanDocument(invalidId)); // false
44+
45+
```
46+
# Author
47+
DevKevs
48+
<a href="https://www.linkedin.com/in/kevin-f%C3%A9liz-encarnaci%C3%B3n-a20888200/" target="_blank">LinkedIn</a> <a href="https://devkevs.netlify.app/#/home" target="_blank">Portfolio</a> <a href="https://x.com/DevKevs_" target="_blank">Twitter (X)</a>

dist/index.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* The function `validateDominicanDocument` in JavasScript validates a Dominican Republic
3+
* identification document number.
4+
* @param {string} document - The code you provided is a function that validates a Dominican Republic
5+
* national identification document number (Cédula de Identidad y Electoral). The function takes a
6+
* string representing the document number as input and performs a series of calculations to validate
7+
* it.
8+
* @returns The function `validateDominicanDocument` is returning a boolean value - `true` if the
9+
* provided Dominican document number is valid, and `false` if it is not valid.
10+
*/
11+
declare function validateDominicanDocument(document: string): boolean;
12+
export { validateDominicanDocument };

dist/index.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.validateDominicanDocument = void 0;
4+
/**
5+
* The function `validateDominicanDocument` in JavasScript validates a Dominican Republic
6+
* identification document number.
7+
* @param {string} document - The code you provided is a function that validates a Dominican Republic
8+
* national identification document number (Cédula de Identidad y Electoral). The function takes a
9+
* string representing the document number as input and performs a series of calculations to validate
10+
* it.
11+
* @returns The function `validateDominicanDocument` is returning a boolean value - `true` if the
12+
* provided Dominican document number is valid, and `false` if it is not valid.
13+
*/
14+
function validateDominicanDocument(document) {
15+
if (document.length != 11) {
16+
throw new Error('The provided document should have only 11 characters');
17+
}
18+
const cedula = document;
19+
const c = cedula.split('');
20+
const v = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2];
21+
let result = 0;
22+
let oc;
23+
for (let i = 0; i < 10; i++) {
24+
const up = parseInt(c[i]) * v[i];
25+
const ab = up;
26+
if (ab >= 10) {
27+
oc = ab
28+
.toString()
29+
.split('')
30+
.map((x) => parseInt(x))
31+
.reduce((x, y) => x + y);
32+
}
33+
else {
34+
oc = ab;
35+
}
36+
result += oc;
37+
}
38+
let dp = result;
39+
let ac = dp.toString().split('')[0] + '0';
40+
ac = parseInt(ac);
41+
const uj = (ac / 10) * 10;
42+
if (uj < dp) {
43+
// eslint-disable-next-line prettier/prettier
44+
dp = (uj + 10) - dp;
45+
}
46+
const validationResult = c[10] == dp.toString();
47+
if (validationResult) {
48+
return true;
49+
}
50+
else {
51+
return false;
52+
}
53+
}
54+
exports.validateDominicanDocument = validateDominicanDocument;

node_modules/.bin/tsc

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/tsserver

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.package-lock.json

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@types/node/LICENSE

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@types/node/README.md

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)