Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

encodeuri-plus

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

encodeuri-plus

encodeURI that is safe, and doesn't do too much in a specific scenario

  • 0.3.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10
increased by11.11%
Maintainers
1
Weekly downloads
 
Created
Source

encodeURI-plus

npm version Website shields.io

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.
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

<script src="https://unpkg.com/encodeuri-plus"></script>

Also available on NPM.

npm i encodeuri-plus

Keywords

FAQs

Package last updated on 17 Jul 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc