extract-github
Advanced tools
Comparing version
12
index.js
@@ -70,7 +70,15 @@ 'use strict'; | ||
return { user: result[1], repo: result[2] }; | ||
} else if ((result = data.split('/')) && result.length === 2) { | ||
} else if ( | ||
(result = data.split('/')) // Split by /. | ||
&& result.length === 2 // Only 2 results. | ||
&& result.every(function every(value) { // Just user/repos. | ||
return !/\s/.test(value); | ||
}) | ||
) { | ||
// | ||
// A simple user/repository based string | ||
// | ||
return { user: result[0], repo: result[1] }; | ||
return { user: result[0].trim(), repo: result[1].trim() }; | ||
} else if (!~data.indexOf(' ')) { | ||
return { user: data }; | ||
} | ||
@@ -77,0 +85,0 @@ } else if ('object' === type) { |
{ | ||
"name": "extract-github", | ||
"version": "0.0.3", | ||
"version": "0.0.5", | ||
"description": "Extract the Github project / repository URL from a given object", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -10,2 +10,18 @@ describe('extract-github', function () { | ||
// | ||
// Expose the fixtures in a readable format. | ||
// | ||
var fixture = fs.readdirSync( | ||
path.join(__dirname, 'fixture') | ||
).reduce(function reduced(memo, file) { | ||
var name = file.slice(0, -3); | ||
memo[name.replace('-', '_')] = memo[name] = fs.readFileSync( | ||
path.join(__dirname, 'fixture', file), | ||
'utf-8' | ||
); | ||
return memo; | ||
}, {}); | ||
it('exports as a function', function () { | ||
@@ -96,14 +112,26 @@ expect(extract).to.be.a('function'); | ||
it('extracts the url from the README', function () { | ||
var github = extract(fs.readFileSync(path.join(__dirname, '../README.md'), 'utf-8')); | ||
it('can default to a username', function () { | ||
var github = extract('3rd-Eden'); | ||
expect(github.user).to.equal('3rd-Eden'); | ||
expect(github.repo).to.equal('extract-github'); | ||
}); | ||
it('correctly parses the README', function () { | ||
var github = extract('Code coverage reporting is available if _instrumented_ code is detected. Currently only _instrumentation_ via [node-jscoverage](https://github.com/visionmedia/node-jscoverage) is supported. When _instrumented_ code is detected and coverage reporting is enabled using any of the `--cover-plain`, `--cover-html`, or `--cover-json` options a code coverage map is generated.'); | ||
describe('README', function () { | ||
it('extracts the url from the README', function () { | ||
var github = extract(fs.readFileSync(path.join(__dirname, '../README.md'), 'utf-8')); | ||
expect(github.user).to.equal('visionmedia'); | ||
expect(github.repo).to.equal('node-jscoverage'); | ||
expect(github.user).to.equal('3rd-Eden'); | ||
expect(github.repo).to.equal('extract-github'); | ||
}); | ||
it('correctly parses node-jsconverage\'s README', function () { | ||
var github = extract(fixture.node_jscoverage); | ||
expect(github.user).to.equal('visionmedia'); | ||
expect(github.repo).to.equal('node-jscoverage'); | ||
}); | ||
it('correctly parses assign\'s README', function () { | ||
expect(extract(fixture.assign)).to.equal(undefined); | ||
expect(extract({ readme: fixture.assign })).to.equal(undefined); | ||
}); | ||
}); | ||
@@ -110,0 +138,0 @@ |
10911
15.89%9
28.57%217
16.04%