hbl-urls
v0.1.0
Published
A helper for Handlebars that adds URL manipulation.
Downloads
1
Readme
hbl-urls
A helper for Handlebars that adds URL manipulation. Meant to supercede helpers/handlebars-helpers
' URLs helpers.
Usage
const Handlebars = require('handlebars');
require('hbl-urls').default();
const tpl = Handlebars.compile('{{escape https://neutralis.org/neu tral is.html}}');
console.log(tpl() // result : 'https%3A%2F%2Fneutralis.org%2Fneu%20tral%20is.html'
Package documentation
{{ decodeURI uri }}
Decode an URI.
Usage : {{ decodeURI "https%3A%2F%2Fneutralis.org" }}
Result : https://neutralis.org
{{ encodeURI uri }}
Encode an URI.
Usage : {{ encodeURI "https://neutralis.org" }}
Result : https%3A%2F%2Fneutralis.org
{{ escape url }}
Escape a URL.
Usage : {{ escape "https://neutralis.org/neu tral is.html" }}
Result : https%3A%2F%2Fneutralis.org%2Fneu%20tral%20is.html
{{ stripProtocol url }}
Remove the protocol from a URL. It removes only the protocol and the trailing colon — the two trailing slashes after persist. This is done to maintain compatibility with helpers/handlebars-helpers
.
Usage : {{ stripProtocol "https://neutralis.org?q=neutralis&v=0.1.0" }}
Result : //neutralis.org?q=neutralis&v=0.1.0
{{ stripQuerystring url }}
Remove the query string from a URL.
Usage : {{ stripQuerystring "https://neutralis.org/page?q=neutralis&v=0.1.0" }}
Result : https://neutralis.org/page
{{ urlParse url }}
Parse a URL into a JSON object.
Usage : {{ urlParse "https://neutralis.org?q=neutralis" }}
Result (expanded) :
{
"protocol": "https:",
"href": "https://neutralis.org/?q=neutralis",
"host": "neutralis.org",
"hostname": "neutralis.org",
"port": "",
"pathname": "/",
"search": "?q=neutralis",
"searchParams": {"q":"neutralis"},
"hash": "",
"origin": "https://neutralis.org",
"password":"",
"username":""
}
{{ urlResolve url }}
Resolve a path to a URL.
Usage : {{ urlResolve "https://neutralis.org" "query" }}
Result : https://neutralis.org/query
{{ url_decode uri }}
Decode an URI. An alias of {{ decodeURI uri }}
.
Usage : {{ decodeURI "https%3A%2F%2Fneutralis.org" }}
Result : https://neutralis.org
{{ url_encode uri }}
Encode an URI. An alias of {{ encodeURI uri }}
.
Usage : {{ url_encode "https://neutralis.org" }}
Result : https%3A%2F%2Fneutralis.org
Acknowledgements
This package is licensed under the 3-Clause BSD licence. A copy of it can be found in the LICENSE
file in the root of the source repository and in the root of the package directory.