https://github.com/gabrielczar/uricomponent
:squirrel: A simple library to converting a javascript object to an encoded URI parameter string. :gem:
https://github.com/gabrielczar/uricomponent
objectmapper url-parser
Last synced: 4 months ago
JSON representation
:squirrel: A simple library to converting a javascript object to an encoded URI parameter string. :gem:
- Host: GitHub
- URL: https://github.com/gabrielczar/uricomponent
- Owner: GabrielCzar
- License: mit
- Created: 2018-01-22T02:33:21.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-03-03T17:21:44.000Z (about 3 years ago)
- Last Synced: 2025-01-19T09:41:41.383Z (about 1 year ago)
- Topics: objectmapper, url-parser
- Language: JavaScript
- Homepage:
- Size: 260 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# URIComponent
A simple library to converting a javascript object to an encoded URI parameter string.
## Installation
```console
npm install uricomponent
```
## Import
**AMD**
```js
define(['uricomponent'], function (uricomponent) {
uricomponent.encode(...);
})
```
**CommonJS**
```js
var uricomponent = require('uricomponent');
uricomponent.encode(...);
```
**ES6 / ES2015 module**
```js
import uricomponent from 'uricomponent'
uricomponent.encode(...);
```
---
## Signature
```js
uricomponent.encode([Object]);
uricomponent.encode([Array],[String]);
```
---
## Use
- Input
```js
var obj = {
name : 'leo jaimesson',
age : 21,
emails : {
email1 : 'test@gmail.com',
email2 : 'test@outlook.com'
},
numbers : [
1,
2,
3
]
};
uricomponent.encode(obj);
```
- Output
```console
"name=leo%20jaimesson&age=21&emails%5Bemail1%5D=test%40gmail.com&emails%5Bemail2%5D=test%40outlook.com&numbers%5B%5D=1&numbers%5B%5D=2&numbers%5B%5D=3"
```
- Input
```js
var array = [
1,
2,
{
a : 'a',
b : 'b'
}
]
uricomponent.encode(array, 'name');
```
- Output
```console
"name%5B%5D=1&name%5B%5D=2&name%5B2%5D%5Ba%5D=a&name%5B2%5D%5Bb%5D=b"
```
---
### License
[MIT License](https://github.com/leojaimesson/MIT-License)