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:106
Constructor.
Parameters
gcpLengthCache
GS1 Company Prefix length cache.
Returns
GCPLength
Accessors
root
Get Signature
get root():
Root
Defined in: src/gcp-length.ts:116
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:127
Get the date/time the GS1 Company Prefix length data was last updated.
Returns
disclaimer
Get Signature
get disclaimer():
string
Defined in: src/gcp-length.ts:134
Get the disclaimer for the GS1 Company Prefix length data.
Returns
string
Methods
load()
load():
Promise<void>
Defined in: src/gcp-length.ts:327
Load the GS1 Company Prefix length data.
Returns
Promise<void>
lengthOf()
lengthOf(
identifierType,identifier):number
Defined in: src/gcp-length.ts:443
Get the length of a GS1 Company Prefix for an identifier.
Parameters
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.