Skip to content

AIDC Toolkit / GS1 / GTINValidator

Class: GTINValidator

Defined in: src/gtin-validator.ts:82

GTIN validator.

Extends

Constructors

Constructor

new GTINValidator(gtinType): GTINValidator

Defined in: src/gtin-validator.ts:106

Constructor.

Parameters

gtinType

GTINType

GTIN type.

Returns

GTINValidator

Overrides

AbstractNumericIdentifierValidator.constructor

Accessors

gtinType

Get Signature

get gtinType(): GTINType

Defined in: src/gtin-validator.ts:134

Inherit Doc
Returns

GTINType


leaderType

Get Signature

get leaderType(): string

Defined in: src/numeric-identifier-validator.ts:100

Get the leader type.

Returns

string

Inherited from

AbstractNumericIdentifierValidator.leaderType


identifierType

Get Signature

get identifierType(): IdentifierType

Defined in: src/identifier-validator.ts:170

Get the identifier type. Per the GS1 General Specifications, the identifier type determines the remaining properties.

Returns

IdentifierType

Inherited from

AbstractNumericIdentifierValidator.identifierType


prefixType

Get Signature

get prefixType(): PrefixType

Defined in: src/identifier-validator.ts:177

Get the prefix type supported by the identifier type. For all identifier types except the GTIN, this is PrefixTypes.GS1CompanyPrefix. For the GTIN, the prefix type determines the length.

Returns

PrefixType

Inherited from

AbstractNumericIdentifierValidator.prefixType


length

Get Signature

get length(): number

Defined in: src/identifier-validator.ts:184

Get the length. For numeric identifier types, the length is fixed; for alphanumeric identifier types, the length is the maximum.

Returns

number

Inherited from

AbstractNumericIdentifierValidator.length


referenceCharacterSet

Get Signature

get referenceCharacterSet(): ContentCharacterSet

Defined in: src/identifier-validator.ts:191

Get the reference character set.

Returns

ContentCharacterSet

Inherited from

AbstractNumericIdentifierValidator.referenceCharacterSet


referenceCreator

Get Signature

get referenceCreator(): CharacterSetCreator

Defined in: src/identifier-validator.ts:198

Get the reference creator.

Returns

CharacterSetCreator

Inherited from

AbstractNumericIdentifierValidator.referenceCreator

Methods

zeroSuppress()

static zeroSuppress(gtin12): string

Defined in: src/gtin-validator.ts:156

Zero suppress a GTIN-12.

Parameters

gtin12

string

GTIN-12.

Returns

string

Zero-suppressed GTIN-12.


zeroExpand()

static zeroExpand(zeroSuppressedGTIN12): string

Defined in: src/gtin-validator.ts:193

Zero expand a zero-suppressed GTIN-12.

Parameters

zeroSuppressedGTIN12

string

Zero-suppressed GTIN-12.

Returns

string

GTIN-12.


convertToGTIN14()

static convertToGTIN14(indicatorDigit, gtin): string

Defined in: src/gtin-validator.ts:236

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()

static normalize(gtin): string

Defined in: src/gtin-validator.ts:267

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()

static validateAny(gtin, gtinLevel): void

Defined in: src/gtin-validator.ts:340

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()

static validateGTIN14(gtin14): void

Defined in: src/gtin-validator.ts:405

Validate a GTIN-14.

Parameters

gtin14

string

GTIN-14.

Returns

void


parseVariableMeasureRCN()

static parseVariableMeasureRCN(format, rcn): RCNReference

Defined in: src/gtin-validator.ts:444

Parse a Restricted Circulation Number (RCN) using a variable measure trade item format. The format is a 12- or 13-character string (for RCN-12 or RCN-13 respectively), containing the following:

  • '2' - The first character of the RCN.
  • '0'-'9' - The second character of the RCN (RCN-13 only).
  • 'I' - One or more, in sequence, for the item reference.
  • 'P' - One or more, in sequence, for the price or weight.
  • 'V' - Zero or one, for the price or weight check digit.
  • 'C' - The check digit of the entire RCN.

The 'I', 'P', and 'V' formats may be in any order.

Some examples:

  • 2IIIIIVPPPPC - RCN-12 with a five-digit item reference, a price or weight check digit, and a four-digit price or weight.
  • 23IIIIVPPPPPC - RCN-13 with a four-digit item reference, a price or weight check digit, and a five-digit price or weight.
  • 2IIIIIIPPPPC - RCN-12 with a six-digit item reference and a four-digit price or eight.
  • 29IIIIIPPPPPC - RCN-13 with a five-digit item reference and a five-digit price or weight.

Parameters

format

string

Format.

rcn

string

RCN.

Returns

RCNReference

RCN reference.


creatorFor()

protected static creatorFor(characterSet): CharacterSetCreator

Defined in: src/identifier-validator.ts:140

Get the character set creator for a character set.

Parameters

characterSet

ContentCharacterSet

Character set.

Returns

CharacterSetCreator

Character set creator.

Inherited from

AbstractNumericIdentifierValidator.creatorFor


validatePrefix()

protected validatePrefix(partialIdentifier, positionOffset?): void

Defined in: src/gtin-validator.ts:142

Validate the prefix within an identifier.

Parameters

partialIdentifier

string

Partial identifier.

positionOffset?

number

Position offset within a larger string.

Returns

void

Overrides

AbstractNumericIdentifierValidator.validatePrefix


validate()

validate(identifier, validation?): void

Defined in: src/numeric-identifier-validator.ts:107

Validate an identifier and throw an error if validation fails.

Parameters

identifier

string

Identifier.

validation?

IdentifierValidation

Identifier validation parameters.

Returns

void

Inherited from

AbstractNumericIdentifierValidator.validate


padIdentifier()

protected padIdentifier(identifier, validation): string

Defined in: src/identifier-validator.ts:215

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.

validation

Identifier validation parameters.

IdentifierValidation | undefined

Returns

string

Padded identifier.

Inherited from

AbstractNumericIdentifierValidator.padIdentifier