Skip to content

📋 Validate and generate valid GTIN's easily. This project indeed to be; stable, easy and fast (when possible)

License

Notifications You must be signed in to change notification settings

vinicioslc/gtin-toolkit-dart

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GTIN Toolkit

Codacy Badge pub package Dart CI

Illustrative Image

A toolkit for validate GTIN's and generate GTIN as well.

This project indeeds to be, stable, easy to use and fast (when possible).

Features

Actually this library could make something like :

  • Validate

    GTIN including types, SSCC, GSIN, GTIN-14, GTIN-13, GTIN-12, GTIN-8.

  • Generate Random valid GTIN

    Only need give the amount of GTIN digits ex.: for SSCC use 18 digits.

  • Classify GTIN

    Return type using length for classify SSCC, GSIN, GTIN-14, GTIN-13, GTIN-12, GTIN-8.

Use Example

import 'package:gtin_toolkit/gtin_toolkit.dart' as gtinTool;
import 'package:test/test.dart';

void main() {
  test('All methods are being exported correctly', () {
    // Generating a valid GTIN number with 12 digit length
    String validGtin = gtinTool.generateGTIN(gtinLength: 12);
    // make error replacing two right number with 1
    String invalidGtin = validGtin.padRight(10).padRight(13, '1');

    List<int> validGtinArray = validGtin.split('').map(int.parse).toList();
    List<int> invalidGtinArray = invalidGtin.split('').map(int.parse).toList();

    expect(gtinTool.parseAndValidate(validGtin), true);
    expect(gtinTool.isValidGTIN(validGtinArray), true);

    expect(gtinTool.parseAndValidate(invalidGtin), false);
    expect(gtinTool.isValidGTIN(invalidGtinArray), false);

    expect(gtinTool.generateGTIN().length, 14);
    expect(gtinTool.classifyGTIN(validGtin)['name'], 'GTIN-12');

    expect(true, true);
  });
}

About

📋 Validate and generate valid GTIN's easily. This project indeed to be; stable, easy and fast (when possible)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages