-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e3dee03
Showing
13 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["es2015"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "./node_modules/wealthfront-javascript/.eslintrc", | ||
"parser": "babel-eslint", | ||
"env": { | ||
"node": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
npm-debug.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"plugins": ["wealthfront-javascript"], | ||
"preset": "wealthfront-javascript", | ||
"esnext": true, | ||
"validateQuoteMarks": { | ||
"mark": "'", | ||
"escape": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"generator-wf-npm": { | ||
"prompts": { | ||
"packageName": "clean-git-ref", | ||
"targetEnv": [ | ||
"Node" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# clean-git-ref | ||
|
||
Clean an input string into a usable git ref. | ||
|
||
For more reference, read https://git-scm.com/docs/git-check-ref-format | ||
|
||
## Installation | ||
|
||
```sh | ||
$ npm install clean-git-ref --save-dev | ||
``` | ||
|
||
## API Usage | ||
|
||
### clean(string input) -> string output | ||
``` | ||
var cleanGitRef = require('clean-git-ref'); | ||
assert.stricEqual(cleanGitRef.clean('bad git ref formats/'), bad-git-ref-formats'); | ||
``` | ||
|
||
## CLI Usage | ||
|
||
```bash | ||
> clean-git-ref 'bad git ref formats/' | ||
bad-git-ref-formats | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
var CleanGitRef = { | ||
clean: function clean(value) { | ||
return value.replace(/[^0-9.]+/, ''); | ||
} | ||
}; | ||
|
||
module.exports = CleanGitRef; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "clean-git-ref", | ||
"version": "1.0.0", | ||
"license": "Apache-2.0", | ||
"author": "Eli White <github@eli-white.com>", | ||
"files": [ | ||
"lib" | ||
], | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"build": "babel src -d lib", | ||
"style": "eslint src test && jscs src test", | ||
"pretest": "npm run style", | ||
"test": "mocha", | ||
"posttest": "npm run build" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "6.6.5", | ||
"babel-eslint": "5.0.0", | ||
"babel-preset-es2015": "6.6.0", | ||
"babel-register": "^6.7.2", | ||
"chai": "3.5.0", | ||
"eslint": "1.10.3", | ||
"jscs": "2.9.0", | ||
"mocha": "2.3.4", | ||
"wealthfront-javascript": "2.4.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
const CleanGitRef = { | ||
clean(value) { | ||
return value.replace(/[^0-9.]+/, ''); | ||
} | ||
}; | ||
|
||
module.exports = CleanGitRef; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"env": { | ||
"mocha": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
var chai = require('chai'); | ||
|
||
chai.config.includeStack = true; | ||
|
||
chai.assert.equal = function() { | ||
throw new Error("Chai's assert.equal function does == instead of ===. Use assert.strictEqual instead"); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
test/js/setup.js | ||
test/src-test/**/*.js | ||
--compilers js:babel-register | ||
-R dot | ||
-u bdd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict'; | ||
|
||
const assert = require('chai').assert; | ||
const spawn = require('child_process').spawn; | ||
const cleanGitRef = require('../../src/index'); | ||
|
||
function assertValidBranchName(branchName) { | ||
const checkRefFormat = spawn('git', ['check-ref-format', 'refs/' + branchName]); | ||
|
||
return new Promise(function(resolve, reject) { | ||
checkRefFormat.on('close', (code) => { | ||
if (code === 0) { | ||
resolve(); | ||
return; | ||
} | ||
|
||
reject(); | ||
}); | ||
}); | ||
} | ||
|
||
function assertOutputAndVerifyValid(input, output) { | ||
it("should convert '" + input + "' to '" + output + "'", () => { | ||
var result = cleanGitRef.clean(input); | ||
assert.strictEqual(result, output); | ||
return assertValidBranchName(result); | ||
}); | ||
} | ||
|
||
describe('CleanGitRef', function() { | ||
describe('clean', function() { | ||
assertOutputAndVerifyValid('^0.2.3', '0.2.3'); | ||
}); | ||
}); |