Projekt

Obecné

Profil

Stáhnout (1.75 KB) Statistiky
| Větev: | Revize:
1 3a515b92 cagy
# origin(al)
2
3
[![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)
4
5
Original generates the origin URL for a given URL or URL object. In addition to
6
that it also comes with a simple `same` function to check if two URL's have the
7
same origin.
8
9
## Install
10
11
This module is browserify and node compatible and is therefor release in the npm
12
registry and can be installed using:
13
14
```
15
npm install --save original
16
```
17
18
## Usage
19
20
In all the examples we assume that the module is loaded using:
21
22
```js
23
'use strict';
24
25
var origin = require('original');
26
```
27
28
To get the origin of a given URL simply call `origin` function with any given
29
URL to get origin.
30
31
```js
32
var o = origin('https://google.com/foo/bar?path');
33
34
// o = https://google.com
35
```
36
37
To compare if two URL's share the same origin you can call the `same` method.
38
39
```js
40
if (origin.same('https://google.com/foo', 'https://primus.io')) {
41
  console.log('same');
42
} else {
43
  console.log('guess what, google.com and primus.io are not the same origin');
44
}
45
```
46
47
And that's it.
48
49
## License
50
51
MIT