@segment/analytics-next
Version:
Analytics Next (aka Analytics 2.0) is the latest version of Segment’s JavaScript SDK - enabling you to send your data to any tool without having to learn, test, or use a new API every time.
17 lines (16 loc) • 454 B
text/typescript
/**
* Tries to gets the unencoded version of an encoded component of a
* Uniform Resource Identifier (URI). If input string is malformed,
* returns it back as-is.
*
* Note: All occurences of the `+` character become ` ` (spaces).
**/
export function gracefulDecodeURIComponent(
encodedURIComponent: string
): string {
try {
return decodeURIComponent(encodedURIComponent.replace(/\+/g, ' '))
} catch {
return encodedURIComponent
}
}