twitter-screen-name

Extract a twitter screen name from a twitter URL or @username string. Return null if not valid.

Usage no npm install needed!

<script type="module">
  import twitterScreenName from 'https://cdn.skypack.dev/twitter-screen-name';
</script>

README

twitter-screen-name Build Status Dependency Status

Extract a twitter screen name from a twitter URL or @username string. Return null if not valid.

Example

var twitterScreenName = require('twitter-screen-name')

twitterScreenName('http://twitter.com/_alanshaw') // -> _alanshaw
twitterScreenName('https://www.twitter.com/_alanshaw') // -> _alanshaw
twitterScreenName('http://twitter.com/_alanshaw/status/695527644901801984') // -> _alanshaw
twitterScreenName('@_alanshaw') // -> _alanshaw
twitterScreenName('_alanshaw') // -> _alanshaw
// etc.

twitterScreenName('http://example.org/foo/') // -> null
twitterScreenName('toolongfortwitter') // -> null
// etc.