@uruhalushia/rule-converter-napi 0.2.0 → 0.3.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/README.md +8 -5
- package/index.d.ts +38 -15
- package/index.js +2 -0
- package/package.json +13 -13
package/README.md
CHANGED
|
@@ -15,6 +15,7 @@ pnpm --dir napi build
|
|
|
15
15
|
import { writeFileSync } from 'node:fs'
|
|
16
16
|
import {
|
|
17
17
|
fileToBuf,
|
|
18
|
+
detectFile,
|
|
18
19
|
listAsnNumbers,
|
|
19
20
|
listGeoipCountries,
|
|
20
21
|
listGeoipDatCountries,
|
|
@@ -82,6 +83,7 @@ console.log(listGeoipCountries('country.mmdb'))
|
|
|
82
83
|
console.log(listGeoipDatCountries('geoip.dat'))
|
|
83
84
|
console.log(listGeositeCodes('geosite.dat'))
|
|
84
85
|
console.log(listAsnNumbers('GeoLite2-ASN.mmdb'))
|
|
86
|
+
console.log(detectFile('geosite.dat'))
|
|
85
87
|
```
|
|
86
88
|
|
|
87
89
|
```js
|
|
@@ -106,10 +108,11 @@ console.log(route.matched, route.rules)
|
|
|
106
108
|
- `bufToStr(input, options?)`: converts a `Uint8Array` payload and returns UTF-8 text outputs.
|
|
107
109
|
- `strToStr(input, options?)`: converts a string payload and returns UTF-8 text outputs.
|
|
108
110
|
- `fileToStr(input, options?)`: converts one input file path and returns UTF-8 text outputs.
|
|
111
|
+
- `detectBuf(input)` / `detectStr(input)` / `detectFile(input)`: returns `{ kind, target, format, behavior }` without converting input.
|
|
109
112
|
- `listGeoipCountries(input)`: reads a GeoIP MMDB file path and returns sorted country codes.
|
|
110
113
|
- `listGeoipCountriesFromBuffer(input)`: reads GeoIP MMDB bytes and returns sorted country codes.
|
|
111
114
|
- `listGeoipDatCountries(input)` / `listGeoipDatCountriesFromBuffer(input)`: reads V2Ray `geoip.dat` and returns sorted country codes.
|
|
112
|
-
- `listGeositeCodes(input)` / `listGeositeCodesFromBuffer(input)`: reads V2Ray `geosite.dat` and returns sorted site codes.
|
|
115
|
+
- `listGeositeCodes(input)` / `listGeositeCodesFromBuffer(input)`: reads V2Ray `geosite.dat` or sing-geosite DB and returns sorted site codes.
|
|
113
116
|
- `listAsnNumbers(input)`: reads an ASN MMDB file path and returns sorted ASN numbers.
|
|
114
117
|
- `listAsnNumbersFromBuffer(input)`: reads ASN MMDB bytes and returns sorted ASN numbers.
|
|
115
118
|
- `matchBuf(input, query, options?)` / `matchStr(input, query, options?)` / `matchFile(input, query, options?)`: matches a domain or IP against rules and returns `{ matched, query, kind, rules }`. Mihomo config input is supported for provider `path`, `file://`, and HTTP(S) `url`. HTTP providers are downloaded into memory for matching.
|
|
@@ -117,10 +120,10 @@ console.log(route.matched, route.rules)
|
|
|
117
120
|
```ts
|
|
118
121
|
interface AnyConvertOptions {
|
|
119
122
|
inputTarget?: 'mihomo' | 'general' | 'egern' | 'sing-box' | 'geoip' | 'geosite' | 'asn'
|
|
120
|
-
inputFormat?: 'yaml' | 'mrs' | 'text' | 'json' | 'srs' | 'domainset' | 'ruleset' | 'ipset' | 'mmdb' | 'sing-db' | 'metadb' | 'dat'
|
|
123
|
+
inputFormat?: 'yaml' | 'mrs' | 'text' | 'json' | 'srs' | 'domainset' | 'ruleset' | 'ipset' | 'mmdb' | 'sing-db' | 'metadb' | 'dat' | 'sing-geosite'
|
|
121
124
|
inputBehavior?: 'auto' | 'domain' | 'ip' | 'classical'
|
|
122
125
|
outputTarget?: 'mihomo' | 'general' | 'egern' | 'sing-box' | 'geoip' | 'geosite' | 'asn'
|
|
123
|
-
outputFormat?: 'mrs' | 'text' | 'yaml' | 'json' | 'srs' | 'domainset' | 'ruleset' | 'ipset' | 'mmdb' | 'sing-db' | 'metadb' | 'dat'
|
|
126
|
+
outputFormat?: 'mrs' | 'text' | 'yaml' | 'json' | 'srs' | 'domainset' | 'ruleset' | 'ipset' | 'mmdb' | 'sing-db' | 'metadb' | 'dat' | 'sing-geosite'
|
|
124
127
|
outputBehavior?: 'auto' | 'domain' | 'ip' | 'classical'
|
|
125
128
|
countries?: string[]
|
|
126
129
|
codes?: string[]
|
|
@@ -161,8 +164,8 @@ DB conversions use the same functions as rule conversions:
|
|
|
161
164
|
- `inputTarget: 'geoip'`, `outputTarget: 'general' | 'mihomo' | 'egern' | 'sing-box'` exports GeoIP contents as rule sets.
|
|
162
165
|
- `inputTarget: 'asn'`, `outputTarget: 'general' | 'mihomo' | 'egern' | 'sing-box'` exports ASN contents as rule sets.
|
|
163
166
|
- `inputTarget: 'geoip'`, `outputTarget: 'geoip'` converts GeoIP DB bytes between `mmdb`, `sing-db`, `metadb`, and V2Ray `dat`.
|
|
164
|
-
- `inputTarget: 'geosite'`, `outputTarget: 'general' | 'mihomo' | 'egern' | 'sing-box'` exports V2Ray `geosite.dat` as rule sets.
|
|
165
|
-
- `inputTarget: 'geosite'`, `outputTarget: 'geosite'` filters
|
|
167
|
+
- `inputTarget: 'geosite'`, `outputTarget: 'general' | 'mihomo' | 'egern' | 'sing-box'` exports V2Ray `geosite.dat` or sing-geosite DB as rule sets.
|
|
168
|
+
- `inputTarget: 'geosite'`, `outputTarget: 'geosite'` converts and filters geosite DB between `dat` and `sing-geosite`.
|
|
166
169
|
- `inputTarget: 'asn'`, `outputTarget: 'asn'` normalizes ASN MMDB bytes. ASN DB output only supports `mmdb`.
|
|
167
170
|
- Rule input can build DB output with `outputTarget: 'geoip'` plus `country`, `outputTarget: 'geosite'` plus `code`, or `outputTarget: 'asn'` plus `asn`.
|
|
168
171
|
|
package/index.d.ts
CHANGED
|
@@ -9,10 +9,10 @@ export interface AnyBufferResult {
|
|
|
9
9
|
|
|
10
10
|
export interface AnyConvertOptions {
|
|
11
11
|
inputTarget?: 'mihomo' | 'general' | 'egern' | 'sing-box' | 'geoip' | 'geosite' | 'asn'
|
|
12
|
-
inputFormat?: 'yaml' | 'mrs' | 'text' | 'json' | 'srs' | 'domainset' | 'ruleset' | 'ipset' | 'mmdb' | 'sing-db' | 'metadb' | 'dat'
|
|
12
|
+
inputFormat?: 'yaml' | 'mrs' | 'text' | 'json' | 'srs' | 'domainset' | 'ruleset' | 'ipset' | 'mmdb' | 'sing-db' | 'metadb' | 'dat' | 'sing-geosite'
|
|
13
13
|
inputBehavior?: 'auto' | 'domain' | 'ip' | 'classical'
|
|
14
14
|
outputTarget?: 'mihomo' | 'general' | 'egern' | 'sing-box' | 'geoip' | 'geosite' | 'asn'
|
|
15
|
-
outputFormat?: 'mrs' | 'text' | 'yaml' | 'json' | 'srs' | 'domainset' | 'ruleset' | 'ipset' | 'mmdb' | 'sing-db' | 'metadb' | 'dat'
|
|
15
|
+
outputFormat?: 'mrs' | 'text' | 'yaml' | 'json' | 'srs' | 'domainset' | 'ruleset' | 'ipset' | 'mmdb' | 'sing-db' | 'metadb' | 'dat' | 'sing-geosite'
|
|
16
16
|
outputBehavior?: 'auto' | 'domain' | 'ip' | 'classical'
|
|
17
17
|
countries?: Array<string>
|
|
18
18
|
codes?: Array<string>
|
|
@@ -40,10 +40,28 @@ export declare function bufToBuf(input: Uint8Array, options?: AnyConvertOptions
|
|
|
40
40
|
|
|
41
41
|
export declare function bufToStr(input: Uint8Array, options?: AnyConvertOptions | undefined | null): AnyStringResult
|
|
42
42
|
|
|
43
|
+
export declare function detectBuf(input: Uint8Array): DetectResult
|
|
44
|
+
|
|
45
|
+
export declare function detectFile(input: string): DetectResult
|
|
46
|
+
|
|
47
|
+
export interface DetectResult {
|
|
48
|
+
kind: 'rules' | 'db'
|
|
49
|
+
target: 'mihomo' | 'general' | 'egern' | 'sing-box' | 'geoip' | 'geosite' | 'asn'
|
|
50
|
+
format: string
|
|
51
|
+
behavior?: string
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export declare function detectStr(input: string): DetectResult
|
|
55
|
+
|
|
43
56
|
export declare function fileToBuf(input: string, options?: AnyConvertOptions | undefined | null): AnyBufferResult
|
|
44
57
|
|
|
45
58
|
export declare function fileToStr(input: string, options?: AnyConvertOptions | undefined | null): AnyStringResult
|
|
46
59
|
|
|
60
|
+
export interface IndexSection {
|
|
61
|
+
title: string
|
|
62
|
+
items: Array<string>
|
|
63
|
+
}
|
|
64
|
+
|
|
47
65
|
export declare function listAsnNumbers(input: string): Array<number>
|
|
48
66
|
|
|
49
67
|
export declare function listAsnNumbersFromBuffer(input: Uint8Array): Array<number>
|
|
@@ -60,18 +78,20 @@ export declare function listGeositeCodes(input: string): Array<string>
|
|
|
60
78
|
|
|
61
79
|
export declare function listGeositeCodesFromBuffer(input: Uint8Array): Array<string>
|
|
62
80
|
|
|
81
|
+
export declare function listIndexes(input: string): Array<IndexSection>
|
|
82
|
+
|
|
83
|
+
export declare function listIndexesFromBuffer(input: Uint8Array): Array<IndexSection>
|
|
84
|
+
|
|
85
|
+
export declare function matchBuf(input: Uint8Array, query: string, options?: MatchOptions | undefined | null): MatchResult
|
|
86
|
+
|
|
87
|
+
export declare function matchFile(input: string, query: string, options?: MatchOptions | undefined | null): MatchResult
|
|
63
88
|
|
|
64
89
|
export interface MatchOptions {
|
|
65
|
-
inputTarget?: 'mihomo' | 'general' | 'egern' | 'sing-box'
|
|
66
|
-
inputFormat?: 'yaml' | 'mrs' | 'text' | 'json' | 'srs' | 'domainset' | 'ruleset' | 'ipset'
|
|
90
|
+
inputTarget?: 'mihomo' | 'general' | 'egern' | 'sing-box' | 'geoip' | 'geosite' | 'asn'
|
|
91
|
+
inputFormat?: 'yaml' | 'mrs' | 'text' | 'json' | 'srs' | 'domainset' | 'ruleset' | 'ipset' | 'dat' | 'sing-geosite' | 'mmdb' | 'sing-db' | 'metadb'
|
|
67
92
|
inputBehavior?: 'auto' | 'domain' | 'ip' | 'classical'
|
|
68
93
|
}
|
|
69
94
|
|
|
70
|
-
export interface MatchRule {
|
|
71
|
-
behavior: string
|
|
72
|
-
rule: string
|
|
73
|
-
}
|
|
74
|
-
|
|
75
95
|
export interface MatchResult {
|
|
76
96
|
matched: boolean
|
|
77
97
|
query: string
|
|
@@ -79,6 +99,15 @@ export interface MatchResult {
|
|
|
79
99
|
rules: Array<MatchRule>
|
|
80
100
|
}
|
|
81
101
|
|
|
102
|
+
export interface MatchRule {
|
|
103
|
+
behavior: string
|
|
104
|
+
rule: string
|
|
105
|
+
source?: string
|
|
106
|
+
set?: string
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export declare function matchStr(input: string, query: string, options?: MatchOptions | undefined | null): MatchResult
|
|
110
|
+
|
|
82
111
|
export interface SkippedRule {
|
|
83
112
|
rule: string
|
|
84
113
|
reason: string
|
|
@@ -87,9 +116,3 @@ export interface SkippedRule {
|
|
|
87
116
|
export declare function strToBuf(input: string, options?: AnyConvertOptions | undefined | null): AnyBufferResult
|
|
88
117
|
|
|
89
118
|
export declare function strToStr(input: string, options?: AnyConvertOptions | undefined | null): AnyStringResult
|
|
90
|
-
|
|
91
|
-
export declare function matchBuf(input: Uint8Array, query: string, options?: MatchOptions | undefined | null): MatchResult
|
|
92
|
-
|
|
93
|
-
export declare function matchStr(input: string, query: string, options?: MatchOptions | undefined | null): MatchResult
|
|
94
|
-
|
|
95
|
-
export declare function matchFile(input: string, query: string, options?: MatchOptions | undefined | null): MatchResult
|
package/index.js
CHANGED
|
@@ -98,6 +98,8 @@ export const fileToBuf = nativeBinding.fileToBuf
|
|
|
98
98
|
export const bufToStr = nativeBinding.bufToStr
|
|
99
99
|
export const strToStr = nativeBinding.strToStr
|
|
100
100
|
export const fileToStr = nativeBinding.fileToStr
|
|
101
|
+
export const listIndexes = nativeBinding.listIndexes
|
|
102
|
+
export const listIndexesFromBuffer = nativeBinding.listIndexesFromBuffer
|
|
101
103
|
export const listGeoipCountries = nativeBinding.listGeoipCountries
|
|
102
104
|
export const listGeoipCountriesFromBuffer = nativeBinding.listGeoipCountriesFromBuffer
|
|
103
105
|
export const listGeoipDatCountries = nativeBinding.listGeoipDatCountries
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uruhalushia/rule-converter-napi",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Node.js bindings for converting mihomo, sing-box, Egern, and generic rule sets.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -51,17 +51,17 @@
|
|
|
51
51
|
"@napi-rs/cli": "^3"
|
|
52
52
|
},
|
|
53
53
|
"optionalDependencies": {
|
|
54
|
-
"@uruhalushia/rule-converter-napi-linux-x64-gnu": "0.
|
|
55
|
-
"@uruhalushia/rule-converter-napi-linux-arm64-gnu": "0.
|
|
56
|
-
"@uruhalushia/rule-converter-napi-linux-riscv64-gnu": "0.
|
|
57
|
-
"@uruhalushia/rule-converter-napi-linux-loong64-gnu": "0.
|
|
58
|
-
"@uruhalushia/rule-converter-napi-linux-x64-musl": "0.
|
|
59
|
-
"@uruhalushia/rule-converter-napi-linux-arm64-musl": "0.
|
|
60
|
-
"@uruhalushia/rule-converter-napi-linux-riscv64-musl": "0.
|
|
61
|
-
"@uruhalushia/rule-converter-napi-linux-loong64-musl": "0.
|
|
62
|
-
"@uruhalushia/rule-converter-napi-darwin-x64": "0.
|
|
63
|
-
"@uruhalushia/rule-converter-napi-darwin-arm64": "0.
|
|
64
|
-
"@uruhalushia/rule-converter-napi-win32-x64-msvc": "0.
|
|
65
|
-
"@uruhalushia/rule-converter-napi-win32-arm64-msvc": "0.
|
|
54
|
+
"@uruhalushia/rule-converter-napi-linux-x64-gnu": "0.3.0",
|
|
55
|
+
"@uruhalushia/rule-converter-napi-linux-arm64-gnu": "0.3.0",
|
|
56
|
+
"@uruhalushia/rule-converter-napi-linux-riscv64-gnu": "0.3.0",
|
|
57
|
+
"@uruhalushia/rule-converter-napi-linux-loong64-gnu": "0.3.0",
|
|
58
|
+
"@uruhalushia/rule-converter-napi-linux-x64-musl": "0.3.0",
|
|
59
|
+
"@uruhalushia/rule-converter-napi-linux-arm64-musl": "0.3.0",
|
|
60
|
+
"@uruhalushia/rule-converter-napi-linux-riscv64-musl": "0.3.0",
|
|
61
|
+
"@uruhalushia/rule-converter-napi-linux-loong64-musl": "0.3.0",
|
|
62
|
+
"@uruhalushia/rule-converter-napi-darwin-x64": "0.3.0",
|
|
63
|
+
"@uruhalushia/rule-converter-napi-darwin-arm64": "0.3.0",
|
|
64
|
+
"@uruhalushia/rule-converter-napi-win32-x64-msvc": "0.3.0",
|
|
65
|
+
"@uruhalushia/rule-converter-napi-win32-arm64-msvc": "0.3.0"
|
|
66
66
|
}
|
|
67
67
|
}
|