@uruhalushia/rule-converter-napi 0.1.1 → 0.1.2
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 +34 -2
- package/index.d.ts +39 -10
- package/index.js +6 -0
- package/package.json +13 -13
package/README.md
CHANGED
|
@@ -13,7 +13,12 @@ pnpm --dir napi build
|
|
|
13
13
|
|
|
14
14
|
```js
|
|
15
15
|
import { writeFileSync } from 'node:fs'
|
|
16
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
convertPayloadStringToMrs,
|
|
18
|
+
convertPayloadStringToString,
|
|
19
|
+
convertFileToBuffer,
|
|
20
|
+
convertFileToPath,
|
|
21
|
+
} from '@uruhalushia/rule-converter-napi'
|
|
17
22
|
|
|
18
23
|
const payload = `
|
|
19
24
|
payload:
|
|
@@ -35,9 +40,28 @@ for (const output of result.outputs) {
|
|
|
35
40
|
writeFileSync(`${output.behavior}.mrs`, output.bytes)
|
|
36
41
|
}
|
|
37
42
|
|
|
43
|
+
const text = convertPayloadStringToString(payload, {
|
|
44
|
+
inputTarget: 'mihomo',
|
|
45
|
+
inputFormat: 'yaml',
|
|
46
|
+
inputBehavior: 'classical',
|
|
47
|
+
outputTarget: 'general',
|
|
48
|
+
outputFormat: 'ruleset',
|
|
49
|
+
outputBehavior: 'classical',
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
console.log(text.outputs[0].text)
|
|
53
|
+
|
|
54
|
+
const srs = convertFileToBuffer('rules.yaml', {
|
|
55
|
+
outputTarget: 'sing-box',
|
|
56
|
+
outputFormat: 'srs',
|
|
57
|
+
outputBehavior: 'classical',
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
writeFileSync('rules.srs', srs.outputs[0].buffer)
|
|
61
|
+
|
|
38
62
|
const written = convertFileToPath('rules.yaml', 'dist/rules.list', {
|
|
39
63
|
outputTarget: 'general',
|
|
40
|
-
outputFormat: '
|
|
64
|
+
outputFormat: 'ruleset',
|
|
41
65
|
outputBehavior: 'classical',
|
|
42
66
|
})
|
|
43
67
|
|
|
@@ -59,6 +83,12 @@ convertFileToPath(['/path/rules-a.yaml', '/path/rules-b.yaml'], 'dist/ad.mrs', {
|
|
|
59
83
|
- `convertPayloadToMrs(payload, options?)`: accepts `Uint8Array` and returns generated MRS files in memory.
|
|
60
84
|
- `convertPayloadStringToMrs(payload, options?)`: accepts a string and returns generated MRS files in memory.
|
|
61
85
|
- `convertFileToMrs(input, options?)`: reads one file, directory, wildcard, or path array and returns generated MRS files in memory.
|
|
86
|
+
- `convertPayloadToBuffer(payload, options?)`: accepts `Uint8Array` and returns generated files as Node.js `Buffer` objects in memory.
|
|
87
|
+
- `convertPayloadStringToBuffer(payload, options?)`: accepts a string and returns generated files as Node.js `Buffer` objects in memory.
|
|
88
|
+
- `convertFileToBuffer(input, options?)`: reads one file, directory, wildcard, or path array and returns generated files as Node.js `Buffer` objects in memory.
|
|
89
|
+
- `convertPayloadToString(payload, options?)`: accepts `Uint8Array` and returns generated text output as strings.
|
|
90
|
+
- `convertPayloadStringToString(payload, options?)`: accepts a string and returns generated text output as strings.
|
|
91
|
+
- `convertFileToString(input, options?)`: reads one file, directory, wildcard, or path array and returns generated text output as strings.
|
|
62
92
|
- `convertFileToPath(input, output, options?)`: writes converted outputs to disk.
|
|
63
93
|
|
|
64
94
|
```ts
|
|
@@ -83,6 +113,8 @@ Defaults:
|
|
|
83
113
|
|
|
84
114
|
mihomo MRS output supports only `domain` and `ip`. sing-box JSON/SRS is available with `outputTarget: 'sing-box'` and `outputFormat: 'json' | 'srs'`.
|
|
85
115
|
|
|
116
|
+
String output supports text formats only: `text`, `yaml`, `json`, `domainset`, `ruleset`, and `ipset`. Use the buffer functions for binary `mrs` and `srs` output.
|
|
117
|
+
|
|
86
118
|
`mihomo + text/yaml + domain` uses mihomo/Clash domain wildcard syntax such as `+.example.com`; `general + domainset + domain` uses domain-set syntax where `.example.com` means the domain itself and all subdomains.
|
|
87
119
|
|
|
88
120
|
`no-resolve` is preserved only between mixed text, mihomo YAML, and Egern ruleset YAML. MRS, sing-box JSON/SRS, and domain-set output do not have a field for it.
|
package/index.d.ts
CHANGED
|
@@ -1,21 +1,31 @@
|
|
|
1
1
|
/* auto-generated by NAPI-RS */
|
|
2
2
|
/* eslint-disable */
|
|
3
|
+
export interface ConvertBufferOutput {
|
|
4
|
+
behavior: 'domain' | 'ip'
|
|
5
|
+
count: number
|
|
6
|
+
buffer: Uint8Array
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface ConvertBufferResult {
|
|
10
|
+
outputs: Array<ConvertBufferOutput>
|
|
11
|
+
skipped: Array<SkippedRule>
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export declare function convertFileToBuffer(input: string | string[], options?: ConvertOptions | undefined | null): ConvertBufferResult
|
|
15
|
+
|
|
3
16
|
export declare function convertFileToMrs(input: string | string[], options?: ConvertOptions | undefined | null): ConvertResult
|
|
4
17
|
|
|
5
18
|
export declare function convertFileToPath(input: string | string[], output: string, options?: ConvertOptions | undefined | null): WriteResult
|
|
6
19
|
|
|
7
|
-
export
|
|
8
|
-
export type RuleFormat = 'mrs' | 'text' | 'yaml' | 'json' | 'srs' | 'domainset' | 'ruleset' | 'ipset'
|
|
9
|
-
export type InputBehavior = 'auto' | 'domain' | 'ip' | 'classical'
|
|
10
|
-
export type OutputBehavior = 'auto' | 'domain' | 'ip' | 'classical'
|
|
20
|
+
export declare function convertFileToString(input: string | string[], options?: ConvertOptions | undefined | null): ConvertStringResult
|
|
11
21
|
|
|
12
22
|
export interface ConvertOptions {
|
|
13
|
-
inputTarget?:
|
|
14
|
-
inputFormat?:
|
|
15
|
-
inputBehavior?:
|
|
16
|
-
outputTarget?:
|
|
17
|
-
outputFormat?:
|
|
18
|
-
outputBehavior?:
|
|
23
|
+
inputTarget?: 'mihomo' | 'general' | 'egern' | 'sing-box'
|
|
24
|
+
inputFormat?: 'yaml' | 'mrs' | 'text' | 'json' | 'srs'
|
|
25
|
+
inputBehavior?: 'auto' | 'domain' | 'ip' | 'classical'
|
|
26
|
+
outputTarget?: 'mihomo' | 'general' | 'egern' | 'sing-box'
|
|
27
|
+
outputFormat?: 'mrs' | 'text' | 'yaml' | 'json' | 'srs' | 'domainset' | 'ruleset' | 'ipset'
|
|
28
|
+
outputBehavior?: 'auto' | 'domain' | 'ip' | 'classical'
|
|
19
29
|
}
|
|
20
30
|
|
|
21
31
|
export interface ConvertOutput {
|
|
@@ -24,15 +34,34 @@ export interface ConvertOutput {
|
|
|
24
34
|
bytes: Uint8Array
|
|
25
35
|
}
|
|
26
36
|
|
|
37
|
+
export declare function convertPayloadStringToBuffer(payload: string, options?: ConvertOptions | undefined | null): ConvertBufferResult
|
|
38
|
+
|
|
27
39
|
export declare function convertPayloadStringToMrs(payload: string, options?: ConvertOptions | undefined | null): ConvertResult
|
|
28
40
|
|
|
41
|
+
export declare function convertPayloadStringToString(payload: string, options?: ConvertOptions | undefined | null): ConvertStringResult
|
|
42
|
+
|
|
43
|
+
export declare function convertPayloadToBuffer(payload: Uint8Array, options?: ConvertOptions | undefined | null): ConvertBufferResult
|
|
44
|
+
|
|
29
45
|
export declare function convertPayloadToMrs(payload: Uint8Array, options?: ConvertOptions | undefined | null): ConvertResult
|
|
30
46
|
|
|
47
|
+
export declare function convertPayloadToString(payload: Uint8Array, options?: ConvertOptions | undefined | null): ConvertStringResult
|
|
48
|
+
|
|
31
49
|
export interface ConvertResult {
|
|
32
50
|
outputs: Array<ConvertOutput>
|
|
33
51
|
skipped: Array<SkippedRule>
|
|
34
52
|
}
|
|
35
53
|
|
|
54
|
+
export interface ConvertStringOutput {
|
|
55
|
+
behavior: 'domain' | 'ip'
|
|
56
|
+
count: number
|
|
57
|
+
text: string
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface ConvertStringResult {
|
|
61
|
+
outputs: Array<ConvertStringOutput>
|
|
62
|
+
skipped: Array<SkippedRule>
|
|
63
|
+
}
|
|
64
|
+
|
|
36
65
|
export interface SkippedRule {
|
|
37
66
|
rule: string
|
|
38
67
|
reason: string
|
package/index.js
CHANGED
|
@@ -100,5 +100,11 @@ if (!nativeBinding) {
|
|
|
100
100
|
export default nativeBinding
|
|
101
101
|
export const convertPayloadToMrs = nativeBinding.convertPayloadToMrs
|
|
102
102
|
export const convertPayloadStringToMrs = nativeBinding.convertPayloadStringToMrs
|
|
103
|
+
export const convertPayloadToBuffer = nativeBinding.convertPayloadToBuffer
|
|
104
|
+
export const convertPayloadStringToBuffer = nativeBinding.convertPayloadStringToBuffer
|
|
105
|
+
export const convertPayloadToString = nativeBinding.convertPayloadToString
|
|
106
|
+
export const convertPayloadStringToString = nativeBinding.convertPayloadStringToString
|
|
103
107
|
export const convertFileToMrs = nativeBinding.convertFileToMrs
|
|
108
|
+
export const convertFileToBuffer = nativeBinding.convertFileToBuffer
|
|
109
|
+
export const convertFileToString = nativeBinding.convertFileToString
|
|
104
110
|
export const convertFileToPath = nativeBinding.convertFileToPath
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uruhalushia/rule-converter-napi",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
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.1.
|
|
55
|
-
"@uruhalushia/rule-converter-napi-linux-arm64-gnu": "0.1.
|
|
56
|
-
"@uruhalushia/rule-converter-napi-linux-riscv64-gnu": "0.1.
|
|
57
|
-
"@uruhalushia/rule-converter-napi-linux-loong64-gnu": "0.1.
|
|
58
|
-
"@uruhalushia/rule-converter-napi-linux-x64-musl": "0.1.
|
|
59
|
-
"@uruhalushia/rule-converter-napi-linux-arm64-musl": "0.1.
|
|
60
|
-
"@uruhalushia/rule-converter-napi-linux-riscv64-musl": "0.1.
|
|
61
|
-
"@uruhalushia/rule-converter-napi-linux-loong64-musl": "0.1.
|
|
62
|
-
"@uruhalushia/rule-converter-napi-darwin-x64": "0.1.
|
|
63
|
-
"@uruhalushia/rule-converter-napi-darwin-arm64": "0.1.
|
|
64
|
-
"@uruhalushia/rule-converter-napi-win32-x64-msvc": "0.1.
|
|
65
|
-
"@uruhalushia/rule-converter-napi-win32-arm64-msvc": "0.1.
|
|
54
|
+
"@uruhalushia/rule-converter-napi-linux-x64-gnu": "0.1.2",
|
|
55
|
+
"@uruhalushia/rule-converter-napi-linux-arm64-gnu": "0.1.2",
|
|
56
|
+
"@uruhalushia/rule-converter-napi-linux-riscv64-gnu": "0.1.2",
|
|
57
|
+
"@uruhalushia/rule-converter-napi-linux-loong64-gnu": "0.1.2",
|
|
58
|
+
"@uruhalushia/rule-converter-napi-linux-x64-musl": "0.1.2",
|
|
59
|
+
"@uruhalushia/rule-converter-napi-linux-arm64-musl": "0.1.2",
|
|
60
|
+
"@uruhalushia/rule-converter-napi-linux-riscv64-musl": "0.1.2",
|
|
61
|
+
"@uruhalushia/rule-converter-napi-linux-loong64-musl": "0.1.2",
|
|
62
|
+
"@uruhalushia/rule-converter-napi-darwin-x64": "0.1.2",
|
|
63
|
+
"@uruhalushia/rule-converter-napi-darwin-arm64": "0.1.2",
|
|
64
|
+
"@uruhalushia/rule-converter-napi-win32-x64-msvc": "0.1.2",
|
|
65
|
+
"@uruhalushia/rule-converter-napi-win32-arm64-msvc": "0.1.2"
|
|
66
66
|
}
|
|
67
67
|
}
|