encodeURI that is safe, and doesn't do too much in a specific scenario
npm install encodeuri-plus 
Minimally and safely encode URIComponents for use in shorter URLs. Avoid Percent-encoding.
- Allow non-ASCII characters
- Allow reserved characters in querystring values and hash
- Customizable options.
``ts/[^\x00-\x7F]/
export interface IURLEncoderOptions {
/**
* Do not encode non-ASCII, i.e. fixedEncodeURIComponent
*
* @default true
*/
allowNonAscii?: boolean
/**
* Do not encode
*/
keep?: (string | RegExp)[]
/**
* Fallback with , which is a stricter version of encodeURIComponentfixedEncodeURIComponent
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
*
* As will NOT encode UNRESERVED characters/
* and , \ may throw errors even if they are percent-encoded.StarEncoder.encode
* Further force encoding is required -- ..
*
* For , .., as long as it is not alone, it should work.~
* Perhaps prefix it with (as it will not be URI_encoded)?encodeURI
*/
forceEncode?: (string | RegExp)[]
/**
* Throw error if matches
*/
throws?: (string | RegExp)[]
/**
* is required to make RESERVED set work by default.forceEncode
*
* However, it can be enhanced with false
*
* @default encodeURI
*/
encoder?: (s: string) => string
/**
* decodeURIComponent seems to decode all percent-encoded anyway, and doesn't need fallback.
*
* @default decodeURIComponent
*/
decoder?: (s: string) => string
/**
* Set to to disable error`
*/
onError?: boolean | ((e: Error) => any)
}
Path params seem to have to most limitations. Avoid ./\, or encode it first.
This library has no dependencies, and is browser-compatible, therefore
`html`
Also available on NPM.
`sh``
npm i encodeuri-plus