uriToIdentifier
uriToIdentifier(
uri):string
Converts a URI to a valid identifier by checking its format and stripping known prefixes.
Parameters
Section titled “Parameters”• uri: undefined | null | string
The URI to be converted into an identifier. Can be a string, null, or undefined.
Returns
Section titled “Returns”string
The validated identifier as a string.
Remarks
Section titled “Remarks”This function processes a URI and transforms it into a valid identifier. It validates the URI’s format, checks for known prefixes, and ensures the resulting string conforms to identifier standards.
Example
Section titled “Example”const uri = 'prefix:identifierString';try { const identifier = uriToIdentifier(uri); console.log('Valid Identifier:', identifier);} catch (error) { console.error('Error:', error);}Throws
Section titled “Throws”If the input is not a string or is empty.
Throws
Section titled “Throws”If the processed identifier is invalid, with a detailed error message.
Description
Section titled “Description”The function first checks if the input is a valid string. If not, it throws an InvalidURIError. It then
searches for known valid prefixes in the URI. If found, these prefixes are removed, leaving only the core identifier.
This identifier is then validated using checkIdentifier, ensuring it adheres to the required format and checksum rules.
If validation fails, an InvalidIdentifierError is thrown, indicating the specific reason for the failure.