UNPKG

sanity

Version:

Sanity is a real-time content infrastructure with a scalable, hosted backend featuring a Graph Oriented Query Language (GROQ), asset pipelines and fast edge caches

22 lines (21 loc) 602 B
/** * Like encodeURIComponent, but supports a custom set of unescaped characters. * @param uriComponent - A value representing an unencoded URI component. * @param unescaped - a string containing characters to not escape */ export function encodeURIComponentExcept( uriComponent: string | number | boolean, unescaped: string, ): string { const chars = [...String(uriComponent)] let res = '' for (let i = 0; i < chars.length; i++) { const char = chars[i] if (unescaped.includes(char)) { res += char } else { res += encodeURIComponent(char) } } return res }