[Pkg-javascript-commits] [node-url-join] 01/02: Imported Upstream version 0.0.1

Thorsten Alteholz alteholz at moszumanska.debian.org
Sun Mar 27 15:41:35 UTC 2016


This is an automated email from the git hooks/post-receive script.

alteholz pushed a commit to branch master
in repository node-url-join.

commit 096c268bc8e627b75414bd5d6570aedb04920bc2
Author: Thorsten Alteholz <debian at alteholz.de>
Date:   Sun Mar 27 17:41:33 2016 +0200

    Imported Upstream version 0.0.1
---
 .npmignore      |  2 ++
 README.md       | 27 +++++++++++++++++++++++++++
 lib/url-join.js | 12 ++++++++++++
 package.json    | 23 +++++++++++++++++++++++
 test/tests.js   | 23 +++++++++++++++++++++++
 5 files changed, 87 insertions(+)

diff --git a/.npmignore b/.npmignore
new file mode 100644
index 0000000..8ee2d2b
--- /dev/null
+++ b/.npmignore
@@ -0,0 +1,2 @@
+node_modules/*
+*.log
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..7be48c3
--- /dev/null
+++ b/README.md
@@ -0,0 +1,27 @@
+Join all arguments together and normalize the resulting url.
+
+## Install
+
+~~~
+npm install url-join
+~~~
+
+## Usage
+
+~~~javascript
+var urljoin = require('url-join');
+
+var fullUrl = urljoin('http://www.google.com', 'a', '/b/cd', '?foo=123');
+
+console.log(fullUrl);
+
+\\will print:
+
+'http://www.google.com/a/b/cd?foo=123'
+~~~
+
+This works similar to [path.join](http://nodejs.org/api/path.html#path_path_join_path1_path2) but you shouldn't use ```path.join``` for urls since it will work different depending of the operative systems but also doesn't work for some cases.
+
+## License
+
+MIT
\ No newline at end of file
diff --git a/lib/url-join.js b/lib/url-join.js
new file mode 100644
index 0000000..6b0f4fc
--- /dev/null
+++ b/lib/url-join.js
@@ -0,0 +1,12 @@
+function normalize (str) {
+  return str
+          .replace(/[\/]+/g, '/')
+          .replace(/\/\?/g, '?')
+          .replace(/\/\#/g, '#')
+          .replace(/\:\//g, '://');
+}
+
+module.exports = function () {
+  var joined = [].slice.call(arguments, 0).join('/');
+  return normalize(joined);
+};
\ No newline at end of file
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..753bea9
--- /dev/null
+++ b/package.json
@@ -0,0 +1,23 @@
+{
+  "name": "url-join",
+  "version": "0.0.1",
+  "description": "Join urls and normalize as in path.join.",
+  "main": "lib/url-join.js",
+  "scripts": {
+    "test": "mocha --require should"
+  },
+  "repository": {
+    "type": "git",
+    "url":  "git://github.com/jfromaniello/url-join.git"
+  },
+  "keywords": [
+    "url",
+    "join"
+  ],
+  "author": "José F. Romaniello <jfromaniello at gmail.com> (http://joseoncode.com)",
+  "license": "MIT",
+  "devDependencies": {
+    "should": "~1.2.1",
+    "mocha": "~1.8.1"
+  }
+}
diff --git a/test/tests.js b/test/tests.js
new file mode 100644
index 0000000..01bac51
--- /dev/null
+++ b/test/tests.js
@@ -0,0 +1,23 @@
+var urljoin = require('../lib/url-join');
+
+describe('url join', function () {
+  it('should work for simple case', function () {
+    urljoin('http://www.google.com/', 'foo/bar', '?test=123')
+      .should.eql('http://www.google.com/foo/bar?test=123');
+  });
+
+  it('should be able to join protocol', function () {
+    urljoin('http:', 'www.google.com/', 'foo/bar', '?test=123')
+      .should.eql('http://www.google.com/foo/bar?test=123');
+  });
+
+  it('should remove extra slashes', function () {
+    urljoin('http:', 'www.google.com///', 'foo/bar', '?test=123')
+      .should.eql('http://www.google.com/foo/bar?test=123');
+  });
+
+  it('should support anchors in urls', function () {
+    urljoin('http:', 'www.google.com///', 'foo/bar', '?test=123', '#faaaaa')
+      .should.eql('http://www.google.com/foo/bar?test=123#faaaaa');
+  });
+});
\ No newline at end of file

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-url-join.git



More information about the Pkg-javascript-commits mailing list