Last change
on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 4 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.7 KB
|
Line | |
---|
1 | # origin(al)
|
---|
2 |
|
---|
3 | [](http://unshift.io)[](http://browsenpm.org/package/original)[](https://travis-ci.org/unshiftio/original)[](https://david-dm.org/unshiftio/original)[](https://coveralls.io/r/unshiftio/original?branch=master)[](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
|
---|
Note:
See
TracBrowser
for help on using the repository browser.