lib/extractor.js
function(text, countryCode, useGooglePhoneLib){

        const that = this,
            resultsFormatted = [];

        return new Promise(function(resolve, reject){

            const data = utils.formatString(text);
            let countryRules;

            if(_.isString(countryCode)){
                countryCode = countryCode.toUpperCase();
            }

            if(countryCode === 'AU'){
                countryRules = new locale.AU(data);
            }

            if(countryCode === 'US'){
                countryRules = new locale.US(data);
            }

            if(!countryRules){
                return reject('Unsupported county code "' + countryCode + '". Supported codes are "AU" (Australia) and "US" (United States)');
            }

            async.map(countryRules.getRules(), function(rule, cb){
                rule.run(function(result){
                    cb(null, result);
                });
            },

            function(err, results){

                results = _.flatten(results || []);

                if(useGooglePhoneLib === true){
                    _.each(results, function(n){
                        resultsFormatted.push(
                            that.formati18n(n, countryCode)
                        )
                    });

                    return resolve(resultsFormatted);
                }

                resolve(results);
            });
        });
    }
function(text, countryCode, useGooglePhoneLib){

        const that = this,
            resultsFormatted = [];

        return new Promise(function(resolve, reject){

            const data = utils.formatString(text);
            let countryRules;

            if(_.isString(countryCode)){
                countryCode = countryCode.toUpperCase();
            }

            if(countryCode === 'AU'){
                countryRules = new locale.AU(data);
            }

            if(countryCode === 'US'){
                countryRules = new locale.US(data);
            }

            if(!countryRules){
                return reject('Unsupported county code "' + countryCode + '". Supported codes are "AU" (Australia) and "US" (United States)');
            }

            async.map(countryRules.getRules(), function(rule, cb){
                rule.run(function(result){
                    cb(null, result);
                });
            },

            function(err, results){

                results = _.flatten(results || []);

                if(useGooglePhoneLib === true){
                    _.each(results, function(n){
                        resultsFormatted.push(
                            that.formati18n(n, countryCode)
                        )
                    });

                    return resolve(resultsFormatted);
                }

                resolve(results);
            });
        });
    }
function ( text , countryCode , useGooglePhoneLib ) { const that = this , resultsFormatted = [ ] ; return new Promise ( function ( resolve , reject ) { const data = utils . formatString ( text ) ; let countryRules ; if ( _ . isString ( countryCode ) ) { countryCode = countryCode . toUpperCase ( ) ; } if ( countryCode === 'AU' ) { countryRules = new locale . AU ( data ) ; } if ( countryCode === 'US' ) { countryRules = new locale . US ( data ) ; } if ( ! countryRules ) { return reject ( 'Unsupported county code "' + countryCode + '". Supported codes are "AU" (Australia) and "US" (United States)' ) ; } async . map ( countryRules . getRules ( ) , function ( rule , cb ) { rule . run ( function ( result ) { cb ( null , result ) ; } ) ; } , function ( err , results ) { results = _ . flatten ( results || [ ] ) ; if ( useGooglePhoneLib === true ) { _ . each ( results , function ( n ) { resultsFormatted . push ( that . formati18n ( n , countryCode ) ) } ) ; return resolve ( resultsFormatted ) ; } resolve ( results ) ; } ) ; } ) ; }
Returns an array of possible phone number candidates for a specific country code
@param {string} text - Text string from where the phone numbers are extracted
@param {string} countryCode - au or us
@param {boolean=} useGooglePhoneLib - When true uses Google LibPhoneNumber to format the result. https://github.com/googlei18n/libphonenumber
@return {Promise}
Returns an array of possible phone number candidates for a specific country code