Skip to content

uri-escapify

npm package

NPM versionNPM Downloadsjsdelivr

A lightweight URI escaping utility library providing escape and unescape functionality.


Installation

bash
npm add uri-escapify
bash
pnpm add uri-escapify
bash
yarn add uri-escapify
html
<script src="https://cdn.jsdelivr.net/npm/uri-escapify/dist/index.umd.min.js"></script>
<script>
  const { escape, unescape } = UriEscapify;
  // Basic encoding
  console.log(escape('hello world')); // Outputs "hello%20world"

  // Chinese encoding
  console.log(escape('中文@示例')); // Outputs "%E4%B8%AD%E6%96%87%40%E7%A4%BA%E4%BE%8B"

  // Reserved characters preservation
  console.log(escape("!-._~'()*")); // Outputs original string

  // Decoding operation
  console.log(unescape("%E4%B8%AD%E6%96%87")); // Outputs "中文"
</script>

Usage Examples

typescript
import { escape, unescape } from 'uri-escapify';

// Basic encoding
console.log(escape('hello world')); // Outputs "hello%20world"

// Chinese encoding
console.log(escape('中文@示例')); // Outputs "%E4%B8%AD%E6%96%87%40%E7%A4%BA%E4%BE%8B"

// Reserved characters preservation
console.log(escape("!-._~'()*")); // Outputs original string

// Decoding operation
console.log(unescape("%E4%B8%AD%E6%96%87")); // Outputs "中文"

API Documentation

escape(input: any): string

  • Input Type: Any type (non-string values are converted to strings)
  • Output: Percent-encoded string
  • Reserved Characters:
    text
    !-._~'()*

unescape(input: string): string

  • Input: Percent-encoded string
  • Output: Decoded original string

Core Functionality Comparison

MethodFunctionDifference from Native APIs
escapeURI EncodingMore strict handling of reserved characters like !-._~'()*
unescapeURI DecodingSupports error-tolerant processing of incomplete encodings

Browser Support

ChromeFirefoxSafariOperaEdge
Latest ✔Latest ✔Latest ✔Latest ✔Latest ✔

Last updated: