Skip to content

:squirrel: A simple library to converting a javascript object to an encoded URI parameter string. 💎

License

Notifications You must be signed in to change notification settings

GabrielCzar/uricomponent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

URIComponent

A simple library to converting a javascript object to an encoded URI parameter string.

Installation

npm install uricomponent

Import

AMD

define(['uricomponent'], function (uricomponent) {
  uricomponent.encode(...);
})

CommonJS

var uricomponent = require('uricomponent');
uricomponent.encode(...);

ES6 / ES2015 module

import uricomponent from 'uricomponent'
uricomponent.encode(...);

Signature

uricomponent.encode([Object]);
uricomponent.encode([Array],[String]);

Use

  • Input
var obj = {
    name : 'leo jaimesson',
    age : 21,
    emails : {
        email1 : 'test@gmail.com',
        email2 : 'test@outlook.com'
    },
    numbers : [
        1,
        2,
        3
    ]
};

uricomponent.encode(obj);
  • Output
"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
var array = [
    1,
    2,
    {
        a : 'a',
        b : 'b'
    }
]

uricomponent.encode(array, 'name');
  • Output
"name%5B%5D=1&name%5B%5D=2&name%5B2%5D%5Ba%5D=a&name%5B2%5D%5Bb%5D=b"

License

MIT License

About

:squirrel: A simple library to converting a javascript object to an encoded URI parameter string. 💎

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published