You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
745 B

7 years ago
  1. Join all arguments together and normalize the resulting url.
  2. ## Install
  3. ~~~
  4. npm install url-join
  5. ~~~
  6. ## Usage
  7. ~~~javascript
  8. var urljoin = require('url-join');
  9. var fullUrl = urljoin('http://www.google.com', 'a', '/b/cd', '?foo=123');
  10. console.log(fullUrl);
  11. ~~~
  12. Prints:
  13. ~~~
  14. 'http://www.google.com/a/b/cd?foo=123'
  15. ~~~
  16. ## Browser and AMD
  17. It also works in the browser, you can either include ```lib/url-join.js``` in your page:
  18. ~~~html
  19. <script src="url-join.js"></script>
  20. <script type="text/javascript">
  21. urljoin('http://blabla.com', 'foo?a=1')
  22. </script>
  23. ~~~
  24. Or using an AMD module system like requirejs:
  25. ~~~javascript
  26. define(['path/url-join.js'], function (urljoin) {
  27. urljoin('http://blabla.com', 'foo?a=1');
  28. });
  29. ~~~
  30. ## License
  31. MIT