Skip to content

AIDC Toolkit / GS1 / PrefixManager

Class: PrefixManager

Defined in: src/prefix-manager.ts:41

Prefix manager. This is the core class for identifier creation.

A prefix manager may be constructed for any prefix type. Construction may be done directly or via the static get() method, which allows for caching and reuse. As most applications work with a limited number of prefixes for creating identifiers, caching and reuse may be a more efficient option.

The prefix type and prefix are normalized before the prefix manager is constructed, so they may not match the input values. For example, the GS1 Company Prefix 0614141 is equivalent to U.P.C. Company Prefix 614141; both result in a prefix manager with prefix type equal to PrefixTypes.UPCCompanyPrefix and prefix equal to "614141".

To support the creation of sparse identifiers, a prefix manager maintains a tweak factor which is used, along with a type-specific multiplier, as the tweak when creating numeric identifiers. The default tweak factor is the numeric value of the GS1 Company Prefix representation of the prefix preceded by '1' to ensure uniqueness (i.e., so that prefixes 0 N1 N2 N3... and N1 N2 N3... produce different tweak factors). This is usually sufficient for obfuscation, but as the sparse creation algorithm is reversible and as the GS1 Company Prefix is discoverable via Verified by GS1, a user-defined tweak factor should be used if a higher degree of obfuscation is required. When using a tweak factor other than the default, care should be taken to restore it when resuming the application. A tweak factor of 0 creates a straight sequence.

Implements

Constructors

Constructor

new PrefixManager(prefixType, prefix): PrefixManager

Defined in: src/prefix-manager.ts:111

Constructor.

Parameters

prefixType

PrefixType

Prefix type.

prefix

string

Prefix.

Returns

PrefixManager

Accessors

prefixType

Get Signature

get prefixType(): PrefixType

Defined in: src/prefix-manager.ts:129

Get the prefix type.

Returns

PrefixType

Prefix type.

Implementation of

PrefixProvider.prefixType


prefix

Get Signature

get prefix(): string

Defined in: src/prefix-manager.ts:136

Get the prefix.

Returns

string

Prefix appropriate to the prefix type.

Implementation of

PrefixProvider.prefix


gs1CompanyPrefix

Get Signature

get gs1CompanyPrefix(): string

Defined in: src/prefix-manager.ts:143

Get the GS1 Company Prefix.

Returns

string

Prefix as GS1 Company Prefix.

Implementation of

PrefixProvider.gs1CompanyPrefix


upcCompanyPrefix

Get Signature

get upcCompanyPrefix(): string | undefined

Defined in: src/prefix-manager.ts:150

Get the U.P.C. Company Prefix if prefix type is PrefixTypes.UPCCompanyPrefix or undefined if not.

Returns

string | undefined

Prefix as U.P.C. Company Prefix if prefix type is PrefixTypes.UPCCompanyPrefix or undefined if not.

Implementation of

PrefixProvider.upcCompanyPrefix


gs18Prefix

Get Signature

get gs18Prefix(): string | undefined

Defined in: src/prefix-manager.ts:157

Get the GS1-8 Prefix if prefix type is PrefixTypes.GS18Prefix or undefined if not.

Returns

string | undefined

Prefix as GS1-8 Prefix if prefix type is PrefixTypes.GS18Prefix or undefined if not.

Implementation of

PrefixProvider.gs18Prefix


tweakFactor

Get Signature

get tweakFactor(): bigint

Defined in: src/prefix-manager.ts:177

Get the tweak factor.

Returns

bigint

Set Signature

set tweakFactor(value): void

Defined in: src/prefix-manager.ts:187

Set the tweak factor.

Parameters
value

Tweak factor.

number | bigint

Returns

void


gtinCreator

Get Signature

get gtinCreator(): GTINCreator

Defined in: src/prefix-manager.ts:273

Get GTIN creator.

Returns

GTINCreator


glnCreator

Get Signature

get glnCreator(): NonSerializableNumericIdentifierCreator

Defined in: src/prefix-manager.ts:280

Get GLN creator.

Returns

NonSerializableNumericIdentifierCreator


ssccCreator

Get Signature

get ssccCreator(): NonSerializableNumericIdentifierCreator

Defined in: src/prefix-manager.ts:287

Get SSCC creator.

Returns

NonSerializableNumericIdentifierCreator


graiCreator

Get Signature

get graiCreator(): SerializableNumericIdentifierCreator

Defined in: src/prefix-manager.ts:294

Get GRAI creator.

Returns

SerializableNumericIdentifierCreator


giaiCreator

Get Signature

get giaiCreator(): NonNumericIdentifierCreator

Defined in: src/prefix-manager.ts:301

Get GIAI creator.

Returns

NonNumericIdentifierCreator


gsrnCreator

Get Signature

get gsrnCreator(): NonSerializableNumericIdentifierCreator

Defined in: src/prefix-manager.ts:308

Get GSRN creator.

Returns

NonSerializableNumericIdentifierCreator


gdtiCreator

Get Signature

get gdtiCreator(): SerializableNumericIdentifierCreator

Defined in: src/prefix-manager.ts:315

Get GDTI creator.

Returns

SerializableNumericIdentifierCreator


gincCreator

Get Signature

get gincCreator(): NonNumericIdentifierCreator

Defined in: src/prefix-manager.ts:322

Get GINC creator.

Returns

NonNumericIdentifierCreator


gsinCreator

Get Signature

get gsinCreator(): NonSerializableNumericIdentifierCreator

Defined in: src/prefix-manager.ts:329

Get GSIN creator.

Returns

NonSerializableNumericIdentifierCreator


gcnCreator

Get Signature

get gcnCreator(): SerializableNumericIdentifierCreator

Defined in: src/prefix-manager.ts:336

Get GCN creator.

Returns

SerializableNumericIdentifierCreator


cpidCreator

Get Signature

get cpidCreator(): NonNumericIdentifierCreator

Defined in: src/prefix-manager.ts:343

Get CPID creator.

Returns

NonNumericIdentifierCreator


gmnCreator

Get Signature

get gmnCreator(): NonNumericIdentifierCreator

Defined in: src/prefix-manager.ts:350

Get GMN creator.

Returns

NonNumericIdentifierCreator

Methods

get()

static get(prefixType, prefix): PrefixManager

Defined in: src/prefix-manager.ts:218

Get a prefix manager.

Parameters

prefixType

PrefixType

Prefix type.

prefix

string

Prefix.

Returns

PrefixManager

Prefix manager with normalized prefix type and prefix.


resetTweakFactor()

resetTweakFactor(): void

Defined in: src/prefix-manager.ts:202

Reset the tweak factor to its default (numeric value of the GS1 Company Prefix preceded by '1').

Returns

void


getIdentifierCreator()

getIdentifierCreator<TIdentifierType>(identifierType): IdentifierCreatorsRecord[TIdentifierType]

Defined in: src/prefix-manager.ts:244

Get an identifier creator.

Type Parameters

TIdentifierType

TIdentifierType extends IdentifierType

Identifier type type.

Parameters

identifierType

TIdentifierType

Identifier type for which to retrieve or construct identifier creator.

Returns

IdentifierCreatorsRecord[TIdentifierType]

Identifier creator.