cube-country-detector

obtains country code for broswer user

Usage no npm install needed!

<script type="module">
  import cubeCountryDetector from 'https://cdn.skypack.dev/cube-country-detector';
</script>

README

用于cubetv官网项目确定用户国家码,以上报后台获取更本地化的推荐服务 注意: 需要进行归类的国家已在包内部声明,日后新增需要服务的国家也会在包中更新,若获取到的国家不在该列表中,返回'ALL', 否则返回对应的国家码

一般用法(大多数情况下) import countryDetector from 'cube-country-detector';

var detector = new countryDetector(); var country_code = detecor.getCountry(); var country_code = detecor.getCountryByIP(function(country_code){}); //若识别到的国家在包中默认的国家列表内,则返回对应的国家码, 否则返回'ALL'

特殊情况 Q & A 1.如果某种场景,我只需要获取自己指定几个国家在内的国家码,而不需要完整的默认国家列表 import countryDetector from 'cube-country-detector';

var detector2 = new countrDetector({ country_list: ['ID', 'VN', 'TH'] }) var country_code = detector2.getCountry(); // 此时只有判断为 country_list中的三个国家才会返回对应的国家码,否则返回'ALL'

版本更改 1.0.1 增加了 根据IP地址判断国家

1.0.2 更换了获取国家码的ajax地址,原来那个地址停止维护了

1.0.3 增加 土耳其 国家判断