probably-china 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/README.md +13 -0
- package/index.d.ts +7 -0
- package/index.js +14 -0
- package/package.json +13 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-PRESENT Mu-Tsun Tsai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
|
|
2
|
+
# probably-china
|
|
3
|
+
|
|
4
|
+
> A lucky guess that we are probably in China or facing a Chinese user.
|
|
5
|
+
|
|
6
|
+
This is a simple package for the browser environment that makes a quick guess
|
|
7
|
+
to see if the current webpage is running in China, or if the user is from China,
|
|
8
|
+
based on the available browser info. It currently uses two strategies:
|
|
9
|
+
|
|
10
|
+
1. Check if the current browser favors simplified Chinese or related languages.
|
|
11
|
+
2. Check if the current timezone is one of the Chinese timezones.
|
|
12
|
+
|
|
13
|
+
The use case for this package is not to avoid showing information that are sensitive in China.
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
const detectChinaLanguage = ["zh-CN", "zh-CHS", "zh-Hans", "zh-HK", "zh-MO"];
|
|
3
|
+
const detectChinaTimeZone = ["Asia/Shanghai", "Asia/Urumqi", "Asia/Hong_Kong", "Asia/Macau"];
|
|
4
|
+
const timeZone = new Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A lucky guess that we are probably in China or facing a Chinese user.
|
|
8
|
+
*/
|
|
9
|
+
export const probablyChina =
|
|
10
|
+
detectChinaTimeZone.includes(timeZone) ||
|
|
11
|
+
detectChinaLanguage.includes(navigator.language) ||
|
|
12
|
+
navigator.languages.some(l => detectChinaLanguage.includes(l));
|
|
13
|
+
|
|
14
|
+
export default probablyChina;
|
package/package.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "probably-china",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A lucky guess that we are probably in China or facing a Chinese user.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"China"
|
|
9
|
+
],
|
|
10
|
+
"author": "Mu-Tsun Tsai <don.m.t.tsai@gmail.com> (https://github.com/MuTsunTsai)",
|
|
11
|
+
"repository": "github:MuTsunTsai/probably-china",
|
|
12
|
+
"license": "MIT"
|
|
13
|
+
}
|