@svg-rs/svgo 0.0.3 → 0.0.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.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020 N-API for Rust
3
+ Copyright (c) 2025 Jacob
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,105 +1,52 @@
1
- # `@napi-rs/package-template`
1
+ # svgo-rs
2
2
 
3
- ![https://github.com/napi-rs/package-template/actions](https://github.com/napi-rs/package-template/workflows/CI/badge.svg)
3
+ `svgo-rs` is a high-performance SVG optimizer written in Rust, designed to process and optimize SVG files efficiently. It provides bindings for Node.js through NAPI-RS, making it accessible for JavaScript and TypeScript developers.
4
4
 
5
- > Template project for writing node packages with napi-rs.
5
+ ## Features
6
6
 
7
- # Usage
7
+ - Written in Rust for high performance.
8
+ - Provides plugins for various SVG optimizations, such as removing metadata, comments, and unnecessary elements.
9
+ - Supports multiple platforms with precompiled binaries.
10
+ - Easy integration with Node.js projects.
8
11
 
9
- 1. Click **Use this template**.
10
- 2. **Clone** your project.
11
- 3. Run `yarn install` to install dependencies.
12
- 4. Run `npx napi rename -n [name]` command under the project folder to rename your package.
12
+ ## Installation
13
13
 
14
- ## Install this test package
14
+ Install the package via npm:
15
15
 
16
+ ```bash
17
+ npm install @svg-rs/svgo
16
18
  ```
17
- yarn add @napi-rs/package-template
18
- ```
19
-
20
- ## Support matrix
21
-
22
- ### Operating Systems
23
-
24
- | | node14 | node16 | node18 |
25
- | ---------------- | ------ | ------ | ------ |
26
- | Windows x64 | ✓ | ✓ | ✓ |
27
- | Windows x32 | ✓ | ✓ | ✓ |
28
- | Windows arm64 | ✓ | ✓ | ✓ |
29
- | macOS x64 | ✓ | ✓ | ✓ |
30
- | macOS arm64 | ✓ | ✓ | ✓ |
31
- | Linux x64 gnu | ✓ | ✓ | ✓ |
32
- | Linux x64 musl | ✓ | ✓ | ✓ |
33
- | Linux arm gnu | ✓ | ✓ | ✓ |
34
- | Linux arm64 gnu | ✓ | ✓ | ✓ |
35
- | Linux arm64 musl | ✓ | ✓ | ✓ |
36
- | Android arm64 | ✓ | ✓ | ✓ |
37
- | Android armv7 | ✓ | ✓ | ✓ |
38
- | FreeBSD x64 | ✓ | ✓ | ✓ |
39
-
40
- ## Ability
41
-
42
- ### Build
43
-
44
- After `yarn build/npm run build` command, you can see `package-template.[darwin|win32|linux].node` file in project root. This is the native addon built from [lib.rs](./src/lib.rs).
45
-
46
- ### Test
47
-
48
- With [ava](https://github.com/avajs/ava), run `yarn test/npm run test` to testing native addon. You can also switch to another testing framework if you want.
49
-
50
- ### CI
51
-
52
- With GitHub Actions, each commit and pull request will be built and tested automatically in [`node@14`, `node@16`, `@node18`] x [`macOS`, `Linux`, `Windows`] matrix. You will never be afraid of the native addon broken in these platforms.
53
19
 
54
- ### Release
20
+ ## Usage
55
21
 
56
- Release native package is very difficult in old days. Native packages may ask developers who use it to install `build toolchain` like `gcc/llvm`, `node-gyp` or something more.
22
+ ### Node.js
57
23
 
58
- With `GitHub actions`, we can easily prebuild a `binary` for major platforms. And with `N-API`, we should never be afraid of **ABI Compatible**.
24
+ ```javascript
25
+ const { optimize } = require('@svg-rs/svgo')
59
26
 
60
- The other problem is how to deliver prebuild `binary` to users. Downloading it in `postinstall` script is a common way that most packages do it right now. The problem with this solution is it introduced many other packages to download binary that has not been used by `runtime codes`. The other problem is some users may not easily download the binary from `GitHub/CDN` if they are behind a private network (But in most cases, they have a private NPM mirror).
27
+ const inputSvg = `<svg xmlns="http://www.w3.org/2000/svg">
28
+ <g attr1="val1">
29
+ <desc>Example</desc>
30
+ <circle cx="50" cy="50" r="40"/>
31
+ </g>
32
+ </svg>`
61
33
 
62
- In this package, we choose a better way to solve this problem. We release different `npm packages` for different platforms. And add it to `optionalDependencies` before releasing the `Major` package to npm.
63
-
64
- `NPM` will choose which native package should download from `registry` automatically. You can see [npm](./npm) dir for details. And you can also run `yarn add @napi-rs/package-template` to see how it works.
65
-
66
- ## Develop requirements
67
-
68
- - Install the latest `Rust`
69
- - Install `Node.js@10+` which fully supported `Node-API`
70
- - Install `yarn@1.x`
71
-
72
- ## Test in local
34
+ const optimizedSvg = optimize(inputSvg)
35
+ console.log(optimizedSvg)
36
+ ```
73
37
 
74
- - yarn
75
- - yarn build
76
- - yarn test
38
+ ## Benchmarks
77
39
 
78
- And you will see:
40
+ `svgo-rs` provides significant performance improvements over JavaScript-based SVG optimizers. Run the benchmarks in the `benchmark/` directory to compare:
79
41
 
80
42
  ```bash
81
- $ ava --verbose
82
-
83
- ✔ sync function from native code
84
- ✔ sleep function from native code (201ms)
85
-
86
-
87
- 2 tests passed
88
- ✨ Done in 1.12s.
43
+ yarn bench
89
44
  ```
90
45
 
91
- ## Release package
92
-
93
- Ensure you have set your **NPM_TOKEN** in the `GitHub` project setting.
94
-
95
- In `Settings -> Secrets`, add **NPM_TOKEN** into it.
46
+ ## License
96
47
 
97
- When you want to release the package:
48
+ This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.
98
49
 
99
- ```
100
- npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease [--preid=<prerelease-id>] | from-git]
101
-
102
- git push
103
- ```
50
+ ## Contributing
104
51
 
105
- GitHub actions will do the rest job for you.
52
+ Contributions are welcome! Please open an issue or submit a pull request on [GitHub](https://github.com/oxidized-world/svgo-rs).
package/README.zh.md ADDED
@@ -0,0 +1,52 @@
1
+ # svgo-rs
2
+
3
+ `svgo-rs` 是一个用 Rust 编写的高性能 SVG 优化器,旨在高效地处理和优化 SVG 文件。它通过 NAPI-RS 提供 Node.js 的绑定,使 JavaScript 和 TypeScript 开发者可以轻松使用。
4
+
5
+ ## 特性
6
+
7
+ - 使用 Rust 编写,性能卓越。
8
+ - 提供多种 SVG 优化插件,例如移除元数据、注释和不必要的元素。
9
+ - 支持多个平台,并提供预编译的二进制文件。
10
+ - 可轻松集成到 Node.js 项目中。
11
+
12
+ ## 安装
13
+
14
+ 通过 npm 安装此包:
15
+
16
+ ```bash
17
+ npm install @svg-rs/svgo
18
+ ```
19
+
20
+ ## 使用方法
21
+
22
+ ### Node.js
23
+
24
+ ```javascript
25
+ const { optimize } = require('@svg-rs/svgo')
26
+
27
+ const inputSvg = `<svg xmlns="http://www.w3.org/2000/svg">
28
+ <g attr1="val1">
29
+ <desc>Example</desc>
30
+ <circle cx="50" cy="50" r="40"/>
31
+ </g>
32
+ </svg>`
33
+
34
+ const optimizedSvg = optimize(inputSvg)
35
+ console.log(optimizedSvg)
36
+ ```
37
+
38
+ ## 基准测试
39
+
40
+ `svgo-rs` 相较于基于 JavaScript 的 SVG 优化器提供了显著的性能提升。可以在 `benchmark/` 目录中运行基准测试进行比较:
41
+
42
+ ```bash
43
+ yarn bench
44
+ ```
45
+
46
+ ## 许可证
47
+
48
+ 此项目基于 MIT 许可证授权。详情请参阅 [LICENSE](./LICENSE) 文件。
49
+
50
+ ## 贡献
51
+
52
+ 欢迎贡献!请在 [GitHub](https://github.com/oxidized-world/svgo-rs) 上提交 issue 或 pull request。
package/index.d.ts CHANGED
@@ -3,14 +3,4 @@
3
3
 
4
4
  /* auto-generated by NAPI-RS */
5
5
 
6
- export interface RemoveDescOptions {
7
- /** Remove any `desc` elements, even if they have children. */
8
- removeAny: boolean
9
- }
10
- export interface PluginConfig {
11
- removeDesc: RemoveDescOptions
12
- }
13
- export interface OptimizeOptions {
14
- plugins: PluginConfig
15
- }
16
- export declare function optimize(inputXml: string, options: OptimizeOptions): string
6
+ export declare function optimize(inputXml: string): string
package/index.js CHANGED
@@ -62,7 +62,9 @@ switch (platform) {
62
62
  case 'win32':
63
63
  switch (arch) {
64
64
  case 'x64':
65
- localFileExisted = existsSync(join(__dirname, 'svgo-rs.win32-x64-msvc.node'))
65
+ localFileExisted = existsSync(
66
+ join(__dirname, 'svgo-rs.win32-x64-msvc.node')
67
+ )
66
68
  try {
67
69
  if (localFileExisted) {
68
70
  nativeBinding = require('./svgo-rs.win32-x64-msvc.node')
@@ -74,7 +76,9 @@ switch (platform) {
74
76
  }
75
77
  break
76
78
  case 'ia32':
77
- localFileExisted = existsSync(join(__dirname, 'svgo-rs.win32-ia32-msvc.node'))
79
+ localFileExisted = existsSync(
80
+ join(__dirname, 'svgo-rs.win32-ia32-msvc.node')
81
+ )
78
82
  try {
79
83
  if (localFileExisted) {
80
84
  nativeBinding = require('./svgo-rs.win32-ia32-msvc.node')
@@ -86,7 +90,9 @@ switch (platform) {
86
90
  }
87
91
  break
88
92
  case 'arm64':
89
- localFileExisted = existsSync(join(__dirname, 'svgo-rs.win32-arm64-msvc.node'))
93
+ localFileExisted = existsSync(
94
+ join(__dirname, 'svgo-rs.win32-arm64-msvc.node')
95
+ )
90
96
  try {
91
97
  if (localFileExisted) {
92
98
  nativeBinding = require('./svgo-rs.win32-arm64-msvc.node')
@@ -125,7 +131,9 @@ switch (platform) {
125
131
  }
126
132
  break
127
133
  case 'arm64':
128
- localFileExisted = existsSync(join(__dirname, 'svgo-rs.darwin-arm64.node'))
134
+ localFileExisted = existsSync(
135
+ join(__dirname, 'svgo-rs.darwin-arm64.node')
136
+ )
129
137
  try {
130
138
  if (localFileExisted) {
131
139
  nativeBinding = require('./svgo-rs.darwin-arm64.node')
@@ -159,7 +167,9 @@ switch (platform) {
159
167
  switch (arch) {
160
168
  case 'x64':
161
169
  if (isMusl()) {
162
- localFileExisted = existsSync(join(__dirname, 'svgo-rs.linux-x64-musl.node'))
170
+ localFileExisted = existsSync(
171
+ join(__dirname, 'svgo-rs.linux-x64-musl.node')
172
+ )
163
173
  try {
164
174
  if (localFileExisted) {
165
175
  nativeBinding = require('./svgo-rs.linux-x64-musl.node')
@@ -170,7 +180,9 @@ switch (platform) {
170
180
  loadError = e
171
181
  }
172
182
  } else {
173
- localFileExisted = existsSync(join(__dirname, 'svgo-rs.linux-x64-gnu.node'))
183
+ localFileExisted = existsSync(
184
+ join(__dirname, 'svgo-rs.linux-x64-gnu.node')
185
+ )
174
186
  try {
175
187
  if (localFileExisted) {
176
188
  nativeBinding = require('./svgo-rs.linux-x64-gnu.node')
@@ -184,7 +196,9 @@ switch (platform) {
184
196
  break
185
197
  case 'arm64':
186
198
  if (isMusl()) {
187
- localFileExisted = existsSync(join(__dirname, 'svgo-rs.linux-arm64-musl.node'))
199
+ localFileExisted = existsSync(
200
+ join(__dirname, 'svgo-rs.linux-arm64-musl.node')
201
+ )
188
202
  try {
189
203
  if (localFileExisted) {
190
204
  nativeBinding = require('./svgo-rs.linux-arm64-musl.node')
@@ -195,7 +209,9 @@ switch (platform) {
195
209
  loadError = e
196
210
  }
197
211
  } else {
198
- localFileExisted = existsSync(join(__dirname, 'svgo-rs.linux-arm64-gnu.node'))
212
+ localFileExisted = existsSync(
213
+ join(__dirname, 'svgo-rs.linux-arm64-gnu.node')
214
+ )
199
215
  try {
200
216
  if (localFileExisted) {
201
217
  nativeBinding = require('./svgo-rs.linux-arm64-gnu.node')
@@ -209,7 +225,9 @@ switch (platform) {
209
225
  break
210
226
  case 'arm':
211
227
  if (isMusl()) {
212
- localFileExisted = existsSync(join(__dirname, 'svgo-rs.linux-arm-musleabihf.node'))
228
+ localFileExisted = existsSync(
229
+ join(__dirname, 'svgo-rs.linux-arm-musleabihf.node')
230
+ )
213
231
  try {
214
232
  if (localFileExisted) {
215
233
  nativeBinding = require('./svgo-rs.linux-arm-musleabihf.node')
@@ -220,7 +238,9 @@ switch (platform) {
220
238
  loadError = e
221
239
  }
222
240
  } else {
223
- localFileExisted = existsSync(join(__dirname, 'svgo-rs.linux-arm-gnueabihf.node'))
241
+ localFileExisted = existsSync(
242
+ join(__dirname, 'svgo-rs.linux-arm-gnueabihf.node')
243
+ )
224
244
  try {
225
245
  if (localFileExisted) {
226
246
  nativeBinding = require('./svgo-rs.linux-arm-gnueabihf.node')
@@ -234,7 +254,9 @@ switch (platform) {
234
254
  break
235
255
  case 'riscv64':
236
256
  if (isMusl()) {
237
- localFileExisted = existsSync(join(__dirname, 'svgo-rs.linux-riscv64-musl.node'))
257
+ localFileExisted = existsSync(
258
+ join(__dirname, 'svgo-rs.linux-riscv64-musl.node')
259
+ )
238
260
  try {
239
261
  if (localFileExisted) {
240
262
  nativeBinding = require('./svgo-rs.linux-riscv64-musl.node')
@@ -245,7 +267,9 @@ switch (platform) {
245
267
  loadError = e
246
268
  }
247
269
  } else {
248
- localFileExisted = existsSync(join(__dirname, 'svgo-rs.linux-riscv64-gnu.node'))
270
+ localFileExisted = existsSync(
271
+ join(__dirname, 'svgo-rs.linux-riscv64-gnu.node')
272
+ )
249
273
  try {
250
274
  if (localFileExisted) {
251
275
  nativeBinding = require('./svgo-rs.linux-riscv64-gnu.node')
@@ -258,7 +282,9 @@ switch (platform) {
258
282
  }
259
283
  break
260
284
  case 's390x':
261
- localFileExisted = existsSync(join(__dirname, 'svgo-rs.linux-s390x-gnu.node'))
285
+ localFileExisted = existsSync(
286
+ join(__dirname, 'svgo-rs.linux-s390x-gnu.node')
287
+ )
262
288
  try {
263
289
  if (localFileExisted) {
264
290
  nativeBinding = require('./svgo-rs.linux-s390x-gnu.node')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@svg-rs/svgo",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Node.js tool for optimizing SVG files by Rust.",
5
5
  "main": "index.js",
6
6
  "repository": "https://github.com/oxidized-world/svgo-rs",
@@ -8,10 +8,9 @@
8
8
  "keywords": [
9
9
  "napi-rs",
10
10
  "NAPI",
11
- "N-API",
12
11
  "Rust",
13
- "node-addon",
14
- "node-addon-api"
12
+ "svgo",
13
+ "svg optimizing"
15
14
  ],
16
15
  "files": [
17
16
  "index.d.ts",
@@ -47,11 +46,10 @@
47
46
  "bench": "node --import @swc-node/register/esm-register benchmark/bench.ts",
48
47
  "build": "napi build --platform --release",
49
48
  "build:debug": "napi build --platform",
50
- "format": "run-p format:prettier format:rs format:toml",
51
- "format:prettier": "prettier . -w",
49
+ "format": "format:rs && format:toml",
52
50
  "format:toml": "taplo format",
53
51
  "format:rs": "cargo fmt",
54
- "lint": "oxlint .",
52
+ "lint": "biome lint --write",
55
53
  "prepublishOnly": "napi prepublish -t npm",
56
54
  "test": "vitest run",
57
55
  "test:watch": "vitest",
@@ -59,27 +57,21 @@
59
57
  "postinstall": "husky"
60
58
  },
61
59
  "devDependencies": {
60
+ "@biomejs/biome": "^1.9.4",
62
61
  "@napi-rs/cli": "^2.18.4",
63
- "@swc-node/register": "^1.10.6",
64
- "@swc/core": "^1.6.13",
62
+ "@swc-node/register": "^1.10.10",
63
+ "@swc/core": "^1.11.21",
65
64
  "@taplo/cli": "^0.7.0",
66
- "chalk": "^5.3.0",
67
- "husky": "^9.0.11",
68
- "lint-staged": "^15.2.7",
69
- "npm-run-all2": "^7.0.0",
70
- "oxlint": "^0.15.0",
71
- "prettier": "^3.3.3",
65
+ "husky": "^9.1.7",
66
+ "lint-staged": "^15.5.1",
72
67
  "svgo": "^3.3.2",
73
- "tinybench": "^3.0.0",
74
- "typescript": "^5.5.3",
75
- "vitest": "^3.0.4"
68
+ "tinybench": "^4.0.1",
69
+ "typescript": "^5.8.3",
70
+ "vitest": "^3.1.2"
76
71
  },
77
72
  "lint-staged": {
78
- "*.@(js|ts|tsx)": [
79
- "oxlint --fix"
80
- ],
81
73
  "*.@(js|ts|tsx|yml|yaml|md|json)": [
82
- "prettier --write"
74
+ "biome lint --write"
83
75
  ],
84
76
  "*.toml": [
85
77
  "taplo format"
@@ -88,27 +80,20 @@
88
80
  "cargo fmt --"
89
81
  ]
90
82
  },
91
- "prettier": {
92
- "printWidth": 120,
93
- "semi": false,
94
- "trailingComma": "all",
95
- "singleQuote": true,
96
- "arrowParens": "always"
97
- },
98
- "packageManager": "yarn@4.6.0",
83
+ "packageManager": "yarn@4.9.1",
99
84
  "optionalDependencies": {
100
- "@svg-rs/svgo-win32-x64-msvc": "0.0.3",
101
- "@svg-rs/svgo-darwin-x64": "0.0.3",
102
- "@svg-rs/svgo-linux-x64-gnu": "0.0.3",
103
- "@svg-rs/svgo-linux-x64-musl": "0.0.3",
104
- "@svg-rs/svgo-linux-arm64-gnu": "0.0.3",
105
- "@svg-rs/svgo-win32-ia32-msvc": "0.0.3",
106
- "@svg-rs/svgo-linux-arm-gnueabihf": "0.0.3",
107
- "@svg-rs/svgo-darwin-arm64": "0.0.3",
108
- "@svg-rs/svgo-android-arm64": "0.0.3",
109
- "@svg-rs/svgo-freebsd-x64": "0.0.3",
110
- "@svg-rs/svgo-linux-arm64-musl": "0.0.3",
111
- "@svg-rs/svgo-win32-arm64-msvc": "0.0.3",
112
- "@svg-rs/svgo-android-arm-eabi": "0.0.3"
85
+ "@svg-rs/svgo-win32-x64-msvc": "0.0.4",
86
+ "@svg-rs/svgo-darwin-x64": "0.0.4",
87
+ "@svg-rs/svgo-linux-x64-gnu": "0.0.4",
88
+ "@svg-rs/svgo-linux-x64-musl": "0.0.4",
89
+ "@svg-rs/svgo-linux-arm64-gnu": "0.0.4",
90
+ "@svg-rs/svgo-win32-ia32-msvc": "0.0.4",
91
+ "@svg-rs/svgo-linux-arm-gnueabihf": "0.0.4",
92
+ "@svg-rs/svgo-darwin-arm64": "0.0.4",
93
+ "@svg-rs/svgo-android-arm64": "0.0.4",
94
+ "@svg-rs/svgo-freebsd-x64": "0.0.4",
95
+ "@svg-rs/svgo-linux-arm64-musl": "0.0.4",
96
+ "@svg-rs/svgo-win32-arm64-msvc": "0.0.4",
97
+ "@svg-rs/svgo-android-arm-eabi": "0.0.4"
113
98
  }
114
99
  }