github-username-regex
Advanced tools
Comparing version 0.0.0 to 1.0.0
{ | ||
"name": "github-username-regex", | ||
"version": "0.0.0", | ||
"version": "1.0.0", | ||
"description": "A regular expression that only matches a valid Github username", | ||
@@ -5,0 +5,0 @@ "repository": "shinnn/github-username-regex", |
@@ -1,18 +0,24 @@ | ||
# append-type | ||
# github-username-regex | ||
[![NPM version](https://img.shields.io/npm/v/append-type.svg)](https://www.npmjs.com/package/append-type) | ||
[![Bower version](https://img.shields.io/bower/v/append-type.svg)](https://github.com/shinnn/append-type/releases) | ||
[![Build Status](https://travis-ci.org/shinnn/append-type.svg?branch=master)](https://travis-ci.org/shinnn/append-type) | ||
[![Coverage Status](https://img.shields.io/coveralls/shinnn/append-type.svg)](https://coveralls.io/r/shinnn/append-type) | ||
[![devDependencies Status](https://david-dm.org/shinnn/append-type/dev-status.svg)](https://david-dm.org/shinnn/append-type?type=dev) | ||
[![NPM version](https://img.shields.io/npm/v/github-username-regex.svg)](https://www.npmjs.com/package/github-username-regex) | ||
[![Bower version](https://img.shields.io/bower/v/github-username-regex.svg)](https://github.com/shinnn/github-username-regex/releases) | ||
[![Build Status](https://travis-ci.org/shinnn/github-username-regex.svg?branch=master)](https://travis-ci.org/shinnn/github-username-regex) | ||
Stringify the value with appending its [type](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/typeof): `10` → `'10 (number)'` | ||
A regular expression that only matches a valid [Github](https://github.com/) username | ||
```javascript | ||
import appendType from 'append-type'; | ||
import githubUsernameRegex from 'github-username-regex'; | ||
appendType('123'); //=> '123 (string)' | ||
appendType(123); //=> '123 (number)' | ||
githubUsernameRegex.test('john'); //=> true | ||
githubUsernameRegex.test('john-due'); //=> true | ||
githubUsernameRegex.test('john-due-'); //=> false | ||
``` | ||
According to the form validation messages on [*Join Github*](https://github.com/join) page, | ||
* Github username may only contain alphanumeric characters or hyphens. | ||
* Github username cannot have multiple consecutive hyphens. | ||
* Github username cannot begin or end with a hyphen. | ||
* Maximum is 39 characters. | ||
## Installation | ||
@@ -23,3 +29,3 @@ | ||
``` | ||
npm install append-type | ||
npm install github-username-regex | ||
``` | ||
@@ -30,3 +36,3 @@ | ||
``` | ||
bower install append-type | ||
bower install github-username-regex | ||
``` | ||
@@ -36,40 +42,31 @@ | ||
### appendType(*value*) | ||
*value*: any type | ||
Return: `String` | ||
Essentially, it returns `String(value) + ' (' + typeof value + ')'`. | ||
```javascript | ||
appendType(() => {}); //=> '() => {} (function)' | ||
import githubUsernameRegex from 'github-username-regex'; | ||
``` | ||
When it takes `null` / `undefined`, it returns `'null'` / `'undefined'`. | ||
### githubUsernameRegex | ||
```javascript | ||
appendType(null); //=> 'null' | ||
appendType(undefined); //=> 'undefined' | ||
``` | ||
Type: [`RegExp`](https://developer.mozilla.org/docs/Web/JavaScript/Guide/Regular_Expressions) (`/^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}$/i`) | ||
## Example | ||
This module is useful for making `TypeError` error messages. | ||
```javascript | ||
function reverse(v) { | ||
if (typeof v !== 'boolean') { | ||
throw new TypeError(`Expected a Boolean value, but got ${appendType(v)}.`); | ||
} | ||
// Returns `true` | ||
githubUsernameRegex.test('a'); | ||
githubUsernameRegex.test('0'); | ||
githubUsernameRegex.test('a-b'); | ||
githubUsernameRegex.test('a-b-123'); | ||
githubUsernameRegex.test('a'.repeat(39)); | ||
return !v; | ||
}; | ||
reverse(1); //=> TypeError: Expected a Boolean value, but got 1 (number). | ||
// Returns `false` | ||
githubUsernameRegex.test(''); | ||
githubUsernameRegex.test('a_b'); | ||
githubUsernameRegex.test('a--b'); | ||
githubUsernameRegex.test('a-b-'); | ||
githubUsernameRegex.test('-a-b'); | ||
githubUsernameRegex.test('a'.repeat(40)); | ||
``` | ||
Note that this module doesn't take reserved usernames into consideration. For example it matches `help`, `about` and `pricing`, though they are reserved words and cannot be used as Github usernames. | ||
## License | ||
Copyright (c) 2016 [Shinnosuke Watanabe](https://github.com/shinnn) | ||
Licensed under [the MIT License](./LICENSE). | ||
[Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/deed) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
3315
1
70