happy-rusty 1.0.7 → 1.0.9
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.cn.md +22 -5
- package/README.md +26 -9
- package/dist/types.d.ts +12 -0
- package/package.json +13 -13
- package/src/mod.ts +16 -0
package/README.cn.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# 在JavaScript中使用Rust特性
|
|
2
2
|
|
|
3
|
+
[](https://npmjs.org/package/happy-rusty)
|
|
4
|
+
[](https://jsr.io/@happy-js/happy-rusty)
|
|
5
|
+
[](https://jsr.io/@happy-js/happy-rusty/score)
|
|
6
|
+
[](https://github.com/jiangjie/happy-rusty/actions/workflows/test.yml)
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
3
10
|
## 部分支持的特性
|
|
4
11
|
|
|
5
12
|
* [option](https://doc.rust-lang.org/core/option/index.html)
|
|
@@ -9,16 +16,26 @@
|
|
|
9
16
|
|
|
10
17
|
## 安装
|
|
11
18
|
|
|
12
|
-
|
|
19
|
+
pnpm
|
|
20
|
+
```
|
|
21
|
+
pnpm add happy-rusty
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
yarn
|
|
13
25
|
```
|
|
14
|
-
|
|
26
|
+
yarn add happy-rusty
|
|
15
27
|
```
|
|
16
28
|
|
|
17
|
-
|
|
29
|
+
npm
|
|
18
30
|
```
|
|
19
31
|
npm install --save happy-rusty
|
|
20
32
|
```
|
|
21
33
|
|
|
34
|
+
通过 JSR
|
|
35
|
+
```
|
|
36
|
+
jsr add @happy-js/happy-rusty
|
|
37
|
+
```
|
|
38
|
+
|
|
22
39
|
通过 deno
|
|
23
40
|
```
|
|
24
41
|
deno add @happy-js/happy-rusty
|
|
@@ -31,13 +48,13 @@ bunx jsr add @happy-js/happy-rusty
|
|
|
31
48
|
|
|
32
49
|
接下来就可以在代码里引用了。
|
|
33
50
|
```ts
|
|
34
|
-
import { Some, None, Ok, Err } from '
|
|
51
|
+
import { Some, None, Ok, Err } from 'happy-rusty';
|
|
35
52
|
```
|
|
36
53
|
|
|
37
54
|
## 示例
|
|
38
55
|
|
|
39
56
|
```ts
|
|
40
|
-
import { Some, None, Ok, Err } from '
|
|
57
|
+
import { Some, None, Ok, Err } from 'happy-rusty';
|
|
41
58
|
|
|
42
59
|
function judge(n: number): Option<Promise<Result<number, Error>>> {
|
|
43
60
|
if (n < 0 || n >= 1) {
|
package/README.md
CHANGED
|
@@ -1,21 +1,33 @@
|
|
|
1
|
-
<p align="center">
|
|
2
|
-
<a href="README.cn.md">[中文]</a>
|
|
3
|
-
</p>
|
|
4
|
-
|
|
5
1
|
# Use Rust features in JavaScript happily
|
|
6
2
|
|
|
3
|
+
[](https://npmjs.org/package/happy-rusty)
|
|
4
|
+
[](https://jsr.io/@happy-js/happy-rusty)
|
|
5
|
+
[](https://jsr.io/@happy-js/happy-rusty/score)
|
|
6
|
+
[](https://github.com/jiangjie/happy-rusty/actions/workflows/test.yml)
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
<a href="README.cn.md">[中文]</a>
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
7
14
|
## Partial supported
|
|
8
15
|
|
|
9
16
|
* [option](https://doc.rust-lang.org/core/option/index.html)
|
|
10
17
|
* [result](https://doc.rust-lang.org/core/result/index.html)
|
|
11
18
|
|
|
12
|
-
|
|
19
|
+
### More is coming
|
|
13
20
|
|
|
14
21
|
## Installation
|
|
15
22
|
|
|
16
|
-
|
|
23
|
+
via pnpm
|
|
17
24
|
```
|
|
18
|
-
|
|
25
|
+
pnpm add happy-rusty
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
or via yarn
|
|
29
|
+
```
|
|
30
|
+
yarn add happy-rusty
|
|
19
31
|
```
|
|
20
32
|
|
|
21
33
|
or just from npm
|
|
@@ -23,6 +35,11 @@ or just from npm
|
|
|
23
35
|
npm install --save happy-rusty
|
|
24
36
|
```
|
|
25
37
|
|
|
38
|
+
via JSR
|
|
39
|
+
```
|
|
40
|
+
jsr add @happy-js/happy-rusty
|
|
41
|
+
```
|
|
42
|
+
|
|
26
43
|
for deno
|
|
27
44
|
```
|
|
28
45
|
deno add @happy-js/happy-rusty
|
|
@@ -35,7 +52,7 @@ bunx jsr add @happy-js/happy-rusty
|
|
|
35
52
|
|
|
36
53
|
then import to your code.
|
|
37
54
|
```ts
|
|
38
|
-
import { Some, None, Ok, Err } from '
|
|
55
|
+
import { Some, None, Ok, Err } from 'happy-rusty';
|
|
39
56
|
```
|
|
40
57
|
|
|
41
58
|
Enjoy the happiness.
|
|
@@ -43,7 +60,7 @@ Enjoy the happiness.
|
|
|
43
60
|
## Examples
|
|
44
61
|
|
|
45
62
|
```ts
|
|
46
|
-
import { Some, None, Ok, Err } from '
|
|
63
|
+
import { Some, None, Ok, Err } from 'happy-rusty';
|
|
47
64
|
|
|
48
65
|
function judge(n: number): Option<Promise<Result<number, Error>>> {
|
|
49
66
|
if (n < 0 || n >= 1) {
|
package/dist/types.d.ts
CHANGED
|
@@ -124,9 +124,21 @@ interface Err<T, E> {
|
|
|
124
124
|
*/
|
|
125
125
|
declare function Err<T, E>(error: E): Result<T, E>;
|
|
126
126
|
|
|
127
|
+
/**
|
|
128
|
+
* The shorthand of Promise<Option<T>>.
|
|
129
|
+
*/
|
|
127
130
|
type AsyncOption<T> = Promise<Option<T>>;
|
|
131
|
+
/**
|
|
132
|
+
* The shorthand of Promise<Result<T, E>>.
|
|
133
|
+
*/
|
|
128
134
|
type AsyncResult<T, E> = Promise<Result<T, E>>;
|
|
135
|
+
/**
|
|
136
|
+
* The shorthand of Result<T, Error>.
|
|
137
|
+
*/
|
|
129
138
|
type IOResult<T> = Result<T, Error>;
|
|
139
|
+
/**
|
|
140
|
+
* The shorthand of Promise<Result<T, Error>>.
|
|
141
|
+
*/
|
|
130
142
|
type AsyncIOResult<T> = Promise<IOResult<T>>;
|
|
131
143
|
|
|
132
144
|
export { type AsyncIOResult, type AsyncOption, type AsyncResult, Err, type IOResult, None, Ok, type Option, type Result, Some };
|
package/package.json
CHANGED
|
@@ -3,13 +3,12 @@
|
|
|
3
3
|
"description": "Porting some excellent design implementations from Rust to JavaScript.",
|
|
4
4
|
"author": "jiang115jie@gmail.com",
|
|
5
5
|
"license": "GPL-3.0",
|
|
6
|
-
"version": "1.0.
|
|
6
|
+
"version": "1.0.9",
|
|
7
7
|
"type": "module",
|
|
8
|
-
"source": "
|
|
9
|
-
"main": "
|
|
10
|
-
"module": "
|
|
11
|
-
"types": "
|
|
12
|
-
"exports": "./src/mod.ts",
|
|
8
|
+
"source": "src/mod.ts",
|
|
9
|
+
"main": "dist/main.cjs",
|
|
10
|
+
"module": "dist/main.mjs",
|
|
11
|
+
"types": "dist/types.d.ts",
|
|
13
12
|
"files": [
|
|
14
13
|
"LICENSE",
|
|
15
14
|
"README.md",
|
|
@@ -20,12 +19,12 @@
|
|
|
20
19
|
],
|
|
21
20
|
"sideEffects": false,
|
|
22
21
|
"scripts": {
|
|
23
|
-
"check": "
|
|
24
|
-
"lint": "
|
|
25
|
-
"prebuild": "
|
|
26
|
-
"build": "
|
|
27
|
-
"test": "bun test",
|
|
28
|
-
"prepublishOnly": "
|
|
22
|
+
"check": "pnpm exec tsc --noEmit",
|
|
23
|
+
"lint": "pnpm exec eslint src/",
|
|
24
|
+
"prebuild": "pnpm exec rimraf dist && pnpm run check && pnpm run lint",
|
|
25
|
+
"build": "pnpm exec rollup --config rollup.config.mjs",
|
|
26
|
+
"test": "bun test --coverage",
|
|
27
|
+
"prepublishOnly": "pnpm run build"
|
|
29
28
|
},
|
|
30
29
|
"repository": {
|
|
31
30
|
"type": "git",
|
|
@@ -51,5 +50,6 @@
|
|
|
51
50
|
"rollup-plugin-dts": "^6.1.0",
|
|
52
51
|
"rollup-plugin-esbuild": "^6.1.1",
|
|
53
52
|
"typescript": "^5.4.5"
|
|
54
|
-
}
|
|
53
|
+
},
|
|
54
|
+
"packageManager": "pnpm@9.1.1+sha512.14e915759c11f77eac07faba4d019c193ec8637229e62ec99eefb7cf3c3b75c64447882b7c485142451ee3a6b408059cdfb7b7fa0341b975f12d0f7629c71195"
|
|
55
55
|
}
|
package/src/mod.ts
CHANGED
|
@@ -5,7 +5,23 @@ export { None, Some, type Option } from './enum/option.ts';
|
|
|
5
5
|
export { Err, Ok, type Result } from './enum/result.ts';
|
|
6
6
|
|
|
7
7
|
// export some commonly used types
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The shorthand of Promise<Option<T>>.
|
|
11
|
+
*/
|
|
8
12
|
export type AsyncOption<T> = Promise<Option<T>>;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The shorthand of Promise<Result<T, E>>.
|
|
16
|
+
*/
|
|
9
17
|
export type AsyncResult<T, E> = Promise<Result<T, E>>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The shorthand of Result<T, Error>.
|
|
21
|
+
*/
|
|
10
22
|
export type IOResult<T> = Result<T, Error>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The shorthand of Promise<Result<T, Error>>.
|
|
26
|
+
*/
|
|
11
27
|
export type AsyncIOResult<T> = Promise<IOResult<T>>;
|