https://github.com/luke3butler/node-phpurlencode
URL encoder/decoder for javascript that is functionally similar to PHP urlencode() and urldecode()
https://github.com/luke3butler/node-phpurlencode
javascript nodejs php url-encoder urldecode urlencode
Last synced: 16 days ago
JSON representation
URL encoder/decoder for javascript that is functionally similar to PHP urlencode() and urldecode()
- Host: GitHub
- URL: https://github.com/luke3butler/node-phpurlencode
- Owner: luke3butler
- License: mit
- Created: 2017-01-21T04:58:29.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-07-31T19:51:22.000Z (over 8 years ago)
- Last Synced: 2025-09-17T21:40:28.746Z (5 months ago)
- Topics: javascript, nodejs, php, url-encoder, urldecode, urlencode
- Language: JavaScript
- Size: 4.88 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# phpurlencode
Functionally similar to PHP urlencode and urldecode functions. No dependencies.
## Install
NPM
```bash
$ npm install phpurlencode
```
Yarn
```bash
$ yarn add phpurlencode
```
## Usage
### Include it in your Node.js file
```js
var phpurlencode = require('phpurlencode');
```
### phpurlencode(string)
```js
var encodedString = phpurlencode("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.67 Safari/537.36");
console.log(encodedString);
// => Mozilla%2F5.0+%28Macintosh%3B+Intel+Mac+OS+X+10_12_2%29+AppleWebKit%2F537.36+%28KHTML%2C+like+Gecko%29+Chrome%2F56.0.2924.67+Safari%2F537.36
```
### phpurlencode.encode(string) [ alias of phpurlencode( ) ]
```js
var encodedString = phpurlencode.encode("!@#$%^&*()-+='\"");
console.log(encodedString);
// => %21%40%23%24%25%5E%26%2A%28%29-%2B%3D%27%22
```
### phpurlencode.decode(string)
```js
var decodedString = phpurlencode.decode('%21%40%23%24%25%5E%26%2A%28%29-%2B%3D%27%22');
console.log(decodedString);
// => !@#$%^&*()-+='"
```
### phpurlencode.definePrototypes()
#### Globally defines `.urlencode` and `.urldecode` String prototypes
```js
// Register String prototypes.
// Once this function is called, the String prototypes will be available across your entire project
phpurlencode.definePrototypes();
var decodedString = '%21%40%23%24%25%5E%26%2A%28%29-%2B%3D%27%22'.urldecode();
console.log(decodedString);
// => !@#$%^&*()-+='"
var encodedString = decodedString.urlencode();
console.log(encodedString);
// => %21%40%23%24%25%5E%26%2A%28%29-%2B%3D%27%22
```