https://github.com/patarapolw/encodeuri-plus
encodeURI that is safe, and doesn't do too much in a specific scenario
https://github.com/patarapolw/encodeuri-plus
encodeuri encodeuricomponent
Last synced: 5 months ago
JSON representation
encodeURI that is safe, and doesn't do too much in a specific scenario
- Host: GitHub
- URL: https://github.com/patarapolw/encodeuri-plus
- Owner: patarapolw
- License: mit
- Created: 2020-07-14T02:26:34.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T11:25:40.000Z (over 3 years ago)
- Last Synced: 2025-10-31T13:06:57.375Z (8 months ago)
- Topics: encodeuri, encodeuricomponent
- Language: TypeScript
- Homepage: https://encodeuri-plus.netlify.app
- Size: 1.8 MB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# encodeURI-plus
[](https://badge.fury.io/js/encodeuri-plus) [](https://encodeuri-plus.netlify.app/)
Minimally and safely encode URIComponents for use in shorter URLs. Avoid Percent-encoding.
## Features
- Allow non-ASCII characters
- Allow reserved characters in querystring values and hash
- Customizable options.
```ts
export interface IURLEncoderOptions {
/**
* Do not encode non-ASCII, i.e. `/[^\x00-\x7F]/`
*
* @default true
*/
allowNonAscii?: boolean
/**
* Do not encode
*/
keep?: (string | RegExp)[]
/**
* Fallback with `fixedEncodeURIComponent`, which is a stricter version of `encodeURIComponent`
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
*
* As `fixedEncodeURIComponent` will NOT encode UNRESERVED characters
* and `/`, `\` may throw errors even if they are percent-encoded.
* Further force encoding is required -- `StarEncoder.encode`.
*
* For `.`, `..`, as long as it is not alone, it should work.
* Perhaps prefix it with `~` (as it will not be URI_encoded)?
*/
forceEncode?: (string | RegExp)[]
/**
* Throw error if matches
*/
throws?: (string | RegExp)[]
/**
* `encodeURI` is required to make RESERVED set work by default.
*
* However, it can be enhanced with `forceEncode`
*
* @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 `false` to disable error
*/
onError?: boolean | ((e: Error) => any)
}
```
## Caveats
Path params seem to have to most limitations. Avoid `./\`, or encode it first.
## Usage
This library has no dependencies, and is browser-compatible, therefore
```html
```
Also available on NPM.
```sh
npm i encodeuri-plus
```