fuc-new/doc/node_modules/@vuepress/plugin-git/lib/node/utils/checkGithubUsername.js
hellcat 6adbc04d4b 1
2025-10-03 17:17:08 +08:00

17 lines
492 B
JavaScript

/**
* Check if the username is a valid github username
*
* - length <= 39
* - starts with a letter
* - contains only letters, numbers, and hyphens
* - does not start or end with a hyphen
* - does not contain consecutive hyphens
*/
export const checkGithubUsername = (username) => {
if (username.length > 39)
return false;
if (username.startsWith('-') || username.endsWith('-'))
return false;
return /^[a-z\d](?:[a-z\d]|-(?=[a-z\d]))*$/i.test(username);
};