Files
RSSHub/lib/utils/valid-host.ts
T
Tony 75d43dd086 chore: add eslint-plugin-regexp (#22189)
* chore: add eslint-plugin-regexp

* chore: autofix

* chore: fix no-useless-flag

* chore: fix optimal-lookaround-quantifier

* chore: fix no-lazy-ends

* chore: fix no-contradiction-with-assertion

* chore: fix no-useless-assertions

* chore: fix no-useless-quantifier

* chore: fix remaining regexp issues

* fix: regex for WFU news link validation
2026-06-05 20:04:39 +08:00

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 };