New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@ar-identification/react

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ar-identification/react

Argentinian identification reader and data decoder

latest
npmnpm
Version
0.2.1
Version published
Maintainers
1
Created
Source

@ar-identification/react

An scanner for Argentinian DNI's.

Installation

yarn add @zxing/browser@^0.1.1 @zxing/library@^0.19.1 @ar-identification/decode@0.1.1 @ar-identification/react@0.2.1

Usage/Examples

The library includes a component called Scanner which scans only the front of the DNI at the moment. Also has the ability to read and validate QR codes.

Props

proptype signaturedescription
onScanSuccess(event: SuccessEvent) => voidcallback triggered on a successful scan
onScanError(error: Error) => voidcallback triggered on any error
classNamestring | undefinedan optional string containing css classes
allowQRbooleanan optional boolean to allow QR codes reading
QRValidationFn(data:string) => Promise<boolean>an optional async fn to validate the QR data

The DNI Object

proptype signaturedescription
namestringNombre / Name
surnamestringApellido / Surname
dateOfBirthDateFecha de nacimiento / Date of birth
dateOfIssueDateFecha de emisión / Date of issue
dateOfExpiryDateFecha de vencimiento / Date of expiry
copystringEjemplar
sex"MALE" | "FEMALE" | "NON_BINARY"Sexo / Sex
dnistringDocumento / Document
cuilstringCUIL
idstringTramite N° / Of. Ident

Implementation

import React, { useState } from "react";
import { DNI } from "@ar-identification/decode";
import { Scanner, ScannerProps } from "@ar-identification/react";

const App = () => {
  const [dni, setDni] = useState<DNI>();
  const [error, setError] = useState<string>();
  const [qr, setQR] = useState<string>();
  const handleOnScanError = (e: Error) => setError(e.message);

  const handleRetry = () => {
    setError(undefined);
    setDni(undefined);
    setQR(undefined);
  };

  const handleSuccess: ScannerProps["onScanSuccess"] = ({ type, data }) => {
    if (type === "DNI") {
      setDni(data as DNI);
    } else {
      setQR(data as string);
    }
  };

  const qrValidator = async (data: string) => {
    try {
      const parsedJSON = JSON.parse(data) as any;
      return !!parsedJSON.test;
    } catch (e) {
      console.log(e);
      return false;
    }
  };

  return (
    <div>
      {error && <p>{error}</p>}
      {dni && <pre style={{ fontFamily: "monospace" }}>{JSON.stringify(dni, null, 2)}</pre>}
      {qr && <pre style={{ fontFamily: "monospace" }}>{JSON.stringify(JSON.parse(qr), null, 2)}</pre>}
      {!dni && !error && !qr && (
        <Scanner onScanSuccess={handleSuccess} onScanError={handleOnScanError} allowQR QRValidationFn={qrValidator} />
      )}
      {(error || dni || qr) && <button onClick={handleRetry}>Retry</button>}
    </div>
  );
};

export default App;

FAQs

Package last updated on 19 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts