AIDC Toolkit / GS1 / GTINValidator
Class: GTINValidator
Defined in: src/gtin-validator.ts:46
GTIN validator.
Extends
Implements
Constructors
Constructor
new GTINValidator(
gtinBaseLength):GTINValidator
Defined in: src/gtin-validator.ts:81
Constructor.
Parameters
gtinBaseLength
GTIN base length (all except GTIN-14).
Returns
GTINValidator
Overrides
NumericIdentifierValidator.constructor
Accessors
prefixType
Get Signature
get prefixType():
PrefixType
Defined in: src/gtin-validator.ts:92
Prefix type supported by the identifier type. For all identifier types except the GTIN, this is a GS1 Company Prefix. For the GTIN, the prefix type determines the length.
Returns
Prefix type supported by the identifier type. For all identifier types except the GTIN, this is a GS1 Company Prefix. For the GTIN, the prefix type determines the length.
Implementation of
Overrides
NumericIdentifierValidator.prefixType
leaderType
Get Signature
get leaderType():
IdentifierTypeDescriptor<TNumericIdentifierType>["leaderType"]
Defined in: src/numeric-identifier-validator.ts:52
Leader type.
Returns
IdentifierTypeDescriptor<TNumericIdentifierType>["leaderType"]
Leader type.
Implementation of
Inherited from
NumericIdentifierValidator.leaderType
identifierType
Get Signature
get identifierType():
IdentifierTypeDescriptor<TIdentifierType>["identifierType"]
Defined in: src/identifier-validator.ts:65
Get the identifier type. Per the GS1 General Specifications, the identifier type determines the remaining properties.
Returns
IdentifierTypeDescriptor<TIdentifierType>["identifierType"]
Identifier type. Per the GS1 General Specifications, the identifier type determines the remaining properties.
Implementation of
Inherited from
NumericIdentifierValidator.identifierType
length
Get Signature
get length():
IdentifierTypeDescriptor<TIdentifierType>["length"]
Defined in: src/identifier-validator.ts:82
Get the length. For numeric identifier types, the length is fixed; for alphanumeric identifier types, the length is the maximum.
Returns
IdentifierTypeDescriptor<TIdentifierType>["length"]
Length. For numeric identifier types, the length is fixed; for non-numeric identifier types, the length is the maximum.
Implementation of
Inherited from
NumericIdentifierValidator.length
referenceCharacterSet
Get Signature
get referenceCharacterSet():
IdentifierTypeDescriptor<TIdentifierType>["referenceCharacterSet"]
Defined in: src/identifier-validator.ts:89
Get the reference character set.
Returns
IdentifierTypeDescriptor<TIdentifierType>["referenceCharacterSet"]
Reference character set.
Implementation of
GTINDescriptor.referenceCharacterSet
Inherited from
NumericIdentifierValidator.referenceCharacterSet
referenceCreator
Get Signature
get referenceCreator():
CharacterSetCreator
Defined in: src/identifier-validator.ts:96
Get the reference creator.
Returns
CharacterSetCreator
Inherited from
NumericIdentifierValidator.referenceCreator
Methods
zeroSuppress()
staticzeroSuppress(gtin12):string
Defined in: src/gtin-validator.ts:113
Zero suppress a GTIN-12.
Parameters
gtin12
string
GTIN-12.
Returns
string
Zero-suppressed GTIN-12.
zeroExpand()
staticzeroExpand(zeroSuppressedGTIN12):string
Defined in: src/gtin-validator.ts:150
Zero expand a zero-suppressed GTIN-12.
Parameters
zeroSuppressedGTIN12
string
Zero-suppressed GTIN-12.
Returns
string
GTIN-12.
convertToGTIN14()
staticconvertToGTIN14(indicatorDigit,gtin):string
Defined in: src/gtin-validator.ts:193
Convert a GTIN of any length to a GTIN-14 with an optional indicator digit.
Parameters
indicatorDigit
string
Indicator digit. If blank, assumes "0" if the GTIN is not already a GTIN-14.
gtin
string
GTIN.
Returns
string
GTIN-14.
normalize()
staticnormalize(gtin):string
Defined in: src/gtin-validator.ts:222
Normalize a GTIN of any length.
- A GTIN-14 that starts with six zeros or a GTIN-13 that starts with five zeros is normalized to GTIN-8.
- A GTIN-14 that starts with two zeros or a GTIN-13 that starts with one zero is normalized to GTIN-12.
- A GTIN-14 that starts with one zero is normalized to GTIN-13.
- Otherwise, the GTIN is unchanged.
Parameters
gtin
string
GTIN.
Returns
string
Normalized GTIN.
validateAny()
staticvalidateAny(gtin,gtinLevel):void
Defined in: src/gtin-validator.ts:295
Validate any GTIN, optionally against a level.
Parameters
gtin
string
GTIN.
gtinLevel
GTINLevel = GTINLevels.Any
Level at which GTIN is to be validated.
Returns
void
validateGTIN14()
staticvalidateGTIN14(gtin14):void
Defined in: src/gtin-validator.ts:367
Validate a GTIN-14.
Parameters
gtin14
string
GTIN-14.
Returns
void
validatePrefix()
protectedvalidatePrefix(partialIdentifier):void
Defined in: src/gtin-validator.ts:99
Validate the prefix within an identifier.
Parameters
partialIdentifier
string
Partial identifier.
Returns
void
Overrides
NumericIdentifierValidator.validatePrefix
validate()
validate(
identifier,validation?):void
Defined in: src/numeric-identifier-validator.ts:59
Validate an identifier and throw an error if validation fails.
Parameters
identifier
string
Identifier.
validation?
Identifier validation parameters.
Returns
void
Inherited from
NumericIdentifierValidator.validate
padIdentifier()
protectedpadIdentifier(identifier,positionOffset?):string
Defined in: src/identifier-validator.ts:113
Pad an identifier on the left with zero-value character for validation purposes. This is done to align an identifier with a position offset for any error message that may be thrown by the reference validator.
Parameters
identifier
string
Identifier.
positionOffset?
number
Position offset within a larger string.
Returns
string
Padded identifier.