libj-url
v1.4.1
Published
Part of libj tools
Downloads
5
Readme
libj-url
Part of libj tools
Contains logic for parsing and manipulating urls
Usage (npm)
npm install libj-url
Example
import { urlParser } from 'libj-url'
var o = urlParser.parse('/api/authentication/login?user_name=admin&password=pass 1#anchor')
/*
returns the following object
{
protocol: 'http:' or 'https:' // based on the current url
host: 'localhost:1234' // based on the current url
hostname: 'localhost' // based on the current url
port: '1234' // based on the current url
pathname: '/api/authentication/login'
search: '?user_name=admin&password=pass 1'
query: {
'user_name': 'admin',
'password': 'pass 1'
},
hash: '#anchor'
}
*/
var urlAbsolute = o.toAbsolute()
/*
returns 'http://localhost:1234/api/authentication/login?user_name=admin&password=pass%201#anchor'
*/
var urlRelative = o.toRelative()
/*
returns '/api/authentication/login?user_name=admin&password=pass%201#anchor'
*/
var query = urlParser.parseQueryString('user_name=admin&password=pass 1');
/*
returns
{
"user_name":"admin",
"password":"pass 1"
}
*/
var search = urlParser.stringifyQueryString(query)
/*
returns 'user_name=admin&password=pass%201'
*/
Coverage tests
- Run this
npm test
Test
- Run this in a separate command line to start node server
node server.js
- Run one of the following to re-create bundles
npm run dev
npm run dev:watch
- Navigate to http://localhost:3000
Build
npm run build
npm run build:watch