npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

is-china-user

v1.0.3

Published

检查当前设备是否是中国地区的设备

Downloads

202

Readme

isChinaUser 🇨🇳

检查当前设备是否是中国地区的设备

为什么?

如果你需要在浏览器端识别中国用户或非中国用户以实现不同的逻辑,那么这个库就是为你准备的。

单纯用语言信息来判断是目前主流的方法,但这不准确,有些中国用户会使用英文系统,有些非中国用户会使用中文系统。 如果你需要更严格的判断就需要这个库了。

一个使用场景是只对中国用户显示一些内容,而屏蔽海外用户,同时尽可能的让海外的中国用户看到内容(他们可能用着当地语言的系统、时区,这通常很难判断,但我们可以判断它的设备是否是国行的)。

这个库有三个判断来源:

  • 语言信息,包括当前首选语言和备选语言(navigator.languagenavigator.languages)。
  • 时区信息,中国用户的时区一般是 Asia/Shanghai 或者 UTC 偏移为 +8 的时区。
  • 设备特征,中国大陆地区的设备有一些字符是没有的如旗帜(🇹🇼),通常这很难伪装。(Windows 无论是否是中国设备都不会国旗,所以 Windows 系统无法判断)

使用

npm i is-china-user
import { isChinaDevice, isChinaUser } from "is-china-user";

console.log(isChinaDevice()); // true or false
console.log(isChinaUser()); // true or false

方法

isChinaUser()

判断当前用户是中国用户

  • 语言(语言列表任一项出现中文)
  • 时区
  • 设备特征

三者任意满足其一即判断为中国用户

中国大陆、台湾、香港、澳门视作中国用户

isChinaUserStrict()

严格条件下判断当前用户是中国用户

  • 语言(首选语言是中文)
  • 时区
  • 设备特征

三者全都满足才判断为中国用户

如果是 Windows 系统不判断设备特征

中国大陆、台湾、香港、澳门视作中国用户

isChinaUserStrictSimplified()

严格条件下判断当前用户是中国大陆简体中文用户

如果是 Windows 系统不判断设备特征

  • 语言(首选语言是简体中文)
  • 时区
  • 设备特征

isChinaDevice()

检查当前设备是否是中国的设备

isChinaLanguage()

检查用户的语言设置是否为中文。

isChinaTimeZone()

验证当前时间区域是否为中国标准时间。