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.

51 lines
1.7 KiB

4 years ago
  1. # origin(al)
  2. [![Made by unshift](https://img.shields.io/badge/made%20by-unshift-00ffcc.svg?style=flat-square)](http://unshift.io)[![Version npm](http://img.shields.io/npm/v/original.svg?style=flat-square)](http://browsenpm.org/package/original)[![Build Status](http://img.shields.io/travis/unshiftio/original/master.svg?style=flat-square)](https://travis-ci.org/unshiftio/original)[![Dependencies](https://img.shields.io/david/unshiftio/original.svg?style=flat-square)](https://david-dm.org/unshiftio/original)[![Coverage Status](http://img.shields.io/coveralls/unshiftio/original/master.svg?style=flat-square)](https://coveralls.io/r/unshiftio/original?branch=master)[![IRC channel](http://img.shields.io/badge/IRC-irc.freenode.net%23unshift-00a8ff.svg?style=flat-square)](http://webchat.freenode.net/?channels=unshift)
  3. Original generates the origin URL for a given URL or URL object. In addition to
  4. that it also comes with a simple `same` function to check if two URL's have the
  5. same origin.
  6. ## Install
  7. This module is browserify and node compatible and is therefor release in the npm
  8. registry and can be installed using:
  9. ```
  10. npm install --save original
  11. ```
  12. ## Usage
  13. In all the examples we assume that the module is loaded using:
  14. ```js
  15. 'use strict';
  16. var origin = require('original');
  17. ```
  18. To get the origin of a given URL simply call `origin` function with any given
  19. URL to get origin.
  20. ```js
  21. var o = origin('https://google.com/foo/bar?path');
  22. // o = https://google.com
  23. ```
  24. To compare if two URL's share the same origin you can call the `same` method.
  25. ```js
  26. if (origin.same('https://google.com/foo', 'https://primus.io')) {
  27. console.log('same');
  28. } else {
  29. console.log('guess what, google.com and primus.io are not the same origin');
  30. }
  31. ```
  32. And that's it.
  33. ## License
  34. MIT