RSSHub/lib/utils/valid-host.ts

15 lines
349 B
TypeScript

/**
* Check if a sub-domain is valid
* @param {String} hostname sub-domain
* @returns {Boolean} true if valid
*/
const isValidHost = (hostname?: string) => {
if (typeof hostname !== 'string') {
return false;
}
const regex = /^[\dA-Z](?:[\dA-Z-]{0,61}[\dA-Z])?$/i;
return regex.test(hostname);
};
export { isValidHost };