Check if a given string is a valid Github issue label name
import validateGithubLabelName from 'validate-github-label-name';
const result = validateGithubLabelName('label🍕name🍔\n');
console.log(result.formatted);Invalid issue label name "label🍕name🍔\n":
at 5,10: Invalid characters: "🍕" and "🍔". Label name cannot have Unicode characters above 0xFFFF.
at 11: Label name cannot have linebreaks.
npm install validate-github-label-name
bower install validate-github-label-name
str: String (Github issue label name)
Return: Object
The returned object has the following properties:
Type: Boolean
Whether the string can be used as a Github issue label name.
Type: Array<Object>
Reasons why the given name is not valid. [] if the string is a valid label name.
Type: String
The human-readable description of the reason.
Type: Array<Number>
The positions in the string where invalid characters are found.
Type: String
The prettily formatted validation message.
import validateGithubLabelName from 'validate-github-label-name';
const result0 = validateGithubLabelName('enhancement');
result0.valid; //=> true
result0.reasons; //=> []
result0.formatted; //=> ''
const result1 = validateGithubLabelName('abc\n𠮷\ndef');
result1.valid;
//=> true
result1.reasons;
/* => [
{
positions: [3, 5],
message: 'Label name cannot have linebreaks.'
},
{
positions: [4],
message: 'Invalid character: "𠮷". Label name cannot have Unicode characters above 0xFFFF.'
}
] */
result1.formatted;
//=> 'Invalid issue label name "abc\\n𠮷\\ndef":\nat 3,5: Label name cannot have ...'Copyright (c) 2017 Shinnosuke Watanabe
Licensed under the MIT License.