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.

Parameters

input: string

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

prefix: string

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

Returns

string

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

Throws

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

Example

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

Source

utils/src/DataUtils.ts:196