url
const url = require('url');
const {URL} = url;
const myURL = new URL('http://www.gilbut.co.kr/book/bookList.aspx?sercate1=001001000#anchor');
console.log(myURL);
console.log('url.format() :'+url.format(myURL));
console.log('--------------------------------');
const parsedURL = url.parse('http://www.gilbut.co.kr/book/bookList.aspx?sercate1=001001000#anchor');
console.log(parsedURL);
console.log('url.format() :'+url.format(parsedURL));
searchParams
const url = require('url');
const myURL = new URL('http://www.gilbut.co.kr/?page=3&limit=10&category=nodejs&category=javascript');
console.log('searchParams:',myURL.searchParams);
console.log('searchParams.getAll() :',myURL.searchParams.getAll('category')); //key 모든 값을 가져온다.
console.log('searchParams.get() :',myURL.searchParams.get('limit')); //key 의 값을 가져온다.
console.log('searchParams.has() :',myURL.searchParams.has('page')); //해당 키가 있는지 여부.
console.log("myURL.searchParams.keys() :",myURL.searchParams.keys());
console.log("myURL.searchParams.values() :",myURL.searchParams.values());
const searchKeys = myURL.searchParams.keys();
for (const name of searchKeys) {
console.log("key:"+name);
}
myURL.searchParams.append('filter','es3');
myURL.searchParams.append('filter','es5');
console.log('searchParams.getAll() :',myURL.searchParams.getAll('filter'));
myURL.searchParams.set('filter','es6');
console.log('searchParams.getAll() :',myURL.searchParams.getAll('filter'));
myURL.searchParams.delete('filter');
console.log('searchParams.getAll() :',myURL.searchParams.getAll('filter'));
console.log('myURL.searchParams.toString() :',myURL.searchParams.toString());
myURL.search = myURL.searchParams.toString();
console.log(myURL);