Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
elicwhite committed Apr 4, 2016
0 parents commit e3dee03
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["es2015"]
}
7 changes: 7 additions & 0 deletions .eslintrc
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
}
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
npm-debug.log
9 changes: 9 additions & 0 deletions .jscsrc
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
}
}
10 changes: 10 additions & 0 deletions .yo-rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"generator-wf-npm": {
"prompts": {
"packageName": "clean-git-ref",
"targetEnv": [
"Node"
]
}
}
}
27 changes: 27 additions & 0 deletions README.md
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
```
9 changes: 9 additions & 0 deletions lib/index.js
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;
28 changes: 28 additions & 0 deletions package.json
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"
}
}
9 changes: 9 additions & 0 deletions src/index.js
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;
5 changes: 5 additions & 0 deletions test/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"env": {
"mocha": true
}
}
9 changes: 9 additions & 0 deletions test/js/setup.js
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");
};
5 changes: 5 additions & 0 deletions test/mocha.opts
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
34 changes: 34 additions & 0 deletions test/src-test/index_test.js
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');
});
});

0 comments on commit e3dee03

Please sign in to comment.