Class PrefixManager

Prefix manager. This is the core class for identification key creation.

A prefix manager may be created for any prefix type. As most applications work with a limited number of prefixes for creating identification keys, prefix managers are cached in memory and may be reused.

Prefix managers are keyed by GS1 Company Prefix, so the prefix type that is requested may not match the prefix type of the returned prefix manager. For example, the prefix manager for GS1 Company Prefix 0614141 is identical to the one for U.P.C. Company Prefix 614141, with the prefix type equal to PrefixType.UPCCompanyPrefix and the prefix equal to "614141".

To support the creation of sparse identification keys, a prefix manager maintains a tweak which is used, along with a type-specific multiplier, as the tweak when creating numeric identification keys. 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.

Properties

GS1_COMPANY_PREFIX_MINIMUM_LENGTH: 4 = 4

GS1 Company Prefix minimum length.

GS1_COMPANY_PREFIX_MAXIMUM_LENGTH: 12 = 12

GS1 Company Prefix maximum length.

UPC_COMPANY_PREFIX_MINIMUM_LENGTH: 6 = 6

U.P.C. Company Prefix minimum length.

UPC_COMPANY_PREFIX_MAXIMUM_LENGTH: 11 = 11

U.P.C. Company Prefix maximum length.

GS1_8_PREFIX_MINIMUM_LENGTH: 2 = 2

GS1-8 Prefix minimum length.

GS1_8_PREFIX_MAXIMUM_LENGTH: 7 = 7

GS1-8 Prefix maximum length.

Accessors

  • get prefix(): string
  • Get the prefix.

    Returns string

  • get gs1CompanyPrefix(): string
  • Get the GS1 Company Prefix.

    Returns string

  • get tweakFactor(): bigint
  • Get the tweak factor.

    Returns bigint

  • set tweakFactor(value): void
  • Set the tweak factor.

    Parameters

    • value: number | bigint

      Tweak factor.

    Returns void

Methods

  • Validate a prefix.

    Parameters

    • prefixType: PrefixType

      Prefix type.

    • allowUPCCompanyPrefix: boolean

      If true, a U.P.C. Company Prefix expressed as a GS1 Company Prefix is permitted.

    • allowGS18Prefix: boolean

      If true, a GS1-8 Prefix expressed as a GS1 Company Prefix is permitted.

    • prefix: string

      Prefix.

    • isFromIdentificationKey: boolean = false

      If true, the prefix is from an identification key and should be trimmed before its character set is validated.

    • isNumericIdentificationKey: boolean = false

      If true, the prefix is from a numeric identification key and its character set will be validated by the caller.

    • OptionalpositionOffset: number

      Position offset within a larger string.

    Returns void

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

    Returns void