[Pkg-javascript-commits] [node-original] 01/02: Imported Upstream version 1.0.0
Thorsten Alteholz
alteholz at moszumanska.debian.org
Sun Feb 14 10:26:36 UTC 2016
This is an automated email from the git hooks/post-receive script.
alteholz pushed a commit to branch master
in repository node-original.
commit 0f76556b8aa33df6cbd785912d6e16c47de5c835
Author: Thorsten Alteholz <debian at alteholz.de>
Date: Sun Feb 14 11:26:07 2016 +0100
Imported Upstream version 1.0.0
---
.gitignore | 3 ++
.travis.yml | 19 +++++++++++++
LICENSE | 22 +++++++++++++++
README.md | 51 +++++++++++++++++++++++++++++++++
index.js | 46 ++++++++++++++++++++++++++++++
package.json | 33 ++++++++++++++++++++++
test.js | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 266 insertions(+)
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..648ea07
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+node_modules
+coverage
+npm-debug.log
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..0765106
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,19 @@
+sudo: false
+language: node_js
+node_js:
+ - "4"
+ - "iojs"
+ - "0.12"
+ - "0.10"
+script:
+ - "npm run test-travis"
+after_script:
+ - "npm install coveralls at 2 && cat coverage/lcov.info | coveralls"
+matrix:
+ fast_finish: true
+notifications:
+ irc:
+ channels:
+ - "irc.freenode.org#unshift"
+ on_success: change
+ on_failure: change
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..6dc9316
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,22 @@
+The 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.
+
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..f144209
--- /dev/null
+++ b/README.md
@@ -0,0 +1,51 @@
+# 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/orig [...]
+
+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
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..3069f46
--- /dev/null
+++ b/index.js
@@ -0,0 +1,46 @@
+'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;
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..d78ec4a
--- /dev/null
+++ b/package.json
@@ -0,0 +1,33 @@
+{
+ "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"
+ }
+}
diff --git a/test.js b/test.js
new file mode 100644
index 0000000..6f7c350
--- /dev/null
+++ b/test.js
@@ -0,0 +1,92 @@
+describe('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();
+ });
+ });
+});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-original.git
More information about the Pkg-javascript-commits
mailing list