Skip to content

Commit 449af99

Browse files
committed
.
0 parents  commit 449af99

File tree

10 files changed

+236
-0
lines changed

10 files changed

+236
-0
lines changed

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
[*.md]
13+
trim_trailing_whitespace = false

.eslintrc

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"env": {
3+
"node": true
4+
},
5+
"rules": {
6+
// warnings
7+
"no-unused-expressions": 1,
8+
"no-warning-comments": 1,
9+
"no-native-reassign": 1,
10+
"no-invalid-regexp": 1,
11+
"no-debugger": 1,
12+
"no-console": 1,
13+
"no-empty": 1,
14+
"radix": 1,
15+
16+
// errors
17+
"no-shadow-restricted-names": 2,
18+
"handle-callback-err": 2,
19+
"no-self-compare": 2,
20+
"no-empty-class": 2,
21+
"no-unused-vars": 2,
22+
"no-dupe-keys": 2,
23+
"valid-typeof": 2,
24+
"no-undef": 2,
25+
26+
// stylistic errors
27+
"quotes": [2, "single", "avoid-escape"],
28+
"no-space-before-semi": 2,
29+
"space-unary-word-ops": 2,
30+
"no-spaced-func": 2,
31+
"yoda": "always",
32+
"new-cap": 2,
33+
34+
// mute
35+
"no-use-before-define": 0,
36+
"eol-last": 0,
37+
"strict": 0,
38+
"eqeqeq": 0,
39+
"curly": 0
40+
}
41+
}

.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# tmp files
2+
lib-cov
3+
*.seed
4+
*.log
5+
*.csv
6+
*.dat
7+
*.out
8+
*.pid
9+
*.gz
10+
11+
# tmp folders
12+
pids/
13+
logs/
14+
results/
15+
coverage/
16+
17+
# node.js
18+
node_modules/
19+
npm-debug.log
20+
21+
# osx
22+
.DS_Store

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_js:
2+
- "0.10"
3+
- "0.11"
4+
language: node_js
5+
script: "make test-travis"
6+
after_script: "npm install coveralls@2 && cat ./coverage/lcov.info | coveralls"

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2014
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
SRC = index.js
2+
3+
include node_modules/make-lint/index.mk
4+
5+
LINT_CONFIG = .eslintrc
6+
TESTS = test.js
7+
8+
test: lint
9+
@NODE_ENV=test ./node_modules/.bin/mocha \
10+
$(TESTS) \
11+
--bail
12+
13+
test-cov:
14+
@NODE_ENV=test node \
15+
node_modules/.bin/istanbul cover \
16+
./node_modules/.bin/_mocha \
17+
-- -u exports \
18+
$(TESTS) \
19+
--bail
20+
21+
test-travis:
22+
@NODE_ENV=test node \
23+
node_modules/.bin/istanbul cover \
24+
./node_modules/.bin/_mocha \
25+
--report lcovonly \
26+
-- -u exports \
27+
$(TESTS) \
28+
--bail
29+
30+
.PHONY: test

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# regex-username
2+
[![NPM version][npm-image]][npm-url]
3+
[![build status][travis-image]][travis-url]
4+
[![Test coverage][coveralls-image]][coveralls-url]
5+
[![Downloads][downloads-image]][downloads-url]
6+
7+
Regular expression for usernames.
8+
9+
## Installation
10+
```bash
11+
npm install regex-username
12+
```
13+
14+
## Usage
15+
```js
16+
var regex = require('regex-username');
17+
18+
regex().test('tobi-ferret');
19+
// => true
20+
```
21+
22+
## Why?
23+
Which usernames to allow typically varies between applications. For prototypes
24+
however it's nice to have an off the shelf solution. This module is that
25+
solution. It follows the same rules GitHub uses:
26+
> Username may only contain alphanumeric characters or dashes and cannot begin
27+
with a dash
28+
29+
## See Also
30+
- [regex-email](https://github.com/regexps/email)
31+
32+
## License
33+
[MIT](https://tldrlegal.com/license/mit-license)
34+
35+
[npm-image]: https://img.shields.io/npm/v/regex-username.svg?style=flat-square
36+
[npm-url]: https://npmjs.org/package/regex-username
37+
[travis-image]: https://img.shields.io/travis/regexps/regex-username.svg?style=flat-square
38+
[travis-url]: https://travis-ci.org/regexps/regex-username
39+
[coveralls-image]: https://img.shields.io/coveralls/regexps/regex-username.svg?style=flat-square
40+
[coveralls-url]: https://coveralls.io/r/regexps/regex-username?branch=master
41+
[downloads-image]: http://img.shields.io/npm/dm/regex-username.svg?style=flat-square
42+
[downloads-url]: https://npmjs.org/package/regex-username

index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Expose username regex.
3+
*
4+
* Example input:
5+
* tobi
6+
* tobi-ferret
7+
* tobino---ferret--
8+
*/
9+
module.exports = function() {
10+
return /^\w[\w-]+$/;
11+
};

package.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "regex-username",
3+
"version": "1.0.0",
4+
"description": "Regular expression for usernames",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "make test"
8+
},
9+
"repository": "regexps/regex-username",
10+
"keywords": [
11+
"regular expression",
12+
"regex",
13+
"regexp",
14+
"user",
15+
"username"
16+
],
17+
"license": "MIT",
18+
"dependencies": {},
19+
"devDependencies": {
20+
"istanbul": "^0.3.5",
21+
"make-lint": "^1.0.1",
22+
"mocha": "^2.0.1"
23+
},
24+
"files": [
25+
"LICENSE",
26+
"index.js",
27+
"README.md"
28+
]
29+
}

test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Module dependencies
3+
*/
4+
var assert = require('assert');
5+
var regex = require('./');
6+
7+
/**
8+
* Test
9+
*/
10+
describe('username regex', function() {
11+
it('should match username input', function() {
12+
assert.equal(regex().test('tobi3'), true);
13+
assert.equal(regex().test('tobi-ferret'), true);
14+
assert.equal(regex().test('3tobi--ferret'), true);
15+
});
16+
17+
it('should catch incorrect input', function() {
18+
assert.equal(regex().test('-hello'), false);
19+
assert.equal(regex().test('~~derp@darp-----++asdfasdf'), false);
20+
});
21+
});

0 commit comments

Comments
 (0)