Parse nested URL query into object, and parse object into readable JSON string
This parses URL path and search query only, without protocol, hostname and hash
$ npm i @9r3i/parser
const { parser }=require('@9r3i/parser');
const parse=new parser;
let query="?test=testing&tos[satu]=tis&tos[dua][belas][lima]=dua-belas&tos[dua][puluh]=tes&trust=believe",
url="/posting/pertama-kali.html"+query;
console.log(parse.likeJSON({
parser:parse,
url:parse.parseURL(url),
},9));
{
"parser": {
"version": "1.2.0",
"parseURL" : "[function]",
"parseQuery" : "[function]",
"parseQueryKey" : "[function]",
"parseJSON" : "[function]",
"objectLength" : "[function]"
},
"url": {
"path": "/posting/pertama-kali.html",
"query": {
"test": "testing",
"tos": {
"satu": "tis",
"dua": {
"belas": {
"lima": "dua-belas"
},
"puluh": "tes"
}
},
"trust": "believe"
}
}
}
<script src="https://9r3i.github.io/parser.js/parser.js"></script>
let query="?test=testing&tos[satu]=tis&tos[dua][belas][lima]=dua-belas&tos[dua][puluh]=tes&trust=believe",
url="/posting/pertama-kali.html"+query,
parse=new parser,
parsed=parse.likeJSON({
parser:parse,
url:parse.parseURL(url),
},9),
pre=document.createElement('pre');
document.body.appendChild(pre);
pre.textContent=parsed;
{
"parser": {
"version": "1.2.0",
"parseURL" : "[function]",
"parseQuery" : "[function]",
"parseQueryKey" : "[function]",
"parseJSON" : "[function]",
"objectLength" : "[function]"
},
"url": {
"path": "/posting/pertama-kali.html",
"query": {
"test": "testing",
"tos": {
"satu": "tis",
"dua": {
"belas": {
"lima": "dua-belas"
},
"puluh": "tes"
}
},
"trust": "believe"
}
}
}
This parses a URL string only path and search query, without protocol, hostname and hash.
Parameters:
url
string of URL path and search query, without protocol, hostname and hash
Parse nested URL query string of search query without question mark.
Parameters:
query
string of URL search query, without question mark
Parse query keys recursively.
Parameters:
object
object of default inputkeys
array of URL query keysvalue
mixed of object value to the targetcounter
int of counter; auto-generate, default: 0
Parse object into readable string JSON.
Parameters:
object
mixed of objectlimit
int of nested limit; default: 1space
int of space count between lines; initial: 0pad
int of padding white-space per lines; default: 2
Calculate object length.
Parameters:
object
object of countable object
That's all there is to it. Alhamdulillaah...
Since January 18th 2023 |