Skip to content

AIDC Toolkit / GS1 / GCPLength

Class: GCPLength ​

Defined in: src/gcp-length.ts:79

GS1 Company Prefix length service. The constructor takes a GCPLengthCache object, which is responsible for managing the cache and source.

The first step is to load the GS1 Company Prefix length data. This is done using the load() method, which works as follows:

  • If the next check date/time is in the future, the method returns immediately, regardless of whether any data is available. It does this to prevent a large number of requests to the source in the event of a failure.
  • Otherwise, if the cache date/time is undefined or less than the source date/time, it loads from the source, converts the data if necessary, and updates the cache.
  • Otherwise, it continues with the cached data.
  • The next check date/time is updated to the later of the source date/time plus one week and the current date/time plus one day.

The base class implementation of the GCPLengthCache manages only the cache itself, and it requires an application-provided storage implementation. The source is expected to be either a GCPLengthData object (created via another cache implementation) or a GCPLengthSourceJSON object, which is the format of the file provided by GS1.

Once the data is loaded, the lengthOf() method can be used to get the length of a GS1 Company Prefix for an identifier type and identifier.

Constructors ​

Constructor ​

new GCPLength(gcpLengthCache): GCPLength

Defined in: src/gcp-length.ts:111

Constructor.

Parameters ​

gcpLengthCache ​

GCPLengthCache

GS1 Company Prefix length cache.

Returns ​

GCPLength

Accessors ​

root ​

Get Signature ​

get root(): Root

Defined in: src/gcp-length.ts:145

Get the GS1 Company Prefix length tree root.

Returns ​

Root

GS1 Company Prefix length tree root.


dateTime ​

Get Signature ​

get dateTime(): Date

Defined in: src/gcp-length.ts:156

Get the date/time the GS1 Company Prefix length data was last updated.

Returns ​

Date


disclaimer ​

Get Signature ​

get disclaimer(): string

Defined in: src/gcp-length.ts:163

Get the disclaimer for the GS1 Company Prefix length data.

Returns ​

string

Methods ​

instance() ​

static instance(cacheInitializer?): Promise<GCPLength>

Defined in: src/gcp-length.ts:125

Get the shared global instance, initializing it if necessary. Every call to this method will call GCPLength.load, so saving the return value is not recommended except for time-limited batch operations.

Parameters ​

cacheInitializer? ​

() => GCPLengthCache

Optional callback to initialize the cache if the instance is undefined.

Returns ​

Promise<GCPLength>

Shared global instance.


load() ​

load(): Promise<void>

Defined in: src/gcp-length.ts:357

Load the GS1 Company Prefix length data. If the data has already been loaded, it will be reloaded if the data is at least a week old, a check for an update was made more than a day ago, and an update is present.

Returns ​

Promise<void>


lengthOf() ​

Call Signature ​

lengthOf(identifierType, identifier): number

Defined in: src/gcp-length.ts:473

Get the length of a GS1 Company Prefix for an identifier.

Parameters ​
identifierType ​

IdentifierType

Identifier type.

identifier ​

string

Identifier.

Returns ​

number

Length of GS1 Company Prefix, 0 if not a GS1 Company Prefix, or -1 if not found.

Call Signature ​

lengthOf(identifierType, identifiers): Iterable<number>

Defined in: src/gcp-length.ts:487

Get the lengths of GS1 Company Prefixes for multiple identifiers.

Parameters ​
identifierType ​

IdentifierType

Identifier type.

identifiers ​

Iterable<string>

Identifiers.

Returns ​

Iterable<number>

Lengths of GS1 Company Prefixes, 0 if not a GS1 Company Prefix, or -1 if not found.