Skip to content

Commit b7a0796

Browse files
committed
support parse github tarballs url. close #2
1 parent f90ee68 commit b7a0796

8 files changed

+144
-13
lines changed

.jshintignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/
2+
coverage/
3+
.tmp/
4+
.git/

.jshintrc

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
{
2+
// JSHint Default Configuration File (as on JSHint website)
3+
// See http://jshint.com/docs/ for more details
4+
5+
"maxerr" : 50, // {int} Maximum error before stopping
6+
7+
// Enforcing
8+
"bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.)
9+
"camelcase" : false, // true: Identifiers must be in camelCase
10+
"curly" : true, // true: Require {} for every new block or scope
11+
"eqeqeq" : true, // true: Require triple equals (===) for comparison
12+
"forin" : false, // true: Require filtering for..in loops with obj.hasOwnProperty()
13+
"immed" : false, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());`
14+
"indent" : false, // {int} Number of spaces to use for indentation
15+
"latedef" : false, // true: Require variables/functions to be defined before being used
16+
"newcap" : false, // true: Require capitalization of all constructor functions e.g. `new F()`
17+
"noarg" : true, // true: Prohibit use of `arguments.caller` and `arguments.callee`
18+
"noempty" : true, // true: Prohibit use of empty blocks
19+
"nonew" : false, // true: Prohibit use of constructors for side-effects (without assignment)
20+
"plusplus" : false, // true: Prohibit use of `++` & `--`
21+
"quotmark" : false, // Quotation mark consistency:
22+
// false : do nothing (default)
23+
// true : ensure whatever is used is consistent
24+
// "single" : require single quotes
25+
// "double" : require double quotes
26+
"undef" : true, // true: Require all non-global variables to be declared (prevents global leaks)
27+
"unused" : false, // true: Require all defined variables be used
28+
"strict" : true, // true: Requires all functions run in ES5 Strict Mode
29+
"trailing" : false, // true: Prohibit trailing whitespaces
30+
"maxparams" : false, // {int} Max number of formal params allowed per function
31+
"maxdepth" : false, // {int} Max depth of nested blocks (within functions)
32+
"maxstatements" : false, // {int} Max number statements per function
33+
"maxcomplexity" : false, // {int} Max cyclomatic complexity per function
34+
"maxlen" : false, // {int} Max number of characters per line
35+
36+
// Relaxing
37+
"asi" : false, // true: Tolerate Automatic Semicolon Insertion (no semicolons)
38+
"boss" : true, // true: Tolerate assignments where comparisons would be expected
39+
"debug" : false, // true: Allow debugger statements e.g. browser breakpoints.
40+
"eqnull" : false, // true: Tolerate use of `== null`
41+
"es5" : false, // true: Allow ES5 syntax (ex: getters and setters)
42+
"esnext" : true, // true: Allow ES.next (ES6) syntax (ex: `const`)
43+
"moz" : false, // true: Allow Mozilla specific syntax (extends and overrides esnext features)
44+
// (ex: `for each`, multiple try/catch, function expression…)
45+
"evil" : false, // true: Tolerate use of `eval` and `new Function()`
46+
"expr" : true, // true: Tolerate `ExpressionStatement` as Programs
47+
"funcscope" : false, // true: Tolerate defining variables inside control statements"
48+
"globalstrict" : false, // true: Allow global "use strict" (also enables 'strict')
49+
"iterator" : false, // true: Tolerate using the `__iterator__` property
50+
"lastsemic" : false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block
51+
"laxbreak" : true, // true: Tolerate possibly unsafe line breakings
52+
"laxcomma" : false, // true: Tolerate comma-first style coding
53+
"loopfunc" : false, // true: Tolerate functions being defined in loops
54+
"multistr" : true, // true: Tolerate multi-line strings
55+
"proto" : false, // true: Tolerate using the `__proto__` property
56+
"scripturl" : false, // true: Tolerate script-targeted URLs
57+
"smarttabs" : false, // true: Tolerate mixed tabs/spaces when used for alignment
58+
"shadow" : true, // true: Allows re-define variables later in code e.g. `var x=1; x=2;`
59+
"sub" : false, // true: Tolerate using `[]` notation when it can still be expressed in dot notation
60+
"supernew" : false, // true: Tolerate `new function () { ... };` and `new Object;`
61+
"validthis" : true, // true: Tolerate using this in a non-constructor function
62+
63+
// Environments
64+
"browser" : true, // Web Browser (window, document, etc)
65+
"couch" : false, // CouchDB
66+
"devel" : true, // Development/debugging (alert, confirm, etc)
67+
"dojo" : false, // Dojo Toolkit
68+
"jquery" : false, // jQuery
69+
"mootools" : false, // MooTools
70+
"node" : true, // Node.js
71+
"nonstandard" : false, // Widely adopted globals (escape, unescape, etc)
72+
"prototypejs" : false, // Prototype and Scriptaculous
73+
"rhino" : false, // Rhino
74+
"worker" : false, // Web Workers
75+
"wsh" : false, // Windows Scripting Host
76+
"yui" : false, // Yahoo User Interface
77+
"noyield" : true, // allow generators without a yield
78+
79+
// Legacy
80+
"nomen" : false, // true: Prohibit dangling `_` in variables
81+
"onevar" : false, // true: Allow only one `var` statement per function
82+
"passfail" : false, // true: Stop on first error
83+
"white" : false, // true: Check against strict whitespace and indentation rules
84+
85+
// Custom Globals
86+
"globals" : { // additional predefined global variables
87+
// mocha
88+
"describe": true,
89+
"it": true,
90+
"before": true,
91+
"afterEach": true,
92+
"beforeEach": true,
93+
"after": true
94+
}
95+
}

.npmignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ coverage.html
33
Makefile
44
.travis.yml
55
logo.png
6+
.jshint*

Makefile

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@ MOCHA_OPTS =
66
install:
77
@npm install --registry=http://registry.cnpmjs.org
88

9+
jshint: install
10+
@./node_modules/.bin/jshint .
11+
912
test: install
1013
@NODE_ENV=test ./node_modules/.bin/mocha \
1114
--reporter $(REPORTER) \
1215
--timeout $(TIMEOUT) \
1316
$(MOCHA_OPTS) \
1417
$(TESTS)
1518

16-
test-cov:
19+
test-cov cov:
1720
@$(MAKE) test MOCHA_OPTS='--require blanket' REPORTER=html-cov | ./node_modules/.bin/cov
1821

1922
test-coveralls: test
@@ -30,4 +33,3 @@ contributors: install
3033
@./node_modules/.bin/contributors -f plain -o AUTHORS
3134

3235
.PHONY: test
33-

README.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
giturl
22
=======
33

4-
[![Build Status](https://secure.travis-ci.org/fengmk2/giturl.png)](http://travis-ci.org/fengmk2/giturl) [![Coverage Status](https://coveralls.io/repos/fengmk2/giturl/badge.png)](https://coveralls.io/r/fengmk2/giturl) [![Dependency Status](https://gemnasium.com/fengmk2/giturl.png)](https://gemnasium.com/fengmk2/giturl)
4+
[![Build Status](https://secure.travis-ci.org/repo-utils/giturl.png)](http://travis-ci.org/repo-utils/giturl)
5+
6+
[![Coverage Status](https://coveralls.io/repos/repo-utils/giturl/badge.png)](https://coveralls.io/r/repo-utils/giturl)
7+
8+
[![Dependency Status](https://gemnasium.com/repo-utils/giturl.png)](https://gemnasium.com/repo-utils/giturl)
59

610
[![NPM](https://nodei.co/npm/giturl.png?downloads=true&stars=true)](https://nodei.co/npm/giturl/)
711

8-
![logo](https://raw.github.com/fengmk2/giturl/master/logo.png)
12+
![logo](https://raw.github.com/repo-utils/giturl/master/logo.png)
913

1014
Transfer git url to web url.
1115

@@ -40,6 +44,9 @@ giturl.parse('[email protected]:cnpm/cnpm.git');
4044

4145
giturl.parse('[email protected]:fengmk2/cnpm.git');
4246
// => http://gitcafe.com/fengmk2/cnpm
47+
48+
giturl.parse('http://github.com/component/emitter/archive/1.0.1.tar.gz')
49+
// => https://github.com/component/emitter
4350
```
4451

4552
## License

lib/giturl.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,8 @@ exports.parse = function parse(sourceURL) {
4141

4242
var host = item[1];
4343
var protocol = HTTPS_HOSTS[host] ? 'https' : 'http';
44-
return protocol + '://' + host + '/' + item[2];
44+
45+
// p1/p2/.../pn[.xxx]
46+
var url = item[2].split('/', 2).join('/');
47+
return protocol + '://' + host + '/' + url;
4548
};

package.json

+9-8
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,24 @@
1919
},
2020
"devDependencies": {
2121
"autod": "*",
22-
"contributors": "*",
23-
"should": "*",
2422
"blanket": "*",
25-
"travis-cov": "*",
23+
"contributors": "*",
2624
"cov": "*",
2725
"coveralls": "*",
26+
"jshint": "*",
27+
"mocha": "*",
2828
"mocha-lcov-reporter": "*",
29-
"mocha": "*"
29+
"should": "3.3.1",
30+
"travis-cov": "*"
3031
},
31-
"homepage": "https://github.com/fengmk2/giturl",
32+
"homepage": "https://github.com/repo-utils/giturl",
3233
"repository": {
3334
"type": "git",
34-
"url": "git://github.com/fengmk2/giturl.git",
35-
"web": "https://github.com/fengmk2/giturl"
35+
"url": "git://github.com/repo-utils/giturl.git",
36+
"web": "https://github.com/repo-utils/giturl"
3637
},
3738
"bugs": {
38-
"url": "https://github.com/fengmk2/giturl/issues",
39+
"url": "https://github.com/repo-utils/giturl/issues",
3940
"email": "[email protected]"
4041
},
4142
"keywords": [

test/giturl.test.js

+18
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,23 @@ describe('giturl.test.js', function () {
3939
giturl.parse('http://bauer-information-technology.com/').should.eql('http://bauer-information-technology.com/');
4040
giturl.parse('').should.eql('');
4141
});
42+
43+
it('should parse github archive url', function () {
44+
giturl.parse('http://github.com/component/emitter/archive/1.0.1.tar.gz')
45+
.should.equal('https://github.com/component/emitter');
46+
giturl.parse('http://github.com/emitter/archive/1.0.1.tar.gz')
47+
.should.equal('https://github.com/emitter/archive');
48+
giturl.parse('http://github.com/emitter/')
49+
.should.equal('https://github.com/emitter/');
50+
});
51+
52+
it('should parse gist url', function () {
53+
giturl.parse('https://gist.github.com/fengmk2/10453258')
54+
.should.equal('https://gist.github.com/fengmk2/10453258');
55+
giturl.parse('http://gist.github.com/fengmk2/10453258')
56+
.should.equal('https://gist.github.com/fengmk2/10453258');
57+
giturl.parse('http://gist.github.com/10453258.git')
58+
.should.equal('https://gist.github.com/10453258');
59+
});
4260
});
4361
});

0 commit comments

Comments
 (0)