checkdigit 0.2.0

  • Readme
  • Changelog
  • Example
  • Installing
  • new55

Checkdigit #

Star on GitHub style: effective dart License: MIT

A set of check digit algorithms used for error detection on identification numbers.

Installation #

In pubspec.yaml add the following dependency:

dependencies:
  checkdigit: ^0.2.0

Algorithms #

Luhn #

bool isValid = luhn.validate('79927398713');
int checkDigit = luhn.checkDigit('7992739871');
String checkDigitAsString = luhn.checkDigitAsString('7992739871');

Verhoeff #

bool isValid = verhoeff.validate('2363');
int checkDigit = verhoeff.checkDigit('236');
String checkDigitAsString = verhoeff.checkDigitAsString('236');

Damm #

bool isValid = damm.validate('5724');
int checkDigit = damm.checkDigit('572');
String checkDigitAsString = damm.checkDigitAsString('572');

ISBN #

// ISBN-10.
bool isValid = isbn10.validate('080442957X');
int checkDigit = isbn10.checkDigit('080442957');
String checkDigitAsString = isbn10.checkDigitAsString('080442957');
// ISBN-13.
bool isValid = isbn13.validate('9783161484100');
int checkDigit = isbn13.checkDigit('978316148410');
String checkDigitAsString = isbn13.checkDigitAsString('978316148410');

ISIN #

bool isValid = isin.validate('US0378331005');
int checkDigit = isin.checkDigit('US037833100');
String checkDigitAsString = isin.checkDigitAsString('US037833100');

CPF #

bool isValid = cpf.validate('11144477735');
int checkDigit = cpf.checkDigit('111444777');
String checkDigitAsString = cpf.checkDigitAsString('111444777');

IBAN #

bool isValid = iban.validate('GB82WEST12345698765432');
int checkDigit = iban.checkDigit('GB00WEST12345698765432');
String checkDigitAsString = iban.checkDigitAsString('GB00WEST12345698765432');

CNPJ #

bool isValid = cnpj.validate('11222333000181');
int checkDigit = cnpj.checkDigit('112223330001');
String checkDigitAsString = cnpj.checkDigitAsString('112223330001');

EAN-X #

// EAN-13.
bool isValid = ean13.validate('4006381333931');
int checkDigit = ean13.checkDigit('400638133393');
String checkDigitAsString = ean13.checkDigitAsString('400638133393');
// UPC-A.
bool isValid = upcA.validate('036000291452');
int checkDigit = upcA.checkDigit('03600029145');
String checkDigitAsString = upcA.checkDigitAsString('03600029145');
// EAN-8.
bool isValid = ean8.validate('73513537');
int checkDigit = ean8.checkDigit('7351353');
String checkDigitAsString = ean8.checkDigitAsString('7351353');

0.2.0 #

  • Add checkDigitAsString method.
  • Add CNPJ and EAN algorithms.
  • Make isbn13 an instance of EAN.

0.1.0 #

  • Initial version

example/main.dart

import 'package:checkdigit/checkdigit.dart';

void main() {
  print(luhn.validate('79927398713'));
  print(luhn.checkDigit('7992739871') == 3);

  print(verhoeff.validate('2363'));
  print(verhoeff.checkDigit('236') == 3);

  print(damm.validate('5724'));
  print(damm.checkDigit('572') == 4);

  print(isbn13.validate('9783161484100'));
  print(isbn13.checkDigit('978316148410') == 0);

  print(isbn10.validate('080442957X'));
  print(isbn10.checkDigit('080442957') == 10);

  print(isin.validate('US0378331005'));
  print(isin.checkDigit('US037833100') == 5);

  print(cpf.validate('11144477735'));
  print(cpf.checkDigit('111444777') == 35);

  print(iban.validate('GB82WEST12345698765432'));
  print(iban.checkDigit('GB00WEST12345698765432') == 82);
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  checkdigit: ^0.2.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:checkdigit/checkdigit.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
10
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
55
Learn more about scoring.

We analyzed this package on Jul 3, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.8.0 <3.0.0
Dev dependencies
effective_dart ^1.2.3
test ^1.15.0