string-template-format-uri

String template literal tag that converts string into valid URI/URL components

Usage no npm install needed!

<script type="module">
  import stringTemplateFormatUri from 'https://cdn.skypack.dev/string-template-format-uri';
</script>

README

String Template Format: URI

String template literal tag that converts string into valid URI/URL components

Usage

import { uri, uriComp } from 'string-template-format-uri'
const str = 'abc/def ghi'
console.log(uri`https://example.com/${str}`)
console.log(uriComp`https://example.com/${str}`)

should print:

https://example.com/abc/def%20ghi
https://example.com/abc%2Fdef%20ghi

License

MIT © Hoàng Văn Khải