You can use libphonenumber library by Google .. Same library is used by Google in android . They have ported the same to use with js application github.com/googlei18n/libphonenumber/tree/master/… .
I'm not sure if npm module for same is available or not . But, can get most of the calculation logic and edge cases.