strip-www
v3.0.0
Published
Remove a "www" subdomain from a hostname.
Readme
strip-www

Remove a "www" subdomain from a hostname.
[!NOTE]
This library uses a rather complex algorithm for parsing hostnames, which can result in bundled file sizes that are larger than you might expect. If all you want is a simple RegExp, use a
1.xrelease; but first read about its edge cases.
Install
npm install strip-wwwUsage
import stripWWW from 'strip-www';
stripWWW('www.domain.com'); //-> 'domain.com'
stripWWW('www.www.domain.com'); //-> 'www.www.domain.com'
stripWWW('www.unlisted-tld'); //-> 'www.unlisted-tld'
stripWWW('www.www.domain.com', true); //-> 'www.domain.com'The hostname must be Punycode encoded, as provided by a URL:
stripWWW('www.ᄯᄯᄯ.com'); //-> 'www.ᄯᄯᄯ.com'
const url = new URL('http://www.ᄯᄯᄯ.com');
stripWWW(url.hostname); //-> 'xn--brdaa.com'If necessary, you can decode after with punycode:
import { toUnicode } from 'punycode';
toUnicode('xn--brdaa.com'); //-> 'ᄯᄯᄯ.com'