Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

shiyou0130011/JS-URL-Variable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 

Repository files navigation

JS-URL-Variable Apache License 2.0

JS-URL-Variable is a javascript code used for parse url query string into an object.

Table of Contents

About

This is the code I wrote for my another project paginate-blogger-posts

Documentation

Example

Parse Full URL

<script src="/The/Path/of/The/File/url_variable.js"></script>
<script>
var urlVariables = new URLVariables("http://example.com/?var1=A&var2=B&var3=https%3A%2F%2Fexample.com");
console.log(urlVariables);      // will log an object: 
                                // {
                                //	"var1": ["A"],
                                //	"var2": ["B"],
                                //	"var3": ["https://example.com"]
                                // }
</script>

Parse Object

<script src="/The/Path/of/The/File/url_variable.js"></script>
<script>
var urlVariables = new URLVariables({"var1":"A", "var2":"B", "var3":"https://example.com"});
console.log(urlVariables);      // will log an object: 
                                // {
                                //	"var1": ["A"],
                                //	"var2": ["B"],
                                //	"var3": ["https://example.com"]
                                // }
</script>

Get Query String

<script src="/The/Path/of/The/File/url_variable.js"></script>
<script>
var urlVariables = new URLVariables({"var2":"B", "var1":"A", "var3":"https://example.com"});
console.log(urlVariables.toString());	// will log a String: "var1=A&var2=B&var3=https%3A%2F%2Fexample.com"
</script>

Adding Variables

<script src="/The/Path/of/The/File/url_variable.js"></script>
<script>
var urlVariables = new URLVariables({"var1":"A", "var2":"B", "var3":"https://example.com"});

urlVariables.decode("var1=A2")   	// add url string
urlVariables.decode({var2: "B2"})	// add an object

console.log(urlVariables);      // will log an object: 
                                // {
                                //	"var1": ["A", "A2"],
                                //	"var2": ["B", "B2"],
                                //	"var3": ["https://example.com"]
                                // }
console.log(urlVariables.toString());	// will log a String: "var1=A&var1=A2&var2=B&var2=B2&var3=https%3A%2F%2Fexample.com"
</script>