@bhxch/vviewer-detect 0.1.0 → 0.1.4

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.
Files changed (2) hide show
  1. package/README.md +48 -0
  2. package/package.json +3 -2
package/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # @bhxch/vviewer-detect
2
+
3
+ 文件级判别纯函数层:扩展名提取、magic 签名嗅探、文本性判定、shebang 语言识别、
4
+ BOM+编码检测链与 chardet 精判。纯函数、零 DOM 依赖,唯一第三方依赖为
5
+ [chardet](https://www.npmjs.com/package/chardet),浏览器 / Node 双形态可用。
6
+ vviewer 格式派发器(`@bhxch/vviewer-core`)的判别底座,亦可独立用于任何需要
7
+ 「这个文件是什么」判定的场景。
8
+
9
+ ## 安装
10
+
11
+ ```bash
12
+ npm install @bhxch/vviewer-detect
13
+ ```
14
+
15
+ ## 使用
16
+
17
+ ```ts
18
+ import { detect, refineEncoding } from '@bhxch/vviewer-detect';
19
+
20
+ const head = bytes.slice(0, 4096); // 头部窗口(签名/编码链判定面)
21
+ const det = detect({ name: 'sample.bin', head }); // → BaseDetection
22
+ await refineEncoding(bytes, det); // 可选:chardet 精判,就地改写 det.encoding
23
+ ```
24
+
25
+ `BaseDetection` 字段:`ext`(小写无点扩展名,签名纠偏后为规范扩展名)、`lang?`
26
+ (helix 名,无扩展名时回退链写入 shebang 语言)、`encoding?`(BOM/编码链结果)、
27
+ `binary?`(magic 或编码检测判定)、`signature?`(20 值 magic 枚举:zip/png/jpeg/
28
+ mp4/webp/gz/7z/rar/flac/ogg/bmp 等,null=无命中)。
29
+
30
+ ## 导出面
31
+
32
+ - 总入口:`detect({ name, head, full? })`
33
+ - 分件(总入口各阶段皆可单独使用):
34
+ - `extractExtension(name)` —— 扩展名提取(小写无点)
35
+ - `sniffSignature(head)` —— magic 签名嗅探(20 值枚举)
36
+ - `looksTextual(head)` —— 文本性判定
37
+ - `shebangLangOf(text)` —— shebang → 语言(helix 名)
38
+ - `detectEncoding(bytes)` / `isStrictUtf8(b)` —— BOM+编码检测链
39
+ - `refineEncoding(bytes, det)` —— chardet 精判(置信度+白名单双闸,仅收窄
40
+ 严格 UTF-8 失败的文本,映射外维持 gb18030)
41
+ - 类型与运行时值:`Encoding`(28 值联合类型,由运行时常量 `ENCODING_VALUES`
42
+ 单源派生——「全量编码值清单」消费方直接 import 该数组,扩列不再漏跟)、
43
+ `BaseDetection`
44
+
45
+ ## 仓库与许可
46
+
47
+ - 仓库:[bhxch/vviewer](https://github.com/bhxch/vviewer),源码位于 `packages/vviewer-detect/`
48
+ - 许可:Apache-2.0;第三方依赖(chardet)许可见仓库 `THIRD_PARTY_NOTICES.md`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bhxch/vviewer-detect",
3
- "version": "0.1.0",
3
+ "version": "0.1.4",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./index.js",
@@ -13,6 +13,7 @@
13
13
  },
14
14
  "files": [
15
15
  "LICENSE",
16
+ "README.md",
16
17
  "detect",
17
18
  "index.d.ts",
18
19
  "index.js",
@@ -28,5 +29,5 @@
28
29
  "dependencies": {
29
30
  "chardet": "^2.2.0"
30
31
  },
31
- "contentHash": "ba4a3e5f420423cf"
32
+ "contentHash": "5706d9f1fb38fd11"
32
33
  }