pax_global_header00006660000000000000000000000064126147010570014515gustar00rootroot0000000000000052 comment=ee5fb8a2bad22c67a64337897e0505d94cb23b6b original-1.0.0/000077500000000000000000000000001261470105700133175ustar00rootroot00000000000000original-1.0.0/.gitignore000066400000000000000000000000441261470105700153050ustar00rootroot00000000000000node_modules coverage npm-debug.log original-1.0.0/.travis.yml000066400000000000000000000005251261470105700154320ustar00rootroot00000000000000sudo: false language: node_js node_js: - "4" - "iojs" - "0.12" - "0.10" script: - "npm run test-travis" after_script: - "npm install coveralls@2 && cat coverage/lcov.info | coveralls" matrix: fast_finish: true notifications: irc: channels: - "irc.freenode.org#unshift" on_success: change on_failure: change original-1.0.0/LICENSE000066400000000000000000000021331261470105700143230ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2015 Unshift.io, Arnout Kazemier, the Contributors. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. original-1.0.0/README.md000066400000000000000000000033731261470105700146040ustar00rootroot00000000000000# origin(al) [![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) Original generates the origin URL for a given URL or URL object. In addition to that it also comes with a simple `same` function to check if two URL's have the same origin. ## Install This module is browserify and node compatible and is therefor release in the npm registry and can be installed using: ``` npm install --save original ``` ## Usage In all the examples we assume that the module is loaded using: ```js 'use strict'; var origin = require('original'); ``` To get the origin of a given URL simply call `origin` function with any given URL to get origin. ```js var o = origin('https://google.com/foo/bar?path'); // o = https://google.com ``` To compare if two URL's share the same origin you can call the `same` method. ```js if (origin.same('https://google.com/foo', 'https://primus.io')) { console.log('same'); } else { console.log('guess what, google.com and primus.io are not the same origin'); } ``` And that's it. ## License MIT original-1.0.0/index.js000066400000000000000000000020221261470105700147600ustar00rootroot00000000000000'use strict'; var parse = require('url-parse'); /** * Transform an URL to a valid origin value. * * @param {String|Object} url URL to transform to it's origin. * @returns {String} The origin. * @api public */ function origin(url) { if ('string' === typeof url) url = parse(url); // // 6.2. ASCII Serialization of an Origin // http://tools.ietf.org/html/rfc6454#section-6.2 // if (!url.protocol || !url.hostname) return 'null'; // // 4. Origin of a URI // http://tools.ietf.org/html/rfc6454#section-4 // // States that url.scheme, host should be converted to lower case. This also // makes it easier to match origins as everything is just lower case. // return (url.protocol +'//'+ url.host).toLowerCase(); } /** * Check if the origins are the same. * * @param {String} a URL or origin of a. * @param {String} b URL or origin of b. * @returns {Boolean} * @api public */ origin.same = function same(a, b) { return origin(a) === origin(b); }; // // Expose the origin // module.exports = origin; original-1.0.0/package.json000066400000000000000000000015201261470105700156030ustar00rootroot00000000000000{ "name": "original", "version": "1.0.0", "description": "Generate the origin from an URL or check if two URL/Origins are the same", "main": "index.js", "scripts": { "100%": "istanbul check-coverage --statements 100 --functions 100 --lines 100 --branches 100", "test-travis": "istanbul cover _mocha --report lcovonly -- test.js", "coverage": "istanbul cover _mocha -- test.js", "watch": "mocha --watch test.js", "test": "mocha test.js" }, "repository": { "type": "git", "url": "https://github.com/unshiftio/original" }, "keywords": [ "origin", "url", "parse" ], "author": "Arnout Kazemier", "license": "MIT", "dependencies": { "url-parse": "1.0.x" }, "devDependencies": { "assume": "1.3.x", "istanbul": "0.4.x", "mocha": "2.3.x", "pre-commit": "1.1.x" } } original-1.0.0/test.js000066400000000000000000000050101261470105700146300ustar00rootroot00000000000000describe('original', function () { 'use strict'; var parse = require('url-parse') , assume = require('assume') , origin = require('./') , same = origin.same; it('is exposed as a function', function () { assume(origin).is.a('function'); }); it('also accepts objects instead of strings', function () { var o = origin(parse('http://google.com:80/pathname')); assume(o).equals('http://google.com'); }); it('also accepts origins as origin', function () { var o = origin('http://google.com:80/pathname'); assume(origin(o)).equals(o); }); it('lowercases the origin', function () { var o = origin('hTtp://WwW.ExAMPLE.cOM:8080'); assume(o).equals('http://www.example.com:8080'); o = origin('https://www.EXAMPLE.com:8080'); assume(o).equals('https://www.example.com:8080'); o = origin('HTTPS://WWW.example.COM:8080'); assume(o).equals('https://www.example.com:8080'); }); it('returns "null" if the protocol is not specified', function () { var o = origin('www.example.com'); assume(o).equals('null'); }); it('returns "null" if the hostname is not specified', function () { var o = origin('http://'); assume(o).equals('null'); }); it('removes default ports for http', function () { var o = origin('http://google.com:80/pathname'); assume(o).equals('http://google.com'); o = origin('http://google.com:80'); assume(o).equals('http://google.com'); o = origin('http://google.com'); assume(o).equals('http://google.com'); o = origin('https://google.com:443/pathname'); assume(o).equals('https://google.com'); o = origin('http://google.com:443/pathname'); assume(o).equals('http://google.com:443'); o = origin('https://google.com:80/pathname'); assume(o).equals('https://google.com:80'); o = origin('file://google.com/pathname'); assume(o).equals('file://google.com'); }); it('removes default ports for ws', function () { var o = origin('ws://google.com:80/pathname'); assume(o).equals('ws://google.com'); o = origin('wss://google.com:443/pathname'); assume(o).equals('wss://google.com'); o = origin('ws://google.com:443/pathname'); assume(o).equals('ws://google.com:443'); o = origin('wss://google.com:80/pathname'); assume(o).equals('wss://google.com:80'); }); describe('.same', function () { assume(origin.same).is.a('function'); it('equals', function () { assume(same('http://google.com', 'http://google.com:80')).is.true(); }); }); });