check digit
v3.0.1
校验数字公式基于 https://www.gs1.org/services/how-calculate-check-digit-manually,并通过 https://www.gs1.org/services/check-digit-calculator 进行测试
您可以通过 Composer 安装该软件包:
composer require lloricode/check-digit
// Sample usage in testing
// tests/Feature/GenerateTest.php
use Lloricode CheckDigit Enums Format ;
use Lloricode CheckDigit Generator ;
# base in https://www.gs1.org/services/check-digit-calculator
assertSame ( 2 , Generator :: new ( 9638527 , Format :: GTIN_8 ())-> getCheckDigit ());
assertSame ( 4 , Generator :: new ( 3216549 , Format :: GTIN_8 ())-> getCheckDigit ());
assertSame ( 2 , Generator :: new ( 91739456321 , Format :: GTIN_12 ())-> getCheckDigit ());
assertSame ( 8 , Generator :: new ( 74185245963 , Format :: GTIN_12 ())-> getCheckDigit ());
assertSame ( 3 , Generator :: new ( 629104150021 , Format :: GTIN_13 ())-> getCheckDigit ());
assertSame ( 6 , Generator :: new ( 123456789876 , Format :: GTIN_13 ())-> getCheckDigit ());
assertSame ( 6 , Generator :: new ( 7539514528423 , Format :: GTIN_14 ())-> getCheckDigit ());
assertSame ( 5 , Generator :: new ( 8563251459762 , Format :: GTIN_14 ())-> getCheckDigit ());
assertSame ( 0 , Generator :: new ( 7896541230123456 , Format :: GSIN ())-> getCheckDigit ());
assertSame ( 3 , Generator :: new ( 7658485040650456 , Format :: GSIN ())-> getCheckDigit ());
assertSame ( 6 , Generator :: new ( 95135623050123698 , Format :: SSCC ())-> getCheckDigit ());
assertSame ( 7 , Generator :: new ( 87643802105978513 , Format :: SSCC ())-> getCheckDigit ());
// get generated value
assertSame ( ' 876438021059785137 ' , Generator :: new ( 87643802105978513 , Format :: SSCC ())-> getValue ());
// starts with zero
assertSame ( 7 , Generator :: new ( ' 0012345 ' , Format :: GTIN_8 ())-> getCheckDigit ());
assertSame ( 5 , Generator :: new ( ' 00123456789 ' , Format :: GTIN_12 ())-> getCheckDigit ());
assertSame ( 5 , Generator :: new ( ' 001234567890 ' , Format :: GTIN_13 ())-> getCheckDigit ());
assertSame ( 2 , Generator :: new ( ' 0012345678901 ' , Format :: GTIN_14 ())-> getCheckDigit ());
assertSame ( 3 , Generator :: new ( ' 0012345678901234 ' , Format :: GSIN ())-> getCheckDigit ());
assertSame ( 2 , Generator :: new ( ' 00123456789012345 ' , Format :: SSCC ())-> getCheckDigit ());
vendor/bin/pest
请参阅变更日志以了解有关最近更改内容的更多信息。
详细信息请参阅贡献。
如果您发现任何与安全相关的问题,请发送电子邮件至 [email protected],而不是使用问题跟踪器。
麻省理工学院许可证 (MIT)。请参阅许可证文件以获取更多信息。