Skip to main content

index/functions/tryParseCompositeKey.md

tryParseCompositeKey(value): GalaChainTokenClassKey | undefined

Parses a $-joined composite key (Collection$Category$Type$AdditionalKey, what compositeKeyOf writes) and nothing else, or undefined. It is tryParseTokenClassKey for a string that may ONLY be in the $ form: a key that contains | is NOT read as the pipe form here (it stays part of a segment), and only a string is accepted. The split is from the right, so a collection that itself contains $ (production's $GMUSIC, stage's $GMUSIC_TEST1) stays whole; 'GALA', 'GALA$Unit$none', 'ETIME$$$', 'GALA$Unit$none$' and '$$$$' are undefined.

It replaces an app's own parseCompositeKey(key): Components | null (?? null), which had exactly these semantics.

Parameters​

ParameterType
valueunknown

Returns​

GalaChainTokenClassKey | undefined

Example​

tryParseCompositeKey('$GMUSIC_TEST1$Unit$none$none')?.collection; // '$GMUSIC_TEST1'
tryParseCompositeKey('GALA$Unit$none'); // undefined