Skip to content

trimPrefix

trimPrefix(input, prefix): string

Trims a specified prefix from an input string and returns the remaining part. If the prefix is not present, returns the original string.

input: string

The input string to process (e.g., ‘registry:cord:abcd’).

prefix: string

The prefix to remove (e.g., ‘registry:cord:’).

string

The string with the prefix removed (e.g., ‘abcd’), or the original string if the prefix is not found.

If the input or prefix is empty or not a string.

trimPrefix('registry:cord:abcd', 'registry:cord:') // Returns 'abcd'
trimPrefix('did:cord:xyz', 'did:cord:') // Returns 'xyz'
trimPrefix('abcd', 'registry:cord:') // Returns 'abcd'

utils/src/DataUtils.ts:196