mirror of
https://github.com/jaywcjlove/reference.git
synced 2025-06-16 20:21:22 +08:00
Compare commits
67 Commits
Author | SHA1 | Date | |
---|---|---|---|
1fda256237 | |||
f9ca460565 | |||
8e265becb5 | |||
e1639d0ce0 | |||
f5f05aacf5 | |||
90c80e720e | |||
823b3163d4 | |||
fe562e5fb1 | |||
85c4149e1c | |||
e849f19712 | |||
71e5470efd | |||
38d79cd2a0 | |||
0e0eb9c628 | |||
7b46142372 | |||
41b42c17b7 | |||
cfb0b98673 | |||
8a9d9de14b | |||
c2cb9fa3d7 | |||
11edef0d1b | |||
b13ca7ee0a | |||
5f6029a051 | |||
8592dff419 | |||
bb817cbb40 | |||
0bc31c68c3 | |||
aab4d3bcff | |||
a3ddc58b0a | |||
c4398d5220 | |||
ada64ac643 | |||
84876edb2e | |||
0c8dddf8e7 | |||
edaf531b50 | |||
2200972ce7 | |||
aaa0f1f523 | |||
465cdc7bc1 | |||
c97f6a7bca | |||
8f980a92c1 | |||
4f0198877b | |||
e0ccae5659 | |||
c40b5ecb85 | |||
9c3ad5a300 | |||
3bac78a4d0 | |||
9db2ce1974 | |||
345bb9013d | |||
4eedb2bcbe | |||
63739bff97 | |||
a4650ba20b | |||
304fca65aa | |||
7dab4bc821 | |||
a3a03dc5cf | |||
c4027826df | |||
ec5de21ad8 | |||
2d29bce40d | |||
45916503c1 | |||
7dab833cb5 | |||
2787e80dd2 | |||
51377308ab | |||
5660ad20dd | |||
0917f70be8 | |||
dcbdaea754 | |||
144f263ad0 | |||
ef5a27f5a1 | |||
82457e896e | |||
d796def71c | |||
8cb9a8eaa4 | |||
739697937d | |||
4ce6660ca8 | |||
5677612d9d |
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@ -0,0 +1 @@
|
||||
*.md linguist-detectable=true
|
15
.github/workflows/ci.yml
vendored
15
.github/workflows/ci.yml
vendored
@ -18,11 +18,26 @@ jobs:
|
||||
|
||||
- name: Generate Contributors Images
|
||||
uses: jaywcjlove/github-action-contributors@main
|
||||
id: contributors
|
||||
with:
|
||||
filter-author: (renovate\[bot\]|renovate-bot|dependabot\[bot\])
|
||||
output: dist/CONTRIBUTORS.svg
|
||||
avatarSize: 42
|
||||
|
||||
- name: Modify CONTRIBUTING.md
|
||||
uses: jaywcjlove/github-action-modify-file-content@main
|
||||
with:
|
||||
path: CONTRIBUTING.md
|
||||
body: |
|
||||
${{steps.contributors.outputs.htmlList}}
|
||||
|
||||
- name: Modify README.md
|
||||
uses: jaywcjlove/github-action-modify-file-content@main
|
||||
with:
|
||||
path: README.md
|
||||
body: |
|
||||
${{steps.contributors.outputs.htmlList}}
|
||||
|
||||
- name: Create Tag
|
||||
id: create_tag
|
||||
uses: jaywcjlove/create-tag-action@main
|
||||
|
@ -83,4 +83,67 @@ npm run build # 编译输出 HTML
|
||||
npm run start # 监听 md 文件编译输出 HTML
|
||||
```
|
||||
|
||||
- 或者你也可以使用 `pnpm` 或者 `yarn` 做为包管理器
|
||||
或者你也可以使用 `pnpm` 或者 `yarn` 做为包管理器
|
||||
|
||||
|
||||
## 贡献
|
||||
|
||||
请参阅[贡献指南](./CONTRIBUTING.md)了解如何开始。一如既往,感谢我们出色的贡献者!
|
||||
|
||||
<!--GAMFC--><a href="https://github.com/jaywcjlove" title="小弟调调™">
|
||||
<img src="https://avatars.githubusercontent.com/u/1680273?v=4" width="42;" alt="小弟调调™"/>
|
||||
</a>
|
||||
<a href="https://github.com/Jack-Zhang-1314" title="fw_qaq">
|
||||
<img src="https://avatars.githubusercontent.com/u/82551626?v=4" width="42;" alt="fw_qaq"/>
|
||||
</a>
|
||||
<a href="https://github.com/catcto" title="喵仙人">
|
||||
<img src="https://avatars.githubusercontent.com/u/5467932?v=4" width="42;" alt="喵仙人"/>
|
||||
</a>
|
||||
<a href="https://github.com/CharlotteZeng" title="Chart">
|
||||
<img src="https://avatars.githubusercontent.com/u/19461184?v=4" width="42;" alt="Chart"/>
|
||||
</a>
|
||||
<a href="https://github.com/demigodliu" title="DemigodLiu">
|
||||
<img src="https://avatars.githubusercontent.com/u/30372735?v=4" width="42;" alt="DemigodLiu"/>
|
||||
</a>
|
||||
<a href="https://github.com/jasnzhuang" title="Jason Zhuang">
|
||||
<img src="https://avatars.githubusercontent.com/u/16612921?v=4" width="42;" alt="Jason Zhuang"/>
|
||||
</a>
|
||||
<a href="https://github.com/JetSquirrel" title="JetSquirrel">
|
||||
<img src="https://avatars.githubusercontent.com/u/20291255?v=4" width="42;" alt="JetSquirrel"/>
|
||||
</a>
|
||||
<a href="https://github.com/HanaNoryu" title="Noryu">
|
||||
<img src="https://avatars.githubusercontent.com/u/109856546?v=4" width="42;" alt="Noryu"/>
|
||||
</a>
|
||||
<a href="https://github.com/gaoxiaoduan" title="coderduan">
|
||||
<img src="https://avatars.githubusercontent.com/u/69953511?v=4" width="42;" alt="coderduan"/>
|
||||
</a>
|
||||
<a href="https://github.com/cool9203" title="cool9203">
|
||||
<img src="https://avatars.githubusercontent.com/u/29609607?v=4" width="42;" alt="cool9203"/>
|
||||
</a>
|
||||
<a href="https://github.com/hua03" title="hua03">
|
||||
<img src="https://avatars.githubusercontent.com/u/19561959?v=4" width="42;" alt="hua03"/>
|
||||
</a>
|
||||
<a href="https://github.com/hweining" title="hweining">
|
||||
<img src="https://avatars.githubusercontent.com/u/8973985?v=4" width="42;" alt="hweining"/>
|
||||
</a>
|
||||
<a href="https://github.com/liliangrong777" title="liliangrong777">
|
||||
<img src="https://avatars.githubusercontent.com/u/58727146?v=4" width="42;" alt="liliangrong777"/>
|
||||
</a>
|
||||
<a href="https://github.com/onewesong" title="onewesong">
|
||||
<img src="https://avatars.githubusercontent.com/u/17920822?v=4" width="42;" alt="onewesong"/>
|
||||
</a>
|
||||
<a href="https://github.com/ryanhex53" title="ryanhex53">
|
||||
<img src="https://avatars.githubusercontent.com/u/360426?v=4" width="42;" alt="ryanhex53"/>
|
||||
</a>
|
||||
<a href="https://github.com/zxx-457" title="zxx-457">
|
||||
<img src="https://avatars.githubusercontent.com/u/114141362?v=4" width="42;" alt="zxx-457"/>
|
||||
</a>
|
||||
<a href="https://github.com/lvzhenbo" title="吕振波">
|
||||
<img src="https://avatars.githubusercontent.com/u/32427677?v=4" width="42;" alt="吕振波"/>
|
||||
</a><!--GAMFC-END-->
|
||||
|
||||
上图贡献者列表,由 [contributors](https://github.com/jaywcjlove/github-action-contributors) 自动生成贡献者图片。
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Kenny Wong](https://github.com/jaywcjlove)
|
||||
|
77
README.md
77
README.md
@ -21,8 +21,10 @@ Quick Reference
|
||||
|
||||
[Ansible](./docs/ansible.md)<!--rehype:style=background: rgb(238 0 0/var(\-\-bg\-opacity));&class=contributing tag&data-lang=RedHad&data-info=👆看看还缺点儿什么?-->
|
||||
[CMake](./docs/cmake.md)<!--rehype:style=background: rgb(92 107 192/var(\-\-bg\-opacity));&class=contributing-->
|
||||
[C#](./docs/cs.md)<!--rehype:style=background: rgb(6 147 13/var(\-\-bg\-opacity));&class=contributing-->
|
||||
[Django](./docs/djiango.md)<!--rehype:style=background: rgb(12 75 51/var(\-\-bg\-opacity));&class=contributing tag&data-lang=Python-->
|
||||
[FFmpeg](./docs/ffmpeg.md)<!--rehype:style=background: rgb(0 193 9/var(\-\-bg\-opacity));&class=contributing-->
|
||||
[LaTeX](./docs/latex.md)<!--rehype:style=background: rgb(0 128 128/var(\-\-bg\-opacity));&class=contributing-->
|
||||
[MATLAB](./docs/matlab.md)<!--rehype:style=background: rgb(0 118 168/var(\-\-bg\-opacity));&class=contributing-->
|
||||
[Vue 3 ](./docs/vue.md)<!--rehype:style=background: rgb(64 184 131/var(\-\-bg\-opacity));&class=contributing-->
|
||||
<!--rehype:class=home-card-->
|
||||
@ -31,6 +33,8 @@ Quick Reference
|
||||
|
||||
[Bash](./docs/bash.md)<!--rehype:style=background: rgb(72 143 223/var(\-\-bg\-opacity));-->
|
||||
[C](./docs/c.md)<!--rehype:style=background: rgb(92 107 192/var(\-\-bg\-opacity));-->
|
||||
[C#](./docs/cs.md)<!--rehype:style=background: rgb(6 147 13/var(\-\-bg\-opacity));&class=contributing-->
|
||||
[Dart](./docs/dart.md)<!--rehype:style=background: rgb(64 196 255/var(\-\-bg\-opacity));-->
|
||||
[Docker](./docs/docker.md)<!--rehype:style=background: rgb(72 143 223/var(\-\-bg\-opacity));-->
|
||||
[Dockerfile](./docs/dockerfile.md)<!--rehype:style=background: rgb(0 72 153/var(\-\-bg\-opacity));&class=tag&data-lang=Docker-->
|
||||
[Django](./docs/djiango.md)<!--rehype:style=background: rgb(12 75 51/var(\-\-bg\-opacity));&class=contributing tag&data-lang=Python-->
|
||||
@ -39,12 +43,15 @@ Quick Reference
|
||||
[INI](./docs/ini.md)<!--rehype:style=background: rgb(57 59 60/var(\-\-bg\-opacity));-->
|
||||
[JSON](./docs/json.md)<!--rehype:style=background: rgb(57 59 60/var(\-\-bg\-opacity));-->
|
||||
[Java](./docs/java.md)<!--rehype:style=background: rgb(211 55 49/var(\-\-bg\-opacity));&class=contributing&data-info=👆看看还缺点儿什么?-->
|
||||
[Julia](./docs/julia.md)<!--rehype:style=background: rgb(211 55 49/var(\-\-bg\-opacity));&class=contributing&data-info=👆看看还缺点儿什么?-->
|
||||
[LaTeX](./docs/latex.md)<!--rehype:style=background: rgb(0 128 128/var(\-\-bg\-opacity));&class=contributing-->
|
||||
[Markdown](./docs/markdown.md)<!--rehype:style=background: rgb(103 61 156/var(\-\-bg\-opacity));-->
|
||||
[MySQL](./docs/mysql.md)<!--rehype:style=background: rgb(103 61 156/var(\-\-bg\-opacity));&class=tag&data-lang=SQL-->
|
||||
[MySQL](./docs/mysql.md)<!--rehype:style=background: rgb(1 117 143/var(\-\-bg\-opacity));&class=tag&data-lang=SQL-->
|
||||
[MATLAB](./docs/matlab.md)<!--rehype:style=background: rgb(0 118 168/var(\-\-bg\-opacity));&class=contributing-->
|
||||
[Python](./docs/python.md)<!--rehype:style=background: rgb(240 81 57/var(\-\-bg\-opacity));-->
|
||||
[PHP](./docs/php.md)<!--rehype:style=background: rgb(79 91 147/var(\-\-bg\-opacity));-->
|
||||
[Python](./docs/python.md)<!--rehype:style=background: rgb(43 91 132/var(\-\-bg\-opacity));-->
|
||||
[PostgreSQL](./docs/postgres.md)<!--rehype:style=background: rgb(43 109 163/var(\-\-bg\-opacity));&class=tag&data-lang=SQL-->
|
||||
[Ruby](./docs/ruby.md)<!--rehype:style=background: rgb(71 71 71/var(\-\-bg\-opacity));-->
|
||||
[Ruby](./docs/ruby.md)<!--rehype:style=background: rgb(204 52 45/var(\-\-bg\-opacity));-->
|
||||
[Rust](./docs/rust.md)<!--rehype:style=background: rgb(71 71 71/var(\-\-bg\-opacity));-->
|
||||
[Swift](./docs/swift.md)<!--rehype:style=background: rgb(240 81 57/var(\-\-bg\-opacity));-->
|
||||
[SwiftUI](./docs/swiftui.md)<!--rehype:style=background: rgb(10 127 247/var(\-\-bg\-opacity));&class=tag&data-lang=swift-->
|
||||
@ -102,6 +109,7 @@ Quick Reference
|
||||
[Ansible](./docs/ansible.md)<!--rehype:style=background: rgb(238 0 0/var(\-\-bg\-opacity));&class=contributing tag&data-lang=RedHad&data-info=👆看看还缺点儿什么?-->
|
||||
[Awk](./docs/awk.md)<!--rehype:style=background: rgb(16 185 129/var(\-\-bg\-opacity));-->
|
||||
[Conan](./docs/conan.md)<!--rehype:style=background: rgb(0 193 9/var(\-\-bg\-opacity));&class=tag&data-lang=C/C++-->
|
||||
[CocoaPods](./docs/cocoapods.md)<!--rehype:style=background: rgb(251 0 6/var(\-\-bg\-opacity));&class=tag&data-lang=C/C++-->
|
||||
[Cargo](./docs/cargo.md)<!--rehype:style=background: rgb(71 71 71/var(\-\-bg\-opacity));&class=tag&data-lang=Rust-->
|
||||
[Curl](./docs/curl.md)<!--rehype:style=background: rgb(16 185 129/var(\-\-bg\-opacity));-->
|
||||
[Chmod](./docs/chmod.md)<!--rehype:style=background: rgb(16 185 129/var(\-\-bg\-opacity));-->
|
||||
@ -147,17 +155,68 @@ Quick Reference
|
||||
[`我有一张备忘单(速查表)`](https://github.com/jaywcjlove/reference/blob/main/CONTRIBUTING.md)<!--rehype:class=home-button text-grey&target=__blank-->
|
||||
<!--rehype:style=margin-top:3rem-->
|
||||
|
||||
<!--rehype:ignore:start-->
|
||||
## 贡献
|
||||
## 感谢所有贡献者
|
||||
<!--rehype:wrap-style=text-align: center;max-width: 650px;margin: 0 auto;&class=home-title-reset-->
|
||||
|
||||
请参阅[贡献指南](./CONTRIBUTING.md)了解如何开始。一如既往,感谢我们出色的贡献者!
|
||||
请参阅 [Quick Reference](./docs/quickreference.md) 了解如何开始。一如既往,感谢我们出色的贡献者!
|
||||
<!--rehype:style=padding-bottom:1rem;-->
|
||||
|
||||
<a href="https://github.com/jaywcjlove/reference/graphs/contributors">
|
||||
<img src="https://jaywcjlove.github.io/reference/CONTRIBUTORS.svg" />
|
||||
<!--GAMFC--><a href="https://github.com/jaywcjlove" title="小弟调调™">
|
||||
<img src="https://avatars.githubusercontent.com/u/1680273?v=4" width="42;" alt="小弟调调™"/>
|
||||
</a>
|
||||
<a href="https://github.com/Jack-Zhang-1314" title="fw_qaq">
|
||||
<img src="https://avatars.githubusercontent.com/u/82551626?v=4" width="42;" alt="fw_qaq"/>
|
||||
</a>
|
||||
<a href="https://github.com/catcto" title="喵仙人">
|
||||
<img src="https://avatars.githubusercontent.com/u/5467932?v=4" width="42;" alt="喵仙人"/>
|
||||
</a>
|
||||
<a href="https://github.com/CharlotteZeng" title="Chart">
|
||||
<img src="https://avatars.githubusercontent.com/u/19461184?v=4" width="42;" alt="Chart"/>
|
||||
</a>
|
||||
<a href="https://github.com/demigodliu" title="DemigodLiu">
|
||||
<img src="https://avatars.githubusercontent.com/u/30372735?v=4" width="42;" alt="DemigodLiu"/>
|
||||
</a>
|
||||
<a href="https://github.com/jasnzhuang" title="Jason Zhuang">
|
||||
<img src="https://avatars.githubusercontent.com/u/16612921?v=4" width="42;" alt="Jason Zhuang"/>
|
||||
</a>
|
||||
<a href="https://github.com/JetSquirrel" title="JetSquirrel">
|
||||
<img src="https://avatars.githubusercontent.com/u/20291255?v=4" width="42;" alt="JetSquirrel"/>
|
||||
</a>
|
||||
<a href="https://github.com/HanaNoryu" title="Noryu">
|
||||
<img src="https://avatars.githubusercontent.com/u/109856546?v=4" width="42;" alt="Noryu"/>
|
||||
</a>
|
||||
<a href="https://github.com/gaoxiaoduan" title="coderduan">
|
||||
<img src="https://avatars.githubusercontent.com/u/69953511?v=4" width="42;" alt="coderduan"/>
|
||||
</a>
|
||||
<a href="https://github.com/cool9203" title="cool9203">
|
||||
<img src="https://avatars.githubusercontent.com/u/29609607?v=4" width="42;" alt="cool9203"/>
|
||||
</a>
|
||||
<a href="https://github.com/hua03" title="hua03">
|
||||
<img src="https://avatars.githubusercontent.com/u/19561959?v=4" width="42;" alt="hua03"/>
|
||||
</a>
|
||||
<a href="https://github.com/hweining" title="hweining">
|
||||
<img src="https://avatars.githubusercontent.com/u/8973985?v=4" width="42;" alt="hweining"/>
|
||||
</a>
|
||||
<a href="https://github.com/liliangrong777" title="liliangrong777">
|
||||
<img src="https://avatars.githubusercontent.com/u/58727146?v=4" width="42;" alt="liliangrong777"/>
|
||||
</a>
|
||||
<a href="https://github.com/onewesong" title="onewesong">
|
||||
<img src="https://avatars.githubusercontent.com/u/17920822?v=4" width="42;" alt="onewesong"/>
|
||||
</a>
|
||||
<a href="https://github.com/ryanhex53" title="ryanhex53">
|
||||
<img src="https://avatars.githubusercontent.com/u/360426?v=4" width="42;" alt="ryanhex53"/>
|
||||
</a>
|
||||
<a href="https://github.com/zxx-457" title="zxx-457">
|
||||
<img src="https://avatars.githubusercontent.com/u/114141362?v=4" width="42;" alt="zxx-457"/>
|
||||
</a>
|
||||
<a href="https://github.com/lvzhenbo" title="吕振波">
|
||||
<img src="https://avatars.githubusercontent.com/u/32427677?v=4" width="42;" alt="吕振波"/>
|
||||
</a><!--GAMFC-END-->
|
||||
|
||||
上图贡献者列表,由 [contributors](https://github.com/jaywcjlove/github-action-contributors) 自动生成贡献者图片。
|
||||
贡献者列表,由 [contributors](https://github.com/jaywcjlove/github-action-contributors) 自动生成
|
||||
<!--rehype:style=padding-top:1rem;-->
|
||||
|
||||
<!--rehype:ignore:start-->
|
||||
## License
|
||||
|
||||
MIT © [Kenny Wong](https://github.com/jaywcjlove)
|
||||
|
@ -127,24 +127,27 @@ $ cargo run
|
||||
Hello, world!
|
||||
```
|
||||
|
||||
### 项目目录
|
||||
### 来源配置
|
||||
|
||||
```bash
|
||||
.
|
||||
├── Cargo.lock
|
||||
├── Cargo.toml
|
||||
├── benches # 基准目录
|
||||
│ └── large-input.rs
|
||||
├── examples # 示例
|
||||
│ └── simple.rs
|
||||
├── src # 源代码
|
||||
│ ├── bin
|
||||
│ │ └── another_executable.rs
|
||||
│ ├── lib.rs # 默认库
|
||||
│ └── main.rs # 入口文件
|
||||
└── tests # 集成测试
|
||||
└── some-integration-tests.rs
|
||||
```toml
|
||||
# `source` 表下,就是存储有关要更换的来源名称
|
||||
[source]
|
||||
|
||||
# 在`source` 表格之下的,可为一定数量的有关来源名称. 示例下面就,定义了一个新源, 叫 `my-awesome-source`,其内容来自本地,`vendor`目录 ,其相对于包含 `.cargo/config` 文件的目录
|
||||
[source.my-awesome-source]
|
||||
directory = "vendor"
|
||||
|
||||
# Git sources 也指定一个 branch/tag/rev
|
||||
git = "https://example.com/path/to/repo"
|
||||
# branch = "master"
|
||||
# tag = "v1.0.1"
|
||||
# rev = "313f44e8"
|
||||
|
||||
# crates.io 默认源 在"crates-io"名称下,且在这里我们使用 `replace-with` 字段指明 默认源更换成"my-awesome-source"源
|
||||
[source.crates-io]
|
||||
replace-with = "my-awesome-source"
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### 编译测试
|
||||
|
||||
@ -154,10 +157,22 @@ $ cargo build
|
||||
# 输出二进制文件,放入 `target/release` 目录
|
||||
$ cargo build --release
|
||||
$ cargo run # 编译并运行
|
||||
$ cargo test # 运行您的测试
|
||||
$ cargo test foo # 传递过滤器,来运行特定测试
|
||||
```
|
||||
|
||||
#### 测试
|
||||
|
||||
```bash
|
||||
$ cargo test # 运行你的所有测试
|
||||
# 指定函数过滤器
|
||||
$ cargo test test_foo # 开头是 test_foo 的函数都会运行,例如(test_foo_bar)
|
||||
# 指定特定模块中的测试函数(通常可以简写 cargo test foo::bar::tests::test_foo)
|
||||
$ cargo test --package rustt --lib -- foo::bar::tests::test_foo --exact --nocapture
|
||||
|
||||
# 指定特定测试的模块(通常可以简写 cargo test foo::bar::tests)
|
||||
$ cargo test --package rustt --lib -- foo::bar::tests --nocapture
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 配置目标
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
@ -188,27 +203,24 @@ edition = '2015'
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 来源配置
|
||||
### 项目目录
|
||||
|
||||
```toml
|
||||
# `source` 表下,就是存储有关要更换的来源名称
|
||||
[source]
|
||||
|
||||
# 在`source` 表格之下的,可为一定数量的有关来源名称. 示例下面就,定义了一个新源, 叫 `my-awesome-source`,其内容来自本地,`vendor`目录 ,其相对于包含 `.cargo/config` 文件的目录
|
||||
[source.my-awesome-source]
|
||||
directory = "vendor"
|
||||
|
||||
# Git sources 也指定一个 branch/tag/rev
|
||||
git = "https://example.com/path/to/repo"
|
||||
# branch = "master"
|
||||
# tag = "v1.0.1"
|
||||
# rev = "313f44e8"
|
||||
|
||||
# crates.io 默认源 在"crates-io"名称下,且在这里我们使用 `replace-with` 字段指明 默认源更换成"my-awesome-source"源
|
||||
[source.crates-io]
|
||||
replace-with = "my-awesome-source"
|
||||
```bash
|
||||
.
|
||||
├── Cargo.lock
|
||||
├── Cargo.toml
|
||||
├── benches # 基准目录
|
||||
│ └── large-input.rs
|
||||
├── examples # 示例
|
||||
│ └── simple.rs
|
||||
├── src # 源代码
|
||||
│ ├── bin
|
||||
│ │ └── another_executable.rs
|
||||
│ ├── lib.rs # 默认库
|
||||
│ └── main.rs # 入口文件
|
||||
└── tests # 集成测试
|
||||
└── some-integration-tests.rs
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### 配置
|
||||
|
||||
|
261
docs/cocoapods.md
Normal file
261
docs/cocoapods.md
Normal file
@ -0,0 +1,261 @@
|
||||
CocoaPods 备忘清单
|
||||
===
|
||||
|
||||
[CocoaPods](https://en.wikipedia.org/wiki/Cron) 是 [Swift](./swift.md) 和 Objective-C Cocoa 项目的依赖管理器,此快速参考备忘单显示了它的常用命令使用清单。
|
||||
|
||||
入门
|
||||
---
|
||||
|
||||
### 安装
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```bash
|
||||
$ sudo gem install cocoapods
|
||||
```
|
||||
|
||||
无 Sudo 安装,不想为此过程授予 `RubyGems` 管理员权限
|
||||
|
||||
```bash
|
||||
export GEM_HOME=$HOME/.gem
|
||||
export PATH=$GEM_HOME/bin:$PATH
|
||||
```
|
||||
|
||||
编辑 `.bash_profile` 配置文件,添加上面内容
|
||||
|
||||
```bash
|
||||
$ gem install cocoapods --user-install
|
||||
$ gem which cocoapods
|
||||
/Users/wcj/.gem/ruby/2.0.0/gems/cocoapods-0.29.0/lib/cocoapods.rb
|
||||
$ /Users/wcj/.gem/ruby/2.0.0/bin/pod install
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 更新 CocoaPods
|
||||
|
||||
```bash
|
||||
$ gem install cocoapods
|
||||
```
|
||||
|
||||
或者对于预发布版本
|
||||
|
||||
```bash
|
||||
$ gem install cocoapods --pre
|
||||
```
|
||||
|
||||
### 安装
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```bash
|
||||
$ pod install
|
||||
```
|
||||
|
||||
在您的项目中安装新的 `pod`,即使你已经有一个 `Podfile` 并且之前运行过 `pod install`; 因此,即使您只是在已经使用 `CocoaPods` 的项目中添加/删除 `pod`
|
||||
|
||||
- 会在 `Podfile.lock` 文件中为每个 pod 写入已安装的版本,此文件跟踪每个 pod 的已安装版本并锁定这些版本
|
||||
- 它只会解析 `Podfile.lock` 中尚未列出的 pod 的依赖关系
|
||||
- 对于 `Podfile.lock` 中列出的 pod,会下载 `Podfile.lock` 中列出的显式版本,而不尝试检查是否有更新的版本可用
|
||||
|
||||
下载 `Podfile` 中定义的所有依赖项,并在 `./Pods` 中创建一个 `Xcode Pods` 库项目
|
||||
|
||||
### 更新过时的依赖
|
||||
|
||||
```bash
|
||||
$ pod outdated
|
||||
```
|
||||
|
||||
显示当前 `Podfile.lock` 中过时的 `pod`,但仅显示来自规范 `repos` 的那些,而不是来自本地/外部来源的那些
|
||||
|
||||
### 更新依赖
|
||||
|
||||
```bash
|
||||
$ pod update
|
||||
$ pod update PODNAME
|
||||
```
|
||||
|
||||
更新由指定 `pod` 名称标识的 `Pod`。 如果没有指定 `Pod` 名称,它会更新所有 `Pod`,而忽略 `Podfile.lock` 的内容。 此命令保留用于更新依赖项,应使用 `pod install` 安装对 `Podfile` 的更改
|
||||
|
||||
### 清理 Pods 依赖
|
||||
|
||||
```bash
|
||||
$ pod deintegrate
|
||||
```
|
||||
|
||||
从 `CocoaPods` 中分离您的项目。 从您的 `Xcode` 项目中删除所有 `CocoaPods` 的痕迹。如果未指定 `xcodeproj`,则将在当前目录中搜索 `Xcode` 项目
|
||||
|
||||
### pod env
|
||||
|
||||
```bash
|
||||
$ pod env
|
||||
```
|
||||
|
||||
显示 pod 环境
|
||||
|
||||
### 将 Pod 添加到 Xcode 项目
|
||||
|
||||
- 创建一个 Podfile,并添加您的依赖项
|
||||
|
||||
```ruby
|
||||
# Podfile
|
||||
target 'MyApp' do
|
||||
pod 'AFNetworking', '~> 3.0'
|
||||
pod 'FBSDKCoreKit', '~> 4.9'
|
||||
end
|
||||
```
|
||||
|
||||
- 在您的项目目录中运行 `$ pod install`
|
||||
- 打开 `App.xcworkspace` 并构建
|
||||
<!--rehype:className=style-timeline-->
|
||||
|
||||
### 创建一个新的 Cocoapod
|
||||
|
||||
命令 | 说明
|
||||
:-- | --
|
||||
`pod lib create pod_name` | 为您创建一个新的 pod 项目
|
||||
`pod trunk push pod_name.podspec` | 将 podspec 推送到 trunk
|
||||
`pod spec create pod_name` | 为您创建 podspec 模板
|
||||
<!--rehype:className=style-list-->
|
||||
|
||||
### 浏览
|
||||
|
||||
- `pod search QUERY` 搜索名称、摘要、描述或作者与 QUERY 匹配的 pod,忽略大小写。 如果指定了 --simple 选项,这将只搜索 pod 的名称
|
||||
- `pod list` 列出所有可用的 pod
|
||||
- `pod try NAME|URL` 下载具有给定名称(或 Git URL)的 Pod,如果需要,安装其依赖项并打开其演示项目。 如果提供了 Git URL,则使用 repo 的头部。 如果指定了 Git URL,则可以提供 --podspec_name,如果 podspec 名称由于某种原因与 git 存储库不同
|
||||
|
||||
### 规格
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
- `pod spec create [NAME\|https://github.com/USER/REPO]` 在当前工作目录中创建一个名为 NAME.podspec 的 PodSpec。如果传递了 GitHub url,则预先填充规范。
|
||||
- `pod spec lint [NAME.podspec|DIRECTORY|http://PATH/NAME.podspec ...]` 验证 NAME.podspec。 如果提供了 DIRECTORY,它会验证找到的 podspec 文件,包括子文件夹。 如果省略参数,则默认为当前工作目录。
|
||||
- `pod spec cat [QUERY]` 将名称与 QUERY 匹配的 podspec 的内容打印到标准输出。
|
||||
- `pod spec which [QUERY]` 打印名称与 QUERY 匹配的 .podspec 文件的路径
|
||||
- `pod spec edit [QUERY]` 打开要编辑的与 QUERY 匹配的 podspec。
|
||||
|
||||
### Repos
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
命令 | 说明
|
||||
:-- | --
|
||||
`pod repo add NAME URL [BRANCH]` | 在 `~/.cocoapods/repos/` 的本地 spec-repos 目录中克隆 URL。远程可以稍后由 NAME 引用
|
||||
`pod repo update [NAME]` | 更新 spec-repo NAME 的本地克隆。如果 NAME 被省略,这将更新 ~/.cocoapods/repos 中的所有 spec-repos
|
||||
`pod repo lint [NAME\|DIRECTORY]` | 对 spec-repo NAME 进行 lints。如果提供了目录,则假定它是存储库的根目录。最后,如果没有提供 NAME,这将 lint CocoaPods 已知的所有规范库
|
||||
`pod repo list` | 从 `~/.cocoapods/repos/` 的本地 spec-repos 目录中列出 repos
|
||||
`pod repo remove NAME` | 从 `~/.cocoapods/repos/` 的本地 spec-repos 目录中删除名为 NAME 的远程
|
||||
`pod repo push REPO [NAME.podspec]` | 验证当前工作目录中的 `NAME.podspec` 或 \*.podspec,在 REPO 的本地副本 (`~/.cocoapods/repos/[REPO]`) 中为 pod 创建目录和版本文件夹,将 podspec 文件复制到版本中目录,最后它将 REPO 推送到其远程
|
||||
`pod setup` | 在 `~/.cocoapods/repos` 创建一个目录,该目录将保存您的规范存储库。它将在这里创建公共主规范仓库的克隆:<https://github.com/CocoaPods/Specs> 如果克隆已经存在,它将确保它是最新的
|
||||
<!--rehype:className=style-list-arrow-->
|
||||
|
||||
### Trunk
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
- `pod trunk add-owner POD OWNER-EMAIL` 将具有指定 OWNER-EMAIL 的注册用户添加为给定 POD 的 `owner`
|
||||
- `pod trunk info NAME` 返回有关 Pod 的信息
|
||||
- `pod trunk me` 包括有关您的注册的信息,然后是您的所有会话
|
||||
- `pod trunk push [PATH]` 在 PATH 发布 podspec 以使其可供 `master` 规范存储库的所有用户使用
|
||||
- `pod trunk register EMAIL [NAME]` 注册一个新帐户,或创建一个新会话
|
||||
- `pod trunk remove-owner POD OWNER-EMAIL` 将具有指定 OWNER-EMAIL 的用户从给定 POD 的 owner 中移除
|
||||
- `pod trunk deprecate NAME` 弃用 pod
|
||||
- `pod trunk delete NAME VERSION` *警告*:删除其他人所依赖的 Pod 版本通常被认为是不良行为!请考虑改用 <red>`deprecate`</red> 命令
|
||||
|
||||
什么是 Podfile?
|
||||
---
|
||||
|
||||
### 简单配置
|
||||
|
||||
```ruby
|
||||
target 'MyApp' do
|
||||
use_frameworks!
|
||||
pod 'Alamofire', '~> 3.0'
|
||||
end
|
||||
```
|
||||
|
||||
Podfile 可以非常简单,这会将 Alamofire 添加到单个目标
|
||||
|
||||
### 添加测试
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```ruby
|
||||
source 'https://github.com/CocoaPods/Specs.git'
|
||||
source 'https://github.com/Artsy/Specs.git'
|
||||
|
||||
platform :ios, '9.0'
|
||||
inhibit_all_warnings!
|
||||
|
||||
target 'MyApp' do
|
||||
pod 'GoogleAnalytics', '~> 3.1'
|
||||
|
||||
# 拥有自己的 OCMock 副本
|
||||
# 并且可以通过应用访问 GoogleAnalytics
|
||||
# 承载测试目标
|
||||
|
||||
target 'MyAppTests' do
|
||||
inherit! :search_paths
|
||||
pod 'OCMock', '~> 2.0.1'
|
||||
end
|
||||
end
|
||||
|
||||
post_install do |installer|
|
||||
installer.pods_project.targets.each do |target|
|
||||
puts target.name
|
||||
end
|
||||
end
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
链接应用程序及其测试包的更复杂 Podfile 的示例
|
||||
|
||||
### 指定 pod 版本
|
||||
|
||||
在开始一个项目时,希望使用最新版本的 Pod。这种情况,只需忽略版本要求
|
||||
|
||||
```ruby
|
||||
pod 'SSZipArchive'
|
||||
```
|
||||
|
||||
稍后在项目中,您可能希望冻结到特定版本的 Pod,在这种情况下,您可以指定该版本号
|
||||
|
||||
```ruby
|
||||
pod 'Objection', '0.9'
|
||||
```
|
||||
|
||||
### 隐式抽象目标
|
||||
|
||||
Podfile 的根目录存在隐式抽象目标,因此您可以将上面的示例编写为
|
||||
|
||||
```ruby
|
||||
pod 'ShowsKit'
|
||||
pod 'Fabric'
|
||||
|
||||
# 拥有自己的 ShowsKit + ShowWebAuth 副本
|
||||
target 'ShowsiOS' do
|
||||
pod 'ShowWebAuth'
|
||||
end
|
||||
|
||||
# 拥有自己的 ShowsKit + ShowTVAuth 副本
|
||||
target 'ShowsTV' do
|
||||
pod 'ShowTVAuth'
|
||||
end
|
||||
```
|
||||
|
||||
### 多个目标共享同一个 pod
|
||||
|
||||
```ruby
|
||||
# 在任何 Xcode 项目中都没有名为“Shows”的目标
|
||||
abstract_target 'Shows' do
|
||||
pod 'ShowsKit'
|
||||
pod 'Fabric'
|
||||
# 拥有自己的 ShowsKit + ShowWebAuth 副本
|
||||
target 'ShowsiOS' do
|
||||
pod 'ShowWebAuth'
|
||||
end
|
||||
# 拥有自己的 ShowsKit + ShowTVAuth 副本
|
||||
target 'ShowsTV' do
|
||||
pod 'ShowTVAuth'
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
另见
|
||||
----
|
||||
|
||||
- [CocoaPods 官方网站](https://cocoapods.org/) *(cocoapods.org)*
|
||||
- [Cocoapods Cheatsheet](https://github.com/SebastianBoldt/Cocoapods-Cheatsheet) *(github.com)*
|
67
docs/cron.md
67
docs/cron.md
@ -16,8 +16,8 @@ Min Hour Day Mon Weekday
|
||||
|
||||
-------
|
||||
|
||||
```
|
||||
* * * * * 要执行的命令
|
||||
```bash
|
||||
* * * * * <要执行的命令>
|
||||
┬ ┬ ┬ ┬ ┬
|
||||
│ │ │ │ └─ 星期几 (0=周日 .. 6=星期六)
|
||||
│ │ │ └────── 月 (1..12)
|
||||
@ -30,12 +30,13 @@ Min Hour Day Mon Weekday
|
||||
|
||||
| 字段 | 范围 | 特殊字符 |
|
||||
|--------------|--------|--------------------|
|
||||
| 分钟 Minute | 0 - 59 | , - * / |
|
||||
| 小时 Hour | 0 - 23 | , - * / |
|
||||
| 月份中的某天 | 1 - 31 | , - * ? / L W |
|
||||
| 月 Month | 1 - 12 | , - * / |
|
||||
| 星期几 | 0 - 6 | , - * ? / L # |
|
||||
<!--rehype:className=show-header -->
|
||||
| 分钟 Minute | 0 - 59 | <kbd>,</kbd> <kbd>-</kbd> <kbd>*</kbd> <kbd>/</kbd>
|
||||
| 小时 Hour | 0 - 23 | <kbd>,</kbd> <kbd>-</kbd> <kbd>*</kbd> <kbd>/</kbd>
|
||||
| 月份中的某天 | 1 - 31 | <kbd>,</kbd> <kbd>-</kbd> <kbd>*</kbd> <kbd>?</kbd> <kbd>/</kbd> <kbd>L</kbd> <kbd>W</kbd>
|
||||
| 月 Month | 1 - 12 | <kbd>,</kbd> <kbd>-</kbd> <kbd>*</kbd> <kbd>/</kbd>
|
||||
| 星期几 | 0 - 6 | <kbd>,</kbd> <kbd>-</kbd> <kbd>*</kbd> <kbd>?</kbd> <kbd>/</kbd> <kbd>L</kbd> <kbd>#</kbd>
|
||||
| 年 Year | 1970–2099 | <kbd>,</kbd> <kbd>-</kbd>
|
||||
<!--rehype:className=show-header-->
|
||||
|
||||
### 示例
|
||||
|
||||
@ -50,33 +51,38 @@ Min Hour Day Mon Weekday
|
||||
| `0 0 * * 0` | 每个星期日的午夜 |
|
||||
| `15 2 * * 1L` | 每月最后一个星期一凌晨 2 点 15 分 |
|
||||
| `15 0 * * 4#2` | 每个月的第二个星期四早上 00:15 |
|
||||
| `0 0 0 1 * *` | 每个月的 1 日(每月) |
|
||||
| `0 0 0 1 1 *` | 每年 1 月 1 日(每年) |
|
||||
| `0 0 0 1 * *` | 每个月的 1 日(每月) |
|
||||
| `0 0 0 1 1 *` | 每年 1 月 1 日(每年) |
|
||||
| `@reboot` | 每次重启 _(非标准)_ |
|
||||
|
||||
### 特殊字符串
|
||||
|
||||
| 特殊字符串 | 意义 |
|
||||
|----------------|----------------------------------------------------|
|
||||
| @reboot | 运行一次,在系统启动时 _(非标准)_ |
|
||||
| @yearly | 每年运行一次,“0 0 1 1 *” _(非标准)_ |
|
||||
| @annually | (与@yearly 相同)_(非标准)_ |
|
||||
| @monthly | 每月运行一次,“0 0 1 \* \*” _(非标准)_ |
|
||||
| @weekly | 每周运行一次,“0 0 \* \* 0” _(非标准)_ |
|
||||
| @daily | 每天运行一次,“0 0 \* \* \*” _(非标准)_ |
|
||||
| @midnight | (与@daily 相同)_(非标准)_ |
|
||||
| @hourly | 每小时运行一次,“0 \* \* \* \*” _(非标准)_ |
|
||||
| @reboot | 运行一次,在系统启动时 _(非标准)_ |
|
||||
| @yearly | 每年运行一次,“0 0 1 1 *” _(非标准)_ |
|
||||
| @annually | (与@yearly 相同)_(非标准)_ |
|
||||
| @monthly | 每月运行一次,“0 0 1 \* \*” _(非标准)_ |
|
||||
| @weekly | 每周运行一次,“0 0 \* \* 0” _(非标准)_ |
|
||||
| @daily | 每天运行一次,“0 0 \* \* \*” _(非标准)_ |
|
||||
| @midnight | (与@daily 相同)_(非标准)_ |
|
||||
| @hourly | 每小时运行一次,“0 \* \* \* \*” _(非标准)_ |
|
||||
<!--rehype:className=show-header -->
|
||||
|
||||
### Crontab 命令
|
||||
|
||||
| - | - |
|
||||
|--------------|---------------------------------------------|
|
||||
| `crontab -e` | 如果不存在,则编辑或创建一个 crontab 文件。 |
|
||||
| `crontab -l` | 显示 crontab 文件。 |
|
||||
| `crontab -r` | 删除 crontab 文件。 |
|
||||
| `crontab -v` | 显示您上次编辑 crontab 文件的时间。 _(非标准)_ |
|
||||
| `echo "@reboot echo hi" | crontab` | 轻松添加任务 |
|
||||
| `crontab -e` | 如果不存在,则编辑或创建一个 crontab 文件 |
|
||||
| `crontab -l` | 显示 crontab 文件 |
|
||||
| `crontab -r` | 删除 crontab 文件 |
|
||||
| `crontab -v` | 显示您上次编辑 crontab 文件的时间 _(非标准)_ |
|
||||
|
||||
轻松添加任务
|
||||
|
||||
```bash
|
||||
echo "@reboot echo hi" \| crontab
|
||||
```
|
||||
|
||||
### 特殊字符
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
@ -84,16 +90,17 @@ Min Hour Day Mon Weekday
|
||||
| 特殊字符 | 说明 |
|
||||
|---------------------|------------|
|
||||
`星号(*)` | 匹配字段中的所有值或任何可能的值。
|
||||
`横杆(-)` | 用于定义范围。例如:第 5 个字段(星期几)中的 1-5 每个工作日,即星期一到星期五
|
||||
`斜线 (/)` | 第一个字段(分钟)/15 表示每十五分钟或范围的增量。
|
||||
`逗号(,)` | 用于分隔项目。例如:第二个字段(小时)中的 2、6、8 在凌晨 2 点、早上 6 点和早上 8 点执行
|
||||
`横杆(-)` | 用于定义范围。例如:第 5 个字段(星期几)中的 1-5 每个工作日,即星期一到星期五
|
||||
`斜线 (/)` | 第一个字段(分钟)/15 表示每十五分钟或范围的增量。
|
||||
`逗号(,)` | 用于分隔项目。例如:第二个字段(小时)中的 2、6、8 在凌晨 2 点、早上 6 点和早上 8 点执行
|
||||
`L` | 仅允许用于 `月份中的某天` 或 `星期几` 字段,`星期几` 中的 `2L` 表示每个月的最后一个星期二
|
||||
`井号 (#)` | 仅允许用于 `星期几` 字段,后面必须在 1 到 5 的范围内。例如,`4#1` 表示给定月份的“第一个星期四”。
|
||||
`问号(?)` | 可以代替“*”并允许用于月份和星期几。使用仅限于 cron 表达式中的 `月份中的某天` 或 `星期几`。
|
||||
<!--rehype:className=show-header auto-wrap-->
|
||||
|
||||
## Also see
|
||||
另见
|
||||
----
|
||||
|
||||
* [Devhints](https://devhints.io/cron) _(devhints.io)_
|
||||
* [Crontab Generator](https://crontab-generator.org/) _(crontab-generator.org)_
|
||||
* [Crontab guru](https://crontab.guru/) _(crontab.guru)_
|
||||
- [Devhints](https://devhints.io/cron) _(devhints.io)_
|
||||
- [Crontab Generator](https://crontab-generator.org/) _(crontab-generator.org)_
|
||||
- [Crontab guru](https://crontab.guru/) _(crontab.guru)_
|
||||
|
200
docs/cs.md
Normal file
200
docs/cs.md
Normal file
@ -0,0 +1,200 @@
|
||||
C# 备忘清单
|
||||
===
|
||||
|
||||
提供基本语法和方法的 C# 快速参考备忘单
|
||||
|
||||
入门
|
||||
--------
|
||||
|
||||
### Hello.cs
|
||||
|
||||
```cs
|
||||
class Hello {
|
||||
// main method
|
||||
static void Main(string[] args)
|
||||
{
|
||||
// 输出: Hello, world!
|
||||
Console.WriteLine("Hello, world!");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
编译运行(确保在项目目录下)
|
||||
|
||||
```shell
|
||||
$ dotnet run
|
||||
Hello, world!
|
||||
```
|
||||
|
||||
### 变量
|
||||
|
||||
```cs
|
||||
int intNum = 9;
|
||||
long longNum = 9999999;
|
||||
float floatNum = 9.99F;
|
||||
double doubleNum = 99.999;
|
||||
decimal decimalNum = 99.9999M;
|
||||
char letter = 'D';
|
||||
bool @bool = true;
|
||||
string site = "quickref.me";
|
||||
var num = 999;
|
||||
var str = "999";
|
||||
var bo = false;
|
||||
```
|
||||
|
||||
### 原始数据类型
|
||||
|
||||
数据类型 | 尺寸 | 范围
|
||||
:- | - | -
|
||||
| `int` | 4 bytes | -2^31^ ^to^ 2^31^-1 |
|
||||
| `long` | 8 bytes | -2^63^ ^to^ 2^63^-1 |
|
||||
| `float` | 4 bytes | 6 ^to^ 7 decimal digits |
|
||||
| `double` | 8 bytes | 15 decimal digits |
|
||||
| `decimal` | 16 bytes | 28 ^to^ 29 decimal digits |
|
||||
| `char` | 2 bytes | 0 ^to^ 65535 |
|
||||
| `bool` | 1 bit | true / false |
|
||||
| `string` | 2 bytes per char | _N/A_ |
|
||||
<!--rehype:className=show-header-->
|
||||
|
||||
### 注释
|
||||
|
||||
```cs
|
||||
// 单行注释
|
||||
/* 多行
|
||||
注释 */
|
||||
// TODO:向 Visual Studio 中的任务列表添加注释
|
||||
/// 用于文档的单行注释
|
||||
/** 多行 注释
|
||||
用于文档 **/
|
||||
```
|
||||
|
||||
### Strings
|
||||
|
||||
```cs
|
||||
string first = "John";
|
||||
string last = "Doe";
|
||||
// 字符串连接
|
||||
string name = first + " " + last;
|
||||
Console.WriteLine(name); // => John Doe
|
||||
```
|
||||
|
||||
查看: [Strings](#c-字符串)
|
||||
|
||||
### User Input
|
||||
|
||||
```cs
|
||||
Console.WriteLine("Enter number:");
|
||||
if(int.TryParse(Console.ReadLine(),out int input))
|
||||
{
|
||||
// 输入验证
|
||||
Console.WriteLine($"You entered {input}");
|
||||
}
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 条件句
|
||||
|
||||
```cs
|
||||
int j = 10;
|
||||
if (j == 10) {
|
||||
Console.WriteLine("I get printed");
|
||||
} else if (j > 10) {
|
||||
Console.WriteLine("I don't");
|
||||
} else {
|
||||
Console.WriteLine("I also don't");
|
||||
}
|
||||
```
|
||||
|
||||
### 数组
|
||||
|
||||
```cs
|
||||
char[] chars = new char[10];
|
||||
chars[0] = 'a';
|
||||
chars[1] = 'b';
|
||||
string[] letters = {"A", "B", "C"};
|
||||
int[] mylist = {100, 200};
|
||||
bool[] answers = {true, false};
|
||||
```
|
||||
|
||||
### 循环
|
||||
|
||||
```cs
|
||||
int[] numbers = {1, 2, 3, 4, 5};
|
||||
for(int i = 0; i < numbers.Length; i++) {
|
||||
Console.WriteLine(numbers[i]);
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```cs
|
||||
foreach(int num in numbers) {
|
||||
Console.WriteLine(num);
|
||||
}
|
||||
```
|
||||
|
||||
C# 字符串
|
||||
----------------
|
||||
|
||||
### 字符串连接
|
||||
|
||||
```cs
|
||||
string first = "John";
|
||||
string last = "Doe";
|
||||
string name = first + " " + last;
|
||||
Console.WriteLine(name); // => John Doe
|
||||
```
|
||||
|
||||
### 字符串插值
|
||||
|
||||
```cs
|
||||
string first = "John";
|
||||
string last = "Doe";
|
||||
string name = $"{first} {last}";
|
||||
Console.WriteLine(name); // => John Doe
|
||||
```
|
||||
|
||||
### 字符串成员
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
成员 | 说明
|
||||
:- | -
|
||||
`Length` | 返回字符串长度的属性
|
||||
`Compare()` | 比较两个字符串的静态方法
|
||||
`Contains()` | 确定字符串是否包含特定的子字符串
|
||||
`Equals()` | 确定两个字符串是否具有相同的字符数据
|
||||
`Format()` | 通过 {0} 表示法和使用其他原语格式化字符串
|
||||
`Trim()` | 从尾随和前导字符中删除特定字符的所有实例。 默认删除前导和尾随空格
|
||||
`Split()` | 删除提供的字符并从两侧的剩余字符中创建一个数组
|
||||
<!--rehype:className=show-header-->
|
||||
|
||||
### 逐字字符串
|
||||
|
||||
```cs
|
||||
string longString = @"I can type any characters in here !#@$%^&*()__+ '' \n \t except double quotes and I will be taken literally. I even work with multiple lines.";
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 成员示例
|
||||
|
||||
```cs
|
||||
// 使用 System.String 的属性
|
||||
string lengthOfString = "How long?";
|
||||
lengthOfString.Length // => 9
|
||||
// 使用 System.String 的方法
|
||||
lengthOfString.Contains("How"); // => true
|
||||
```
|
||||
|
||||
杂项
|
||||
-----------
|
||||
|
||||
### 一般 .NET 条款
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
条款 | 定义
|
||||
:- | -
|
||||
Runtime | 执行给定的已编译代码单元所需的服务集合
|
||||
Common Language Runtime (CLR) | 主要定位、加载和托管 .NET 对象。<br/>CLR 还处理内存管理、应用程序托管、线程协调、执行安全检查和其他低级细节
|
||||
Managed code | 在 `.NET` 运行时编译和运行的代码。 C#/F#/VB 就是例子
|
||||
Unmanaged code | 直接编译为机器代码且不能由 .NET 运行时直接托管的代码。<br/>不包含空闲内存管理、垃圾收集等。从 C/C++ 创建的 DLL 就是示例
|
||||
<!--rehype:className=show-header-->
|
14
docs/css.md
14
docs/css.md
@ -250,10 +250,10 @@ p:first-child {
|
||||
:- | :-
|
||||
`div.classname` | 具有特定类名的 div
|
||||
`div#idname` | 具有特定 ID 的 div
|
||||
`div p` | div 中的段落
|
||||
`div > p` | div 子节点中的所有 `P` 标签
|
||||
`div + p` | div 之后的 `P` 标签
|
||||
`div ~ p` | div 前面的 `P` 标签
|
||||
`div p` | div 中的所有段落
|
||||
`div > p` | 父元素是 div 的 `P` 标签
|
||||
`div + p` | div 之后的第一个同级 `P` 标签
|
||||
`div ~ p` | div 之后所有的同级 `P` 标签
|
||||
|
||||
另见: [相邻兄弟](https://developer.mozilla.org/zh-CN/docs/Web/CSS/Adjacent_sibling_combinator) / [通用兄弟](https://developer.mozilla.org/zh-CN/docs/Web/CSS/General_sibling_combinator) / [子](https://developer.mozilla.org/zh-CN/docs/Web/CSS/Child_combinator) 选择器
|
||||
|
||||
@ -340,7 +340,7 @@ a:active { color: red; }
|
||||
:- | :-
|
||||
`p:first-child` | 第一个孩子 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:first-child)
|
||||
`p:last-child` | 最后一个孩子 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:last-child)
|
||||
`p:first-of-type` | 首先是某种类型 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:first-of-type)
|
||||
`p:first-of-type` | 第一个 p 类型的元素 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:first-of-type)
|
||||
`p:last-of-type` | 某种类型的最后一个 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:last-of-type)
|
||||
`p:nth-child(2)` | 其父母的第二个孩子 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:nth-child)
|
||||
`p:nth-child(3n42)` | Nth-child(an + b) 公式 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:nth-child)
|
||||
@ -352,8 +352,8 @@ a:active { color: red; }
|
||||
`:is(header, div) p` | 可以选择的元素 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:is)
|
||||
`:where(header, div) p` | 与 `:is` 相同 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:where)
|
||||
`a:has(> img)` | 包含 `img` 元素的 `a` 元素 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:has)
|
||||
`::first-letter` | 第一行的第一个字母 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:first-letter)
|
||||
`::first-line` | 第一行应用样式 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:first-line)
|
||||
`::first-letter` | 第一行的第一个字母 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/::first-letter)
|
||||
`::first-line` | 第一行应用样式 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/::first-line)
|
||||
|
||||
CSS 字体
|
||||
------
|
||||
|
598
docs/dart.md
Normal file
598
docs/dart.md
Normal file
@ -0,0 +1,598 @@
|
||||
Dart 备忘清单
|
||||
===
|
||||
|
||||
包含最重要概念、功能、方法等的 [Dart](https://dart.dev/) 备忘单。初学者的完整快速参考
|
||||
|
||||
入门
|
||||
-----
|
||||
|
||||
### 安装 Dart
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
#### Windows
|
||||
|
||||
```bash
|
||||
C:\> choco install dart-sdk # Windows
|
||||
```
|
||||
|
||||
#### Linux
|
||||
|
||||
执行以下一次性设置
|
||||
|
||||
```bash
|
||||
$ sudo apt-get update
|
||||
$ sudo apt-get install apt-transport-https
|
||||
$ wget -qO- https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmor -o /usr/share/keyrings/dart.gpg
|
||||
$ echo 'deb [signed-by=/usr/share/keyrings/dart.gpg arch=amd64] https://storage.googleapis.com/download.dartlang.org/linux/debian stable main' | sudo tee /etc/apt/sources.list.d/dart_stable.list
|
||||
```
|
||||
|
||||
安装 Dart SDK
|
||||
|
||||
```bash
|
||||
$ sudo apt-get update
|
||||
$ sudo apt-get install dart
|
||||
```
|
||||
|
||||
#### Mac
|
||||
|
||||
```bash
|
||||
$ brew tap dart-lang/dart
|
||||
$ brew install dart
|
||||
```
|
||||
|
||||
### hello.dart
|
||||
|
||||
```dart
|
||||
// 应用执行开始的顶级函数
|
||||
void main() {
|
||||
print("Hello World!"); // 打印到控制台
|
||||
}
|
||||
```
|
||||
|
||||
每个应用程序都有一个 `main()` 函数
|
||||
|
||||
#### Windows
|
||||
|
||||
```bash
|
||||
$ dart compile exe hellow.dart
|
||||
$ time ./hello.exe
|
||||
Hello World!
|
||||
```
|
||||
|
||||
### 变量
|
||||
|
||||
```dart
|
||||
int x = 2; // 显式键入
|
||||
var p = 5; // 类型推断 - 具有类型推断的通用var
|
||||
dynamic z = 8; // 变量可以采用任何类型
|
||||
z = "cool"; // cool
|
||||
|
||||
// 如果您从不打算更改变量,请使用 final 或 const
|
||||
// 像这样的东西:
|
||||
final email = "temid@gmail.com";
|
||||
// 与 var 相同,但不能重新分配
|
||||
final String email = "temid@gmail.com";
|
||||
// 你不能改变价值
|
||||
const qty = 5; // 编译时常数
|
||||
```
|
||||
|
||||
### 数据类型
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```dart
|
||||
// 整数,范围 -2^63 到 2^63 - 1
|
||||
int age = 20;
|
||||
// 浮点数字
|
||||
|
||||
double height = 1.85;
|
||||
// 您还可以将变量声明为 num
|
||||
// x 可以同时具有 int 和 double 值
|
||||
num x = 1;
|
||||
num += 2.5;
|
||||
print(num); // 打印: 3.5
|
||||
|
||||
String name = "Nicola";
|
||||
bool isFavourite = true;
|
||||
bool isLoaded = false;
|
||||
```
|
||||
|
||||
### 注释
|
||||
|
||||
```dart
|
||||
// 这是一条正常的单行注释
|
||||
/// 这是一个文档注释,用于文档库,
|
||||
/// 类及其成员。 IDE 和 dartdoc 等工具
|
||||
/// doc 特别注释。
|
||||
/* 也支持此类注释 */
|
||||
```
|
||||
|
||||
### 字符串插值
|
||||
|
||||
```dart
|
||||
// 可以对字符串类型使用单引号或双引号
|
||||
var firstName = 'Nicola';
|
||||
var lastName = "Tesla";
|
||||
// 可以用 $ 将变量嵌入到字符串中
|
||||
String fullName = "$firstName $lastName";
|
||||
// 与 + 连接
|
||||
var name = "Albert " + "Einstein";
|
||||
String upperCase = '${firstName.toUpperCase()}';
|
||||
print(upperCase); // 打印: NICOLA
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### 导入 Imports
|
||||
|
||||
```dart
|
||||
// 导入核心库
|
||||
import 'dart:math';
|
||||
// 从外部包导入库
|
||||
import 'package:test/test.dart';
|
||||
// 导入文件
|
||||
import 'path/to/my_other_file.dart';
|
||||
```
|
||||
|
||||
操作符
|
||||
-------
|
||||
|
||||
### 算术运算符
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```dart
|
||||
print(2 + 3); // 打印: 5
|
||||
print(2 - 3); // 打印: -1
|
||||
print(2 * 3); // 打印: 6
|
||||
print(5 / 2); // 打印: 2.5 - 结果是 double
|
||||
print(5 ~/ 2); // 打印: 2 - 结果是n int
|
||||
print(5 % 2); // 打印: 1 - 余
|
||||
int a = 1, b;
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
```dart
|
||||
// 增
|
||||
b = ++a; // 前增量 - 在 b 获得其值之前增加 a
|
||||
b = a++; // 后增量 - 在 b 获得它的值之后增加 a
|
||||
// 递
|
||||
b = --a; // 前减量 - 在 b 获得它的值之前减少 a
|
||||
b = a--; // 后减量 - 在 b 获得它的值之后递减 a
|
||||
```
|
||||
|
||||
### 逻辑运算符
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
```dart
|
||||
// !expr 反转表达式(将 false 更改为 true,反之亦然)
|
||||
// || 逻辑或
|
||||
// && 逻辑与
|
||||
bool isOutOfStock = false;
|
||||
int quantity = 3;
|
||||
if (!isOutOfStock && (quantity == 2 || quantity == 3)) {
|
||||
// ...Order the product...
|
||||
}
|
||||
```
|
||||
|
||||
### 等式和关系运算符
|
||||
|
||||
```dart
|
||||
print(2 == 2); // 打印: true - 平等的
|
||||
print(2 != 3); // 打印: true - 不相等
|
||||
print(3 > 2); // 打印: true - 比...更棒
|
||||
print(2 < 3); // 打印: true - 少于
|
||||
print(3 >= 3); // 打印: true - 大于或等于
|
||||
print(2 <= 3); // 打印: true - 小于或等于
|
||||
```
|
||||
|
||||
控制流:条件
|
||||
------
|
||||
|
||||
### if 和 else if
|
||||
|
||||
```dart
|
||||
if(age < 18){
|
||||
print("Teen");
|
||||
} else if( age > 18 && age <60){
|
||||
print("Adult");
|
||||
} else {
|
||||
print("Old");
|
||||
}
|
||||
```
|
||||
|
||||
### switch case
|
||||
|
||||
```dart
|
||||
enum Pet {dog, cat}
|
||||
Pet myPet = Pet.dog;
|
||||
switch(myPet){
|
||||
case Pet.dog:
|
||||
print('My Pet is Dog.');
|
||||
break;
|
||||
case Pet.cat:
|
||||
print('My Pet is Cat.');
|
||||
break;
|
||||
default:
|
||||
print('I don\'t have a Pet');
|
||||
}
|
||||
// 打印: My Pet is Dog.
|
||||
```
|
||||
|
||||
控制流:循环
|
||||
-----
|
||||
|
||||
### while 循环
|
||||
|
||||
```dart
|
||||
while (!dreamsAchieved) {
|
||||
workHard();
|
||||
}
|
||||
```
|
||||
|
||||
循环迭代之前的 `while` 循环检查条件
|
||||
|
||||
### do-while 循环
|
||||
|
||||
```dart
|
||||
do {
|
||||
workHard();
|
||||
} while (!dreamsAchieved);
|
||||
```
|
||||
|
||||
`do-while` 循环在执行循环内的语句后验证条件
|
||||
|
||||
### for 循环
|
||||
|
||||
```dart
|
||||
for(int i=0; i< 10; i++){
|
||||
print(i);
|
||||
}
|
||||
var numbers = [1,2,3];
|
||||
// 列表的 for-in 循环
|
||||
for(var number in numbers){
|
||||
print(number);
|
||||
}
|
||||
```
|
||||
|
||||
Collections
|
||||
------------
|
||||
|
||||
### Lists
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
```dart
|
||||
// 有序的对象组
|
||||
var list = [1, 2, 3];
|
||||
print(list.length); //Print: 3
|
||||
print(list[1]); //Print: 2
|
||||
// 列表声明和初始化的其他方式
|
||||
List<String> cities = <String>["New York", "Mumbai", "Tokyo"];
|
||||
// 创建一个编译时常量的列表
|
||||
const constantCities = const ["New York", "Mumbai", "Tokyo"];
|
||||
```
|
||||
|
||||
### Maps
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```dart
|
||||
// 映射是关联键和值的对象
|
||||
var person = Map<String, String>();
|
||||
// 要初始化地图,请执行以下操作:
|
||||
person['firstName'] = 'Nicola';
|
||||
person['lastName'] = 'Tesla';
|
||||
print(person);
|
||||
// 打印: {firstName:Nicola, lastName:Tesla}
|
||||
print(person['lastName']);
|
||||
// 打印: Tesla
|
||||
|
||||
var nobleGases = {
|
||||
// Key: Value
|
||||
2: 'helium',
|
||||
10: 'neon',
|
||||
18: 'argon',
|
||||
};
|
||||
```
|
||||
|
||||
### Sets
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
```dart
|
||||
// Dart 中的集合是唯一项的无序集合
|
||||
var halogens = {'fluorine', 'chlorine', 'bromine', 'iodine', 'astatine'};
|
||||
// 创建一个空集
|
||||
var names = <String>{};
|
||||
Set<String> names = {}; // 这也有效
|
||||
//var names = {}; // 创建地图,而不是集合
|
||||
```
|
||||
|
||||
函数
|
||||
------
|
||||
|
||||
### 函数示例
|
||||
|
||||
```dart
|
||||
// dart 中的函数是对象并且有一个类型
|
||||
int add(int a, int b){
|
||||
return a+b;
|
||||
}
|
||||
// 函数可以分配给变量
|
||||
int sum = add(2,3); // 回报:5
|
||||
// 可以作为参数传递给其他函数
|
||||
int totalSum = add(2, add(2,3)); // 返回:7
|
||||
```
|
||||
|
||||
### 箭头语法 (=>)
|
||||
|
||||
```dart
|
||||
// 只包含一个表达式的函数,您可以使用简写语法
|
||||
bool isFav(Product product) => favProductsList.contains(product);
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### Anonymous (lambda) functions
|
||||
|
||||
```dart
|
||||
// 没有名字的小单行函数
|
||||
int add(a,b) => a+b;
|
||||
// lambda 函数大多作为参数传递给其他函数
|
||||
const list = [
|
||||
'apples', 'bananas', 'oranges'
|
||||
];
|
||||
|
||||
list.forEach(
|
||||
(item) =>
|
||||
print('${list.indexOf(item)}: $item')
|
||||
);
|
||||
// 打印: 0: apples 1: bananas 2: oranges
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
类和对象
|
||||
----------
|
||||
|
||||
### 类 Class
|
||||
|
||||
```dart
|
||||
class Cat {
|
||||
String name;
|
||||
// 方法
|
||||
void voice(){
|
||||
print("Meow");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 对象 Object
|
||||
|
||||
```dart
|
||||
// 类的实例
|
||||
// 在 myCat 下面是 Cat 类的对象
|
||||
void main(){
|
||||
Cat myCat = Cat();
|
||||
myCat.name = "Kitty";
|
||||
myCat.voice(); // 打印: Meow
|
||||
}
|
||||
```
|
||||
|
||||
### 构造函数
|
||||
|
||||
```dart
|
||||
class Cat {
|
||||
String name;
|
||||
Cat(this.name);
|
||||
}
|
||||
void main(){
|
||||
Cat myCat = Cat("Kitty");
|
||||
print(myCat.name); // 打印: Kitty
|
||||
}
|
||||
```
|
||||
|
||||
### 抽象类
|
||||
|
||||
```dart
|
||||
// 抽象类——不能实例化的类
|
||||
// 这个类被声明为抽象的,因此不能被实例化
|
||||
abstract class AbstractContainer {
|
||||
// 定义构造函数、字段、方法...
|
||||
void updateChildren(); // 抽象方法
|
||||
}
|
||||
```
|
||||
|
||||
### Getters Setters
|
||||
|
||||
```dart
|
||||
// 提供对对象属性的读写访问
|
||||
class Cat {
|
||||
String name;
|
||||
// getter
|
||||
String get catName {
|
||||
return name;
|
||||
}
|
||||
// setter
|
||||
void set catName(String name){
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
隐式接口
|
||||
------------
|
||||
|
||||
### 一个基本的界面
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
```dart
|
||||
// 一个人。隐式接口包含 greet()。
|
||||
class Person {
|
||||
// 在接口中,但仅在此库中可见。
|
||||
final String _name;
|
||||
// 不在接口中,因为这是一个构造函数。
|
||||
Person(this._name);
|
||||
// 在接口中
|
||||
String greet(String who) => 'Hello, $who. I am $_name.';
|
||||
}
|
||||
// Person 接口的实现。
|
||||
class Impostor implements Person {
|
||||
String get _name => '';
|
||||
String greet(String who) => 'Hi $who. Do you know who I am?';
|
||||
}
|
||||
String greetBob(Person person) => person.greet('Bob');
|
||||
void main() {
|
||||
print(greetBob(Person('Kathy')));
|
||||
// 打印: Hello, Bob. I am Kathy.
|
||||
print(greetBob(Impostor()));
|
||||
// 打印: Hi Bob. Do you know who I am?
|
||||
}
|
||||
```
|
||||
|
||||
### 扩展类
|
||||
|
||||
```dart
|
||||
class Phone {
|
||||
void use(){
|
||||
_call();
|
||||
_sendMessage();
|
||||
}
|
||||
}
|
||||
// 使用 extends 创建子类
|
||||
class SmartPhone extends Phone {
|
||||
void use(){
|
||||
// 使用 super 来引用超类
|
||||
super.use();
|
||||
_takePhotos();
|
||||
_playGames();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
异常
|
||||
-----
|
||||
|
||||
### Throw
|
||||
|
||||
```dart
|
||||
// 抛出 throws 或引发 raises 和异常 exception
|
||||
throw IntegerDivisionByZeroException();
|
||||
// 你也可以抛出任意对象
|
||||
throw "Product out of stock!";
|
||||
```
|
||||
|
||||
### Catch
|
||||
|
||||
```dart
|
||||
try {
|
||||
int c = 3/0;
|
||||
print(c);
|
||||
} on IntegerDivisionByZeroException {
|
||||
// 一个特定的异常
|
||||
print('Can not divide integer by 0.')
|
||||
} on Exception catch (e) {
|
||||
// 任何其他异常情况
|
||||
print('Unknown exception: $e');
|
||||
} catch (e) {
|
||||
// 没有指定类型,处理所有
|
||||
print('Something really unknown: $e');
|
||||
}
|
||||
```
|
||||
|
||||
### Finally
|
||||
|
||||
```dart
|
||||
// 确保某些代码无论是否抛出异常都能运行
|
||||
try {
|
||||
cookFood();
|
||||
} catch (e) {
|
||||
print('Error: $e'); // 先处理异常
|
||||
} finally {
|
||||
cleanKitchen(); // 然后清理
|
||||
}
|
||||
```
|
||||
|
||||
Futures
|
||||
------------
|
||||
|
||||
### Async Await
|
||||
|
||||
```dart
|
||||
// 异步函数:它们在设置可能耗时的操作后返回
|
||||
// async 和 await 关键字支持异步编程
|
||||
Future<String> login() {
|
||||
String userName="Temidjoy";
|
||||
return
|
||||
Future.delayed(
|
||||
Duration(seconds: 4), () => userName
|
||||
);
|
||||
}
|
||||
// 异步
|
||||
main() async {
|
||||
print('Authenticating please wait...');
|
||||
print(await userName());
|
||||
}
|
||||
```
|
||||
|
||||
各种各样的
|
||||
------------
|
||||
|
||||
### Null 和 Null 感知
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
```dart
|
||||
int x; // 任何对象的初始值为 null
|
||||
// ?? 空感知运算符
|
||||
x ??=6; // ??= 赋值运算符,仅当变量当前为 null 时才为其赋值
|
||||
print(x); // 打印: 6
|
||||
x ??=3;
|
||||
print(x); // 打印: 6 - 结果仍然是 6
|
||||
print(null ?? 10); // 打印: 10。如果不为空,则显示左侧的值,否则返回右侧的值
|
||||
```
|
||||
|
||||
### 三元运算符
|
||||
|
||||
```dart
|
||||
// 条件 ? 条件如果为真 : 条件如果为假
|
||||
bool isAvailable;
|
||||
isAvailable ? orderproduct() : addToFavourite();
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 条件属性访问
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
```dart
|
||||
userObject?.userName
|
||||
// 上面的代码片段等效于以下代码:
|
||||
(userObject != null) ? userObject.userName : null
|
||||
// 您可以将 ? 的多种用途链接起来。一起在一个表达式中
|
||||
userObject?.userName?.toString()
|
||||
// 如果 userObject 或 userObject.userName 为 null,则前面的代码返回 null 并且从不调用 toString()
|
||||
```
|
||||
|
||||
### 级联符号 (..)
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```dart
|
||||
// 允许您对同一对象进行一系列操作
|
||||
// 而不是这样做
|
||||
var user = User();
|
||||
user.name = "Nicola";
|
||||
user.email = "nicola@g.c";
|
||||
user.age = 24;
|
||||
// 你可以这样做
|
||||
var user = User()
|
||||
..name = "Nicola"
|
||||
..email = "nicola@g.c"
|
||||
..age = 24;
|
||||
```
|
||||
|
||||
### 扩展运算符 (...)
|
||||
|
||||
```dart
|
||||
// 将多个值插入到集合中
|
||||
var list = [1, 2, 3];
|
||||
var list2 = [0, ...list];
|
||||
print(list2.length); // 打印: 4
|
||||
```
|
||||
|
||||
另见
|
||||
----
|
||||
|
||||
- [Dart 官方文档](https://dart.dev/) _(dart.dev)_
|
59
docs/es6.md
59
docs/es6.md
@ -149,6 +149,41 @@ class Circle extends Shape {
|
||||
原型的语法糖。
|
||||
请参阅: [类](https://babeljs.io/learn-es2015/#classes)
|
||||
|
||||
### 私有类
|
||||
|
||||
javascript 默认字段是公共的(`public`),如果需要注明私有,可以使用(`#`)
|
||||
|
||||
```js
|
||||
class Dog {
|
||||
#name;
|
||||
constructor(name) {
|
||||
this.#name = name;
|
||||
}
|
||||
printName() {
|
||||
//只能在类内部调用私有字段
|
||||
console.log(`你的名字是${this.#name}`)
|
||||
}
|
||||
}
|
||||
|
||||
const dog = new Dog("putty")
|
||||
//console.log(this.#name)
|
||||
//Private identifiers are not allowed outside class bodies.
|
||||
dog.printName()
|
||||
```
|
||||
|
||||
#### 静态私有类
|
||||
|
||||
```js
|
||||
class ClassWithPrivate {
|
||||
static #privateStaticField;
|
||||
static #privateStaticFieldWithInitializer = 42;
|
||||
|
||||
static #privateStaticMethod() {
|
||||
// …
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Promises
|
||||
--------
|
||||
|
||||
@ -455,6 +490,13 @@ function foo() {}
|
||||
foo.name // "foo"
|
||||
```
|
||||
|
||||
### length 属性
|
||||
|
||||
```js
|
||||
function foo(a, b){}
|
||||
foo.length // 2
|
||||
```
|
||||
|
||||
Objects
|
||||
-------
|
||||
|
||||
@ -664,6 +706,23 @@ new URL('data.txt', import.meta.url)
|
||||
|
||||
Node.js 环境中,`import.meta.url`返回的总是本地路径,即 `file:URL` 协议的字符串,比如 `file:///home/user/foo.js`
|
||||
|
||||
### 导入断言(Import Assertions)
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
#### 静态导入
|
||||
|
||||
```js
|
||||
import json from "./package.json" assert {type: "json"}
|
||||
// 导入 json 文件中的所有对象
|
||||
```
|
||||
|
||||
#### 动态导入
|
||||
|
||||
```js
|
||||
const json =
|
||||
await import("./package.json", { assert: { type: "json" } })
|
||||
```
|
||||
|
||||
Generators
|
||||
----------
|
||||
|
||||
|
224
docs/ffmpeg.md
224
docs/ffmpeg.md
@ -121,33 +121,17 @@ $ ffmpeg -i movie.webm movie.mp4
|
||||
---
|
||||
<!--rehype:body-class=cols-2-->
|
||||
|
||||
### 裁剪
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
### 剪切视频部分
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
```bash
|
||||
$ ffmpeg -i <input> -filter:v "crop=640:480:100:25" <output>
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
通过从输入视频中复制偏移 `x=100px` `y=25px` 的相应窗口来创建 `640x480` 大小的输出视频
|
||||
|
||||
```bash
|
||||
# 裁剪到宽度 360,高度 640
|
||||
$ ffmpeg -i input.mov -filter:v 'crop=360:640:0:0' -codec:a copy output.mov
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
裁剪到宽度 360,高度 640,从坐标 (10, 20) 开始
|
||||
|
||||
```bash
|
||||
$ ffmpeg -i input.mov -filter:v 'crop=360:640:10:20' -codec:a copy output.mov
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### 缩放
|
||||
|
||||
```bash
|
||||
$ ffmpeg -i <输入> -vf scale=640:480 <输出>
|
||||
# 从1分45秒开始剪切2分35秒
|
||||
$ ffmpeg -i <input> -ss 00:01:45 -t 00:02:35 -vcodec copy -acodec copy <output>
|
||||
# 从1分45秒开始剪切到第4分20秒,与上一行等效
|
||||
$ ffmpeg -i <input> -ss 00:01:45 -to 00:04:20 -codec copy <output>
|
||||
$ ffmpeg -ss 00:00:30 -i orginalfile.mpg -t 00:00:05 -vcodec copy -acodec copy newfile.mpg
|
||||
# 从 4.5 秒开始的 5 秒长的视频
|
||||
$ ffmpeg -i in.mp4 -ss 4.5 -t 5 out.mp4
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
@ -165,20 +149,6 @@ $ ffmpeg -r 1 -i input.m2v -r 24 output.avi
|
||||
|
||||
将输入文件的帧速率(仅对原始格式有效)强制为 1 fps,将输出文件的帧速率强制为 24 fps
|
||||
|
||||
### 剪切视频部分
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
```bash
|
||||
# 从1分45秒开始剪切2分35秒
|
||||
$ ffmpeg -i <input> -ss 00:01:45 -t 00:02:35 -vcodec copy -acodec copy <output>
|
||||
# 从1分45秒开始剪切到第4分20秒,与上一行等效
|
||||
$ ffmpeg -i <input> -ss 00:01:45 -to 00:04:20 -codec copy <output>
|
||||
$ ffmpeg -ss 00:00:30 -i orginalfile.mpg -t 00:00:05 -vcodec copy -acodec copy newfile.mpg
|
||||
# 从 4.5 秒开始的 5 秒长的视频
|
||||
$ ffmpeg -i in.mp4 -ss 4.5 -t 5 out.mp4
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### H265 2-pass 编码
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
@ -212,14 +182,6 @@ $ ffmpeg -i <input> -c copy -metadata:s:v:0 rotate=90 <output>
|
||||
|
||||
不要为旋转重新编码,而是简单地为旋转角度添加一个视频元数据字段
|
||||
|
||||
### 放慢视频速度
|
||||
|
||||
```bash
|
||||
$ ffmpeg -i in.mp4 -filter:v "setpts=4.0*PTS" out.mp4
|
||||
```
|
||||
|
||||
使用过滤器减慢视频。 此示例将视频减慢四倍
|
||||
|
||||
### 缩放到特定宽度
|
||||
|
||||
```bash
|
||||
@ -240,23 +202,6 @@ $ ffmpeg -i file.mp4 -vn -c copy output.aac
|
||||
|
||||
`-vn` (过滤视频),使用 `-c copy`,不会重新解码和编码,加快速度。
|
||||
|
||||
### 创建缩略图
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
在 10 秒时创建一个缩略图
|
||||
|
||||
```bash
|
||||
$ ffmpeg -ss 10 -i <input file> -vframes 1 -vcodec png -an thumb.png
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
例如,要每 `n` 秒创建一次缩略图,请使用 `-vf fps=1/n`
|
||||
|
||||
```bash
|
||||
$ ffmpeg -i <input file> -vf fps=1/60 thumbnails/thumb%03d.png
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### 提取视频流
|
||||
|
||||
```bash
|
||||
@ -289,6 +234,13 @@ $ ffmpeg -i file.aac -acodec mp3 -ar 44100 -ab 128000 output.mp3
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### 将输入文件转码为 DVD PAL 格式
|
||||
|
||||
```bash
|
||||
$ ffmpeg -y -threads 8 -i inFile -target pal-dvd -ac 2 -aspect 16:9 -acodec mp2 -ab 224000 -vf pad=0:0:0:0 outFile
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### -map 命令
|
||||
<!--rehype:wrap-class=col-span-2 row-span-2-->
|
||||
|
||||
@ -399,10 +351,19 @@ $ ffmpeg -hide_banner -loglevel error -stats -f gdigrab -framerate 60 \
|
||||
$ ffmpeg -f avfoundation -i 1:0 -preset ultrafast out.mkv
|
||||
```
|
||||
|
||||
### 将输入文件转码为 DVD PAL 格式
|
||||
### 合并音频与图片
|
||||
|
||||
合并多个音频,自定义背景图片,生成视频音乐
|
||||
|
||||
```bash
|
||||
$ ffmpeg -y -threads 8 -i inFile -target pal-dvd -ac 2 -aspect 16:9 -acodec mp2 -ab 224000 -vf pad=0:0:0:0 outFile
|
||||
# mylist.txt >>>
|
||||
file '1.mp3'
|
||||
file '2.mp3'
|
||||
file '3.mp3'
|
||||
|
||||
# OBS: 46500 = 25:50 minutes * 60 * 30fps
|
||||
# echo "00:25:50" | awk -F: '{ print (($1 * 3600) + ($2 * 60) + $3) * 30 }'
|
||||
$ ffmpeg -y -loop 1 -i cover.jpg -f concat -i mylist.txt -c:v libx264 -r 30 -pix_fmt yuv420p -vframes 46500 -c:a aac -b:a 192k -strict experimental -shortest output.mp4
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
@ -569,7 +530,7 @@ $ ffmpeg -i audioS.mp4 -i videoS.mp4 -c copy -map 0:a -map 1:v outFile.mp4
|
||||
|
||||
### 合并视频
|
||||
|
||||
<!--rehype:wrap-class=col-span-2 row-span-3-->
|
||||
<!--rehype:wrap-class=col-span-3 row-span-3-->
|
||||
|
||||
合并相同规格(解码/分辨率/帧率)视频
|
||||
|
||||
@ -618,29 +579,44 @@ $ ffmpeg -f concat -i mylist.txt -c:v copy -c:a flac -strict -2 output.mp4
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### 合并音频与图片
|
||||
视频过滤器
|
||||
---
|
||||
|
||||
合并多个音频,自定义背景图片,生成视频音乐
|
||||
### 格式
|
||||
|
||||
如果一个 fliter 有多个参数,需要使用 `,` 分隔
|
||||
|
||||
```bash
|
||||
# mylist.txt >>>
|
||||
file '1.mp3'
|
||||
file '2.mp3'
|
||||
file '3.mp3'
|
||||
$ ffmpeg -i test.avi -c:v libx264 -vf "scale=1024:-1,transpose=1,crop=iw/3:ih/3" output.mp4
|
||||
```
|
||||
|
||||
# OBS: 46500 = 25:50 minutes * 60 * 30fps
|
||||
# echo "00:25:50" | awk -F: '{ print (($1 * 3600) + ($2 * 60) + $3) * 30 }'
|
||||
$ ffmpeg -y -loop 1 -i cover.jpg -f concat -i mylist.txt -c:v libx264 -r 30 -pix_fmt yuv420p -vframes 46500 -c:a aac -b:a 192k -strict experimental -shortest output.mp4
|
||||
### 缩放
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```bash
|
||||
$ ffmpeg -i input.mp4 -vf "scale=640:480" out.mp4
|
||||
# -1 → 指根据另一个参数帮我们推断
|
||||
$ ffmpeg -i input.mp4 -vf "scale=720:-1" out.mp4
|
||||
# 宽度和高度
|
||||
ffmpeg -i input.mp4 -vf "scale=w=800:h=600" output.mp4
|
||||
# in_w\in_h 输入尺寸
|
||||
ffmpeg -i input.mkv -vf "scale=w=1/2*in_w:h=1/2*in_h" output.mkv
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### 添加水印
|
||||
### 裁剪
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
在视频左上方 20,20 的位置插入 logo.png 图片
|
||||
从左上角开始,复制 `x=0px` `y=0px` 的相应窗口来创建 `1280x720` 大小的输出视频
|
||||
|
||||
```bash
|
||||
# -b:v 548k 可选参数,设置视频比特率,默认 200k 最好设置与原视频一致
|
||||
ffmpeg -i 1.mp4 -acodec copy -b:v 548k -vf "movie=logo.png[watermark];[in][watermark]overlay=20:20" output.mp4
|
||||
ffmpeg -i input.mp4 -vf "crop=w=1280:h=720:x=0:y=0" output.mp4
|
||||
```
|
||||
|
||||
裁剪到宽度 360,高度 640,从坐标 (10, 20) 开始
|
||||
|
||||
```bash
|
||||
$ ffmpeg -i input.mov -vf 'crop=360:640:10:20' output.mov
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
@ -654,6 +630,94 @@ ffmpeg -i 1.mp4 -b:v 548k -vf delogo=x=10:y=10:w=120:h=45:show=1 output.mp4
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### 创建缩略图
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
在 10 秒时创建一个缩略图
|
||||
|
||||
```bash
|
||||
$ ffmpeg -ss 10 -i <input file> -vframes 1 -vcodec png -an thumb.png
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
例如,要每 `n` 秒创建一次缩略图,请使用 `-vf fps=1/n`
|
||||
|
||||
```bash
|
||||
$ ffmpeg -i <input file> -vf fps=1/60 thumbnails/thumb%03d.png
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### 添加水印
|
||||
|
||||
在视频左上方 20,20 的位置插入 logo.png 图片
|
||||
|
||||
```bash
|
||||
# -b:v 548k 可选参数,设置视频比特率,默认 200k 最好设置与原视频一致
|
||||
ffmpeg -i 1.mp4 -acodec copy -b:v 548k -vf "movie=logo.png[watermark];[in][watermark]overlay=20:20" output.mp4
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### 视频旋转
|
||||
|
||||
```bash
|
||||
# 顺时针旋转 90
|
||||
$ ffmpeg -i input.avi -vf "rotate=90*PI/180" out.mp4
|
||||
# 顺时针旋转 180,翻转 90
|
||||
$ ffmpeg -i input.mp4 -vf "rotate=PI" out.mp4
|
||||
```
|
||||
|
||||
### 更改视频播放速度
|
||||
|
||||
```bash
|
||||
# 加速 2 倍
|
||||
$ ffmpeg -i input.mkv -vf "setpts=0.5*PTS" output.mkv
|
||||
# 减速 2 倍
|
||||
$ ffmpeg -i input.mp4 -vf "setpts=2*PTS" output.mp4
|
||||
```
|
||||
|
||||
### 添加背景音乐
|
||||
|
||||
```bash
|
||||
# -t 10 文件时长,单位为秒,建议取值原始视频总时长
|
||||
$ ffmpeg -i 1.mp4 -i test.mp3 \
|
||||
-filter_complex "[1:a]aloop=loop=-1:size=2e+09[out];[out][0:a]amix" \
|
||||
-t 10 out.mp4
|
||||
```
|
||||
|
||||
音频过滤器
|
||||
---
|
||||
|
||||
### 调节音量
|
||||
|
||||
```bash
|
||||
# 增大音量
|
||||
$ ffmpeg -i test.mp4 -af "volumn=1.5" out.mp4
|
||||
```
|
||||
|
||||
### 更改音频速度
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```bash
|
||||
$ ffmpeg -i input.wav -af "atempo=0.75" output.wav
|
||||
# 加速 4 倍
|
||||
$ ffmpeg -i input.mp3 -af "atempo=2.0,atempo=2.0" ouutput.mp3
|
||||
```
|
||||
|
||||
`atempo` 它只接受 `0.5`(半速) 到 `2` (倍速)之间的值。为了越过这个限制,你可以链式使用这个过滤器
|
||||
|
||||
### 统一视频的音量
|
||||
|
||||
```bash
|
||||
$ ffmpeg -i test.mp4 -af "loudnorm=I=-5:LRA=1" out.mp4
|
||||
```
|
||||
|
||||
### 重新映射通道数
|
||||
|
||||
```bash
|
||||
# 使左右耳的声音同时出现
|
||||
$ ffmpeg -i input.mp3 -af "channelmap=1-0|1-1" output.mp3
|
||||
```
|
||||
|
||||
另见
|
||||
---
|
||||
|
||||
|
@ -23,7 +23,7 @@ $ go run hello.go
|
||||
Hello, world!
|
||||
```
|
||||
|
||||
或者在 [Go repl](https://repl.it/languages/go) 中尝试一下
|
||||
或者在 [Go repl](https://repl.it/languages/go) 中尝试一,`go` 命令[参考](#go-命令)
|
||||
|
||||
### 变量
|
||||
|
||||
@ -955,6 +955,54 @@ func main() {
|
||||
| `%` | `>>` | `%=` | `>>=` | `--` | `!` | `...` | `.` | `:` |
|
||||
| | `&^` | `&^=` | | | | | | |
|
||||
|
||||
Go 命令
|
||||
---
|
||||
|
||||
### Go 编译器命令
|
||||
|
||||
:- | --
|
||||
:- | --
|
||||
`go command [参数]` | go 命令 [参数]
|
||||
`go build` | 编译包和依赖包
|
||||
`go clean` | 移除对象和缓存文件
|
||||
`go doc` | 显示包的文档
|
||||
`go env` | 打印go的环境变量信息
|
||||
`go bug` | 报告bug
|
||||
`go fix` | 更新包使用新的api
|
||||
`go fmt` | 格式规范化代码
|
||||
`go generate` | 通过处理资源生成go文件
|
||||
`go get` | 下载并安装包及其依赖
|
||||
`go install` | 编译和安装包及其依赖
|
||||
`go list` | 列出所有包
|
||||
`go run` | 编译和运行go程序
|
||||
`go test` | 测试
|
||||
`go tool` | 运行给定的go工具
|
||||
`go version` | 显示go当前版本
|
||||
`go vet` | 发现代码中可能的错误
|
||||
|
||||
### ENV
|
||||
|
||||
:- | --
|
||||
:- | --
|
||||
`GOOS` | 编译系统
|
||||
`GOARCH` | 编译arch
|
||||
`GO111MODULE` | gomod开关
|
||||
`GOPROXY` | go代理 <https://goproxy.io> <https://goproxy.cn>
|
||||
`GOSSAFUNC` | 生成 `SSA.html` 文件,展示代码优化的每一步 `GOSSAFUNC=func_name go build`
|
||||
<!--rehype:className=style-list-arrow-->
|
||||
|
||||
### Module
|
||||
|
||||
:- | --
|
||||
:- | --
|
||||
`go mod init` | 初始化当前文件夹,创建go.mod文件
|
||||
`go mod download` | 下载依赖的module到本地
|
||||
`go mod tidy` | 增加缺少的module,删除无用的module
|
||||
`go mod vendor` | 将依赖复制到vendor下
|
||||
文件 `go.mod` | 依赖列表和版本约束
|
||||
文件 `go.sum` | 记录 `module` 文件 `hash` 值,用于安全校验
|
||||
<!--rehype:className=style-list-arrow-->
|
||||
|
||||
另见
|
||||
--------
|
||||
|
||||
|
14
docs/java.md
14
docs/java.md
@ -783,6 +783,20 @@ try {
|
||||
}
|
||||
```
|
||||
|
||||
### util工具类
|
||||
|
||||
- `ArrayDeque` 提供 resizable-array 并实现 Deque 接
|
||||
- `Arrays` 包含一个静态工厂,允许将数组视为列表
|
||||
- `Collections` 包含对集合进行操作或返回集合的静态方法
|
||||
- `Date` 表示特定的时间瞬间,精度为毫秒
|
||||
- `Dictionary` 是任何类的抽象父类,例如 Hashtable,它将键映射到值
|
||||
- `EnumMap` 一个专门用于枚举键的 Map 实现
|
||||
- `EnumSet` 一个专门用于枚举键的 Set 实现
|
||||
- `Formatter` 提供对布局对齐和对齐、数字、字符串和日期/时间数据的常用格式以及特定于语言环境的输出的支持
|
||||
- `Random` 实例用于生成伪随机数流
|
||||
- `UUID` 表示一个不可变的通用唯一标识符
|
||||
- `Vector` 实现了一个可增长的对象数组
|
||||
|
||||
另见
|
||||
---
|
||||
|
||||
|
@ -219,9 +219,9 @@ String(23);
|
||||
(23).toString();
|
||||
// 从字符串返回数字
|
||||
Number("23");
|
||||
// 解码 URI。 结果:“我的 page.asp”
|
||||
// 解码 URI。 结果:“my page.asp”
|
||||
decodeURI(enc);
|
||||
// 编码 URI。 结果:“my%page.asp”
|
||||
// 编码 URI。 结果:“my%20page.asp”
|
||||
encodeURI(uri);
|
||||
// 解码 URI 组件
|
||||
decodeURIComponent(enc);
|
||||
|
681
docs/julia.md
Normal file
681
docs/julia.md
Normal file
@ -0,0 +1,681 @@
|
||||
Julia 备忘清单
|
||||
===
|
||||
|
||||
本备忘清单旨在快速理解 [Julia](https://mysql.com) 一份简单而粗略的语言概览,供您参考。
|
||||
|
||||
入门
|
||||
---
|
||||
|
||||
### Julia 是什么?
|
||||
<!--rehype:wrap-class=row-span-3-->
|
||||
|
||||
- **`Julia`** 是一种为科学计算而生的,开源、多平台、高性能的高级编程语言
|
||||
- **`Julia`** 有一个基于 LLVM 的 JIT 编译器,这让使用者无需编写底层的代码也能拥有像 C 与 FORTRAN 那样的性能。因为代码在运行中编译,你可以在 shell 或 REPL 中运行代码,这也是一种推荐的工作流程
|
||||
- **`Julia`** 是动态类型的。并且提供了为并行计算和分布式运算设计的多重派发机制
|
||||
- **`Julia`** 自带包管理器
|
||||
- **`Julia`** 有许多内置的数学函数,包括特殊函数 (例如:Gamma 函数)。并且支持开箱即用的复数运算
|
||||
- **`Julia`** 允许你通过类似 Lisp 的宏来自动生成代码
|
||||
- **`Julia`** 诞生于 2012 年
|
||||
|
||||
### 赋值语句
|
||||
|
||||
```julia
|
||||
answer = 42
|
||||
x, y, z = 1, [1:10; ], "A string"
|
||||
x, y = y, x # 交换 x, y
|
||||
```
|
||||
|
||||
### 常量定义
|
||||
|
||||
```julia
|
||||
const DATE_OF_BIRTH = 2012
|
||||
```
|
||||
|
||||
### 行尾注释
|
||||
|
||||
```julia
|
||||
i = 1 # 这是一行注释
|
||||
# 多行注释
|
||||
#= 这是另一行注释 =#
|
||||
```
|
||||
|
||||
### 链式操作
|
||||
|
||||
```julia
|
||||
x = y = z = 1 # 从右向左
|
||||
0 < x < 3 # true
|
||||
5 < x != y < 5 # false
|
||||
```
|
||||
|
||||
### 函数定义
|
||||
|
||||
```julia
|
||||
function add_one(i)
|
||||
return i + 1
|
||||
end
|
||||
```
|
||||
|
||||
### 插入 LaTeX 符号
|
||||
|
||||
```julia
|
||||
\delta + [Tab] # δ
|
||||
```
|
||||
|
||||
### 运算符
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
基本算数运算 | `+`,`-`,`*`,`/`
|
||||
幂运算 | `2^3` => 8
|
||||
除法 | `3/12` => 0.25
|
||||
反向除法 | `7\3 == 3/7` => true
|
||||
取余 | `x % y` 或 `rem(x,y)`
|
||||
取反 | `!true` => false
|
||||
等于 | `a == b`
|
||||
不等于 | `a != b` 或 `a ≠ b`
|
||||
小于与大于 | `<` 与 `>`
|
||||
小于等于 | `<=` 或 `≤`
|
||||
大于等于 | `>=` 或 `≥`
|
||||
逐元素运算(点运算) | `[1, 2, 3] .+ [1, 2, 3] == [2, 4, 6]` => true<br /> `[1, 2, 3] .* [1, 2, 3] == [1, 4, 9]` => true
|
||||
检测非数值(NaN) | `isnan(NaN)` => true <br />而不是 `NaN == NaN` => false
|
||||
三元运算符 | `a == b ? "Equal" : "Not equal"`
|
||||
短路 AND 和 OR 表达式 | `a && b` 和 `a \|\| b`
|
||||
对象等价 | `a === b`
|
||||
|
||||
### shell/REPL 环境
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
上一次运算的结果 | `ans`
|
||||
中断命令执行 | <kbd>Ctrl</kbd> + <kbd>C</kbd>
|
||||
清屏 | <kbd>Ctrl</kbd> + <kbd>L</kbd>
|
||||
运行程序文件 | `include("filename.jl")`
|
||||
查找 func 相关的帮助 | `?func`
|
||||
查找 func 的所有定义 | `apropos("func")`
|
||||
命令行模式 | `;`
|
||||
包管理模式 | `]`
|
||||
帮助模式 | `?`
|
||||
查找特殊符号输入方式 | `?☆ # "☆" can be typed by \bigwhitestar<tab>`
|
||||
退出特殊模式,返回到 REPL | 在空行上按 <kbd>Backspace</kbd>
|
||||
退出 REPL | `exit()` 或 <kbd>Ctrl</kbd> + <kbd>D</kbd>
|
||||
|
||||
### 缺失值与空值
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
空值(Null) | `nothing`
|
||||
缺失数据 | `missing`
|
||||
浮点数的非数值 | `NaN`
|
||||
滤除缺失值 | `collect(skipmissing([1, 2, missing])) == [1,2]`
|
||||
替换缺失值 | `collect((df[:col], 1))`
|
||||
检查是否有缺失值 | `ismissing(x)` 而不是 `x == missing`
|
||||
|
||||
### 自我检查与反射
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
类型 | `typeof(name)`
|
||||
类型检查 | `isa(name, TypeName)`
|
||||
列出子类型 | `subtypes(TypeName)`
|
||||
列出超类型 | `supertype(TypeName)`
|
||||
函数方法 | `methods(func)`
|
||||
即时编译的字节码 | `code_llvm(expr)`
|
||||
汇编代码 | `code_native(expr)`
|
||||
|
||||
### 随机数
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
设置随机数种子 | `Random.seed!(seed)`
|
||||
产生随机数 | `rand()` # 均匀分布 [0,1)<br/>`randn()` # 正态分布 (-Inf, Inf)
|
||||
产生特定分布的随机数 | `using Distributions`<br/>`my_dist = Bernoulli(0.2)` 举例<br/>`rand(my_dist)`
|
||||
以概率 p 从 A 中进行伯努利抽样 | `randsubseq(A, p)`
|
||||
随机重排 A 中的元素 | `shuffle(A)`
|
||||
|
||||
许多随机数函数都需要 `using Random`
|
||||
|
||||
### 异常处理
|
||||
<!--rehype:wrap-class=row-span-3-->
|
||||
|
||||
```julia
|
||||
# 抛出异常 SomeExcep
|
||||
throw(SomeExcep())
|
||||
# 再次引发当前的异常
|
||||
rethrow()
|
||||
```
|
||||
|
||||
定义新异常 NewExcep
|
||||
|
||||
```julia
|
||||
struct NewExcep <: Exception
|
||||
v::String
|
||||
end
|
||||
Base.showerror(io::IO, e::NewExcep) = print(io, "A problem with $(e.v)!")
|
||||
|
||||
throw(NewExcep("x"))
|
||||
# 抛出带文本的异常
|
||||
error(msg)
|
||||
```
|
||||
|
||||
异常处理流程
|
||||
|
||||
```julia
|
||||
try
|
||||
# 进行一些可能会失败的操作
|
||||
catch ex
|
||||
if isa(ex, SomeExcep)
|
||||
# 处理异常 SomeExcep
|
||||
elseif isa(ex, AnotherExcep)
|
||||
# 处理另一个异常 AnotherExcep
|
||||
else
|
||||
# 处理其余的异常
|
||||
end
|
||||
finally
|
||||
# 永远执行这些语句
|
||||
end
|
||||
```
|
||||
|
||||
### 类型
|
||||
<!--rehype:wrap-class=row-span-4-->
|
||||
|
||||
```julia
|
||||
# 类型注释
|
||||
var::TypeName
|
||||
# 类型声明
|
||||
struct Programmer
|
||||
name::String
|
||||
birth_year::UInt16
|
||||
fave_language::AbstractString
|
||||
end
|
||||
# 可变类型声明
|
||||
将 struct 替换为 mutable struct
|
||||
# 类型别名
|
||||
const Nerd = Programmer
|
||||
# 类型构造器
|
||||
methods(TypeName)
|
||||
# 类型实例
|
||||
me = Programmer("Ian", 1984, "Julia")
|
||||
me = Nerd("Ian", 1984, "Julia")
|
||||
# 子类型声明
|
||||
abstract type Bird end
|
||||
struct Duck <: Bird
|
||||
pond::String
|
||||
end
|
||||
# 参数化类型
|
||||
struct Point{T <: Real}
|
||||
x::T
|
||||
y::T
|
||||
end
|
||||
|
||||
p = Point{Float64}(1,2)
|
||||
# 联合类型
|
||||
Union{Int, String}
|
||||
# 遍历类型层级
|
||||
supertype(TypeName) 和 subtypes(TypeName)
|
||||
# 默认的超类型
|
||||
Any
|
||||
# 所有字段
|
||||
fieldnames(TypeName)
|
||||
# 所有字段类型
|
||||
TypeName.types
|
||||
```
|
||||
|
||||
### 标准库
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
Random | `rand`, `randn`, `randsubseq`
|
||||
Statistics | `mean`, `std`, `cor`, `median`, `quantile`
|
||||
LinearAlgebra | `I`, `eigvals`, `eigvecs`, `det`, `cholesky`
|
||||
SparseArrays | `sparse`, `SparseVector`, `SparseMatrixCSC`
|
||||
Distributed | `@distributed`, `pmap`, `addprocs`
|
||||
Dates | `DateTime`, `Date`
|
||||
|
||||
### 表达式
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
使用引用 `:( ... )` 或块引用 `quote ... end` 可以创建一个表达式,就像 `parse(str)`,和 `Expr(:call, ...)`。
|
||||
|
||||
```julia
|
||||
x = 1
|
||||
line = "1 + $x" # 一些代码
|
||||
expr = Meta.parse(line) # 生成一个 Expr 对象
|
||||
typeof(expr) == Expr # true
|
||||
dump(expr) # 打印生成抽象语法(AST)
|
||||
eval(expr) == 2 # 对 Expr 对象求值: true
|
||||
```
|
||||
|
||||
Julia 具有同像性:程序被表示为语言本身的数据结构。 实际上 `Julia` 语言里的任何东西都是一个表达式 `Expr`。符号(`Symbols`)即驻留字符串 ,以冒号 `:` 为前缀。相对于其他类型来说,符号效率更高。它也经常用作标识符、字典的键或者数据表里的列名。符号不能进行拼接。
|
||||
|
||||
### 输入/输出
|
||||
<!--rehype:wrap-class=row-span-3-->
|
||||
|
||||
读取流
|
||||
|
||||
```julia
|
||||
stream = stdin
|
||||
for line in eachline(stream)
|
||||
# 做点啥
|
||||
end
|
||||
```
|
||||
|
||||
读取文件
|
||||
|
||||
```julia
|
||||
open(filename) do file
|
||||
for line in eachline(file)
|
||||
# 做点啥
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
读取/写入 CSV 文件
|
||||
|
||||
```julia
|
||||
# 读取 CSV 文件
|
||||
using CSV
|
||||
data = CSV.File(filename)
|
||||
# 写入 CSV 文件
|
||||
[label](koajs.md)CSV.write(filename, data)
|
||||
```
|
||||
|
||||
读取/保存 Julia 对象
|
||||
|
||||
```julia
|
||||
using JLD
|
||||
# 保存 Julia 对象
|
||||
save(filename, "object_key", object, ...)
|
||||
# 读取 Julia 对象
|
||||
d = load(filename) # 返回对象的字典
|
||||
```
|
||||
|
||||
读取/保存 HDF5
|
||||
|
||||
```julia
|
||||
using HDF5
|
||||
# 保存 HDF5
|
||||
h5write(filename, "key", object)
|
||||
# 读取 HDF5
|
||||
h5read(filename, "key")
|
||||
```
|
||||
|
||||
### 宏
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
宏允许你在程序中自动生成代码(如:表达式)
|
||||
|
||||
```julia
|
||||
# 定义
|
||||
macro macroname(expr)
|
||||
# 做点啥
|
||||
end
|
||||
```
|
||||
|
||||
使用
|
||||
|
||||
```julia
|
||||
macroname(ex1, ex2, ...) 或 @macroname ex1, ex2, ...
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
内置的宏
|
||||
|
||||
```julia
|
||||
@assert # assert (单元测试)
|
||||
@which # 查看对特定参数使用的方法/查找函数所在的模块
|
||||
@time # 运行时间与内存分配统计
|
||||
@elapsed # 返回执行用时
|
||||
@allocated # 查看内存分配
|
||||
@async # 异步任务
|
||||
|
||||
using Test
|
||||
@test # 精确相等
|
||||
@test x ≈ y # 近似相等 isapprox(x, y)
|
||||
|
||||
using Profile
|
||||
@profile # 优化
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
创建 卫生宏 (hygienic macros)的规则:
|
||||
|
||||
- 在宏的内部只通过 `local` 声明本地变量
|
||||
- 在宏的内部不使用 `eval`
|
||||
- 转义插值表达式以避免宏变大:`$(esc(expr))`
|
||||
|
||||
### 并行计算
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
并行计算相关的工具可以在标准库 `Distributed` 里找到
|
||||
|
||||
```julia
|
||||
# 启动带 N 各 worker 的 REPL
|
||||
julia -p N
|
||||
# 可用的 worker 数量
|
||||
nprocs()
|
||||
# 添加 N 个 worker
|
||||
addprocs(N)
|
||||
# 查看所有 worker 的 pid
|
||||
for pid in workers()
|
||||
println(pid)
|
||||
end
|
||||
# 获得正在执行的 worker 的 id
|
||||
myid()
|
||||
# 移除 worker
|
||||
rmprocs(pid)
|
||||
# 在特定 pid 的 worker 上运行 f(args)
|
||||
r = remotecall(f, pid, args...)
|
||||
# 或:
|
||||
r = @spawnat pid f(args)
|
||||
...
|
||||
fetch(r)
|
||||
# 在特定 pid 的 worker 上运行 f(args) (更高效)
|
||||
remotecall_fetch(f, pid, args...)
|
||||
# 在任意 worker 上运行 f(args)
|
||||
r = @spawn f(args) ... fetch(r)
|
||||
# 在所有 worker 上运行 f(args)
|
||||
r = [@spawnat w f(args) for w in workers()] ... fetch(r)
|
||||
# 让表达式 expr 在所有 worker 上执行
|
||||
@everywhere expr
|
||||
# 并行化带规约函数 red 的循环
|
||||
sum = @distributed (red) for i in 1:10^6
|
||||
# 进行并行任务
|
||||
end
|
||||
# 将 f 用用到集合 coll 中的所有元素上
|
||||
pmap(f, coll)
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 数组
|
||||
<!--rehype:wrap-class=col-span-2 row-span-2-->
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
声明数组 | `arr = Float64[]`
|
||||
预分配内存 | `sizehint!(arr, 10^4)`
|
||||
访问与赋值 | `arr = Any[1,2]`<br/>`arr[1] = "Some text"`
|
||||
从 m 到 n 的子数组 | `arr[m:n]`
|
||||
n 个 `0.0` 填充的数组 | `zeros(n)`
|
||||
n 个 `1.0` 填充的数组 | `ones(n)`
|
||||
n 个随机 Int8 填充的数组 | `rand(Int8, n)`
|
||||
用值 val 填充数组 | `fill!(arr, val)`
|
||||
弹出最后一个元素 | `pop!(arr)`
|
||||
弹出第一个元素 | `popfirst!(a)`
|
||||
n 个 `#undef` 填充的数组 | `Vector{Type}(undef,n)`
|
||||
n 个从 `start` 到 `stop` 的等间距数 | `range(start,stop=stop,length=n)`
|
||||
将值 `val` 作为最后一个元素压入数组 | `push!(arr, val)`
|
||||
将值 `val` 作为第一个元素压入数组 | `pushfirst!(arr, val)`
|
||||
删除指定索引值的元素 | `deleteat!(arr, idx)`
|
||||
数组排序 | `sort!(arr)`
|
||||
将 `b` 连接到 `a` 后 | `append!(a,b)`
|
||||
转化为字符串,并以 delim 分隔 | `join(arr, delim)`
|
||||
<!--rehype:className=left-align-->
|
||||
|
||||
---
|
||||
|
||||
```julia
|
||||
# 数组比较
|
||||
a = [1:10;]
|
||||
b = a # b 指向 a
|
||||
a[1] = -99
|
||||
a == b # true
|
||||
# 复制元素(而不是地址)/深拷贝
|
||||
b = copy(a)
|
||||
b = deepcopy(a)
|
||||
# 检查值 val 是否在数组 arr 中
|
||||
in(val, arr) # 或
|
||||
val in arr
|
||||
# 改变维数
|
||||
reshape(1:6, 3, 2)' == [1 2 3; 4 5 6]
|
||||
```
|
||||
|
||||
### 线性代数
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
单位矩阵 | `I`
|
||||
定义矩阵 | `M = [1 0; 0 1]`
|
||||
矩阵维数 | `size(M)`
|
||||
选出第 i 行 | `M[i, :]`
|
||||
选出第 j 列 | `M[:, j]`
|
||||
水平拼接 | `M = [a b] 或 M = hcat(a, b)`
|
||||
竖直拼接 | `M = [a ; b]` 或 `M = vcat(a, b)`
|
||||
矩阵转置 | `transpose(M)`
|
||||
共轭转置 | `M'` 或 `adjoint(M)`
|
||||
迹(trace) | `tr(M)`
|
||||
行列式 | `det(M)`
|
||||
秩(rank) | `rank(M)`
|
||||
特征值 | `eigvals(M)`
|
||||
特征向量 | `eigvecs(M)`
|
||||
矩阵求逆 | `inv(M)`
|
||||
解矩阵方程 `M*x == v` | `M\v` 比 `inv(M)*v` 更好
|
||||
求 Moore-Penrose 伪逆 | `pinv(M)`
|
||||
<!--rehype:className=left-align-->
|
||||
|
||||
控制流与循环
|
||||
---
|
||||
|
||||
### 条件语句
|
||||
|
||||
```julia
|
||||
if x < y
|
||||
println("x is less than y")
|
||||
elseif x > y
|
||||
println("x is greater than y")
|
||||
else
|
||||
println("x is equal to y")
|
||||
end
|
||||
```
|
||||
|
||||
### for 循环
|
||||
|
||||
```julia
|
||||
for i in 1:10
|
||||
println(i)
|
||||
end
|
||||
```
|
||||
|
||||
### 嵌套循环
|
||||
|
||||
```julia
|
||||
for i in 1:10, j = 1:5
|
||||
println(i*j)
|
||||
end
|
||||
```
|
||||
|
||||
### 枚举
|
||||
|
||||
```julia
|
||||
for (idx, val) in enumerate(arr)
|
||||
println("the $idx-th element is $val")
|
||||
end
|
||||
```
|
||||
|
||||
### while 循环
|
||||
|
||||
```julia
|
||||
while bool_expr
|
||||
# 做点啥
|
||||
end
|
||||
```
|
||||
|
||||
### 退出循环
|
||||
|
||||
```julia {4}
|
||||
julia> i = 0
|
||||
julia> while true
|
||||
global i += 1
|
||||
i > 5 && break
|
||||
println(i)
|
||||
end
|
||||
```
|
||||
|
||||
### 退出本次循环
|
||||
|
||||
```julia {2}
|
||||
for i = 1:6
|
||||
iseven(i) && continue
|
||||
println(i)
|
||||
end
|
||||
```
|
||||
|
||||
数字相关
|
||||
---
|
||||
|
||||
### 整数类型
|
||||
|
||||
`IntN` 和 `UIntN`, 且 `N ∈ {8, 16, 32, 64, 128}`, `BigInt`
|
||||
|
||||
### 浮点类型
|
||||
|
||||
`FloatN` 且 `N ∈ {16, 32, 64}`
|
||||
`BigFloat`
|
||||
|
||||
### 类型的最大和最小值
|
||||
|
||||
```julia
|
||||
typemin(Int8)
|
||||
typemax(Int64)
|
||||
```
|
||||
|
||||
### 复数类型
|
||||
|
||||
```julia
|
||||
Complex{T<:Real}
|
||||
```
|
||||
|
||||
### 虚数单位
|
||||
|
||||
```julia
|
||||
im
|
||||
```
|
||||
|
||||
### 机器精度
|
||||
|
||||
```julia
|
||||
eps() # 等价于 eps(Float64)
|
||||
```
|
||||
|
||||
### 圆整
|
||||
|
||||
```julia
|
||||
round() # 浮点数圆整
|
||||
round(Int, x) # 整数圆整
|
||||
```
|
||||
|
||||
### 类型转换
|
||||
|
||||
```julia
|
||||
# 尝试进行转换/可能会报错
|
||||
convert(TypeName, val)
|
||||
# 调用类型构造器转换
|
||||
TypeName(val)
|
||||
```
|
||||
|
||||
### 全局常量
|
||||
|
||||
```julia
|
||||
pi # 3.1415...
|
||||
π # 3.1415...
|
||||
im # real(im * im) == -1
|
||||
```
|
||||
|
||||
### 更多常量
|
||||
|
||||
```julia
|
||||
using Base.MathConstants
|
||||
```
|
||||
|
||||
模块
|
||||
---
|
||||
|
||||
### 定义
|
||||
|
||||
```julia
|
||||
module PackageName
|
||||
# 添加模块定义
|
||||
# 使用 export 让定义对外可见
|
||||
end
|
||||
```
|
||||
|
||||
### 包含文件 filename.jl
|
||||
|
||||
```julia
|
||||
include("filename.jl")
|
||||
```
|
||||
|
||||
### 加载
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```julia
|
||||
using ModuleName # 导出所有名称
|
||||
# 仅导出 x, y
|
||||
using ModuleName: x, y
|
||||
# 仅导出 x, y
|
||||
using ModuleName.x, ModuleName.y:
|
||||
# 仅导出 ModuleName
|
||||
import ModuleName
|
||||
# 仅导出 x, y
|
||||
import ModuleName: x, y
|
||||
# 仅导出 x, y
|
||||
import ModuleName.x, ModuleName.y
|
||||
```
|
||||
|
||||
`using` 和 `import` 只有一点区别:使用 `using` 时,你需要写 `function Foo.bar(..` 来给 `Foo` 模块的函数 `bar` 增添一个新方法; 而使用 `import Foo.bar` 时,只需写 `function bar(...` 就能达到同样的效果
|
||||
|
||||
### 导出
|
||||
|
||||
```julia
|
||||
# 得到模块导出名称的数组
|
||||
names(ModuleName)
|
||||
|
||||
# 包含未导出的、弃用的
|
||||
# 和编译器产生的名称
|
||||
names(ModuleName, all::Bool)
|
||||
# 也显示从其他模块显式导入的名称
|
||||
names(ModuleName, all::Bool, imported::Bool)
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
包管理
|
||||
---
|
||||
|
||||
### 介绍
|
||||
|
||||
一个程序包必须先[注册](https://github.com/JuliaRegistries/General),然后才能在包管理器中看到它。在 Julia 1.0 中,有两种使用包管理器的方法:
|
||||
|
||||
- 一是通过 `using Pkg` 导入 `Pkg` 模块,然后用它的函数管理其他包;
|
||||
- 或者在 REPL 中输入 `]`,然后按回车。进入特殊的交互式包管理模式。 (要从包管理模式返回 REPL,只需要在空行上按退格键 `BACKSPACE` 就行了)
|
||||
|
||||
注意新的工具总是先添加到交互式模式中,然后才会加入 `Pkg` 模块
|
||||
|
||||
### 在 Julia 会话中使用 Pkg 管理包
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
列出已安装的包 | `Pkg.status()`
|
||||
更新所有包 | `Pkg.update()`
|
||||
安装包 | `Pkg.add("PackageName")`
|
||||
重新构建包 | `Pkg.build("PackageName")`
|
||||
使用包 | `using PackageName`
|
||||
删除包 | `Pkg.rm("PackageName")`
|
||||
<!--rehype:className=left-align-->
|
||||
|
||||
### 交互式包管理模式
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
添加包 | `add PackageName`
|
||||
删除包 | `rm PackageName`
|
||||
更新包 | `update PackageName`
|
||||
使用开发版本 | `dev PackageName` 或 `dev GitRepoUrl`
|
||||
返回普通发行版 | `free PackageName`
|
||||
<!--rehype:className=left-align-->
|
||||
|
||||
另见
|
||||
---
|
||||
|
||||
- [快速入门一份简单而粗略的语言概览](https://cheatsheet.juliadocs.org/zh-cn/)
|
433
docs/latex.md
Normal file
433
docs/latex.md
Normal file
@ -0,0 +1,433 @@
|
||||
LaTeX 备忘清单
|
||||
===
|
||||
|
||||
本备忘单总结了 [LaTeX](https://www.latex-project.org/) 常用显示数学符号的参考列表和一些 [KaTeX](https://katex.org/) 的应用示例。
|
||||
|
||||
入门
|
||||
---
|
||||
|
||||
### 介绍
|
||||
|
||||
[LaTeX](https://www.latex-project.org/) 基于 TEX 的排版系统,适用于生成高印刷质量的科技和数学、物理文档。
|
||||
|
||||
- [LaTeX 官网](https://www.latex-project.org/) _(latex-project.org)_
|
||||
- [KaTeX 官网](https://katex.org/) _(katex.org)_
|
||||
|
||||
而 [KaTeX](https://katex.org/) 只处理 LaTeX 的数学符号的一个更小的子集,用于 web 上展示
|
||||
|
||||
### 示例
|
||||
|
||||
```KaTeX
|
||||
% \f is defined as #1f(#2) using the macro
|
||||
f\relax(x) = \int_{-\infty}^\infty
|
||||
f\hat\xi\,e^{2 \pi i \xi x}
|
||||
\,d\xi
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```LaTeX
|
||||
% \f is defined as #1f(#2) using the macro
|
||||
f\relax(x) = \int_{-\infty}^\infty
|
||||
f\hat\xi\,e^{2 \pi i \xi x}
|
||||
\,d\xi
|
||||
```
|
||||
|
||||
### 行内展示
|
||||
|
||||
```markdown
|
||||
基于 KaTeX 在一行
|
||||
展示示例: `KaTeX:\int_0^\infty x^2 dx`
|
||||
```
|
||||
|
||||
基于 KaTeX 在一行展示示例: `KaTeX:\int_0^\infty x^2 dx`
|
||||
|
||||
Supported Functions
|
||||
---
|
||||
|
||||
### Accents
|
||||
<!--rehype:wrap-class=col-span-2 row-span-2-->
|
||||
|
||||
:- | :- | :-
|
||||
:- | :- | :-
|
||||
`KaTeX:a'` <pur>`a'`</pur> | `KaTeX:\tilde{a}` <pur>`\tilde{a}`</pur> | `KaTeX:\mathring{g}` <pur>`\mathring{g}`</pur>
|
||||
`KaTeX:a''` <pur>`a''`</pur> | `KaTeX:\widetilde{ac}` <pur>`\widetilde{ac}`</pur> | `KaTeX:\overgroup{AB}` <pur>`\overgroup{AB}`</pur>
|
||||
`KaTeX:a^{\prime}` <pur>`a^{\prime}`</pur> | `KaTeX:\utilde{AB}` <pur>`\utilde{AB}`</pur> | `KaTeX:\undergroup{AB}` <pur>`\undergroup{AB}`</pur>
|
||||
`KaTeX:\acute{a}` <pur>`\acute{a}`</pur> | `KaTeX:\vec{F}` <pur>`\vec{F}`</pur> | `KaTeX:\Overrightarrow{AB}` <pur>`\Overrightarrow{AB}`</pur>
|
||||
`KaTeX:\bar{y}` <pur>`\bar{y}`</pur> | `KaTeX:\overleftarrow{AB}` <pur>`\overleftarrow{AB}`</pur> | `KaTeX:\overrightarrow{AB}` <pur>`\overrightarrow{AB}`</pur>
|
||||
`KaTeX:\breve{a}` <pur>`\breve{a}`</pur> | `KaTeX:\underleftarrow{AB}` <pur>`\underleftarrow{AB}`</pur> | `KaTeX:\underrightarrow{AB}` <pur>`\underrightarrow{AB}`</pur>
|
||||
`KaTeX:\check{a}` <pur>`\check{a}`</pur> | `KaTeX:\overleftharpoon{ac}` <pur>`\overleftharpoon{ac}`</pur> | `KaTeX:\overrightharpoon{ac}` <pur>`\overrightharpoon{ac}`</pur>
|
||||
`KaTeX:\dot{a}` <pur>`\dot{a}`</pur> | `KaTeX:\overleftrightarrow{AB}` <pur>`\overleftrightarrow{AB}`</pur> | `KaTeX:\overbrace{AB}` <pur>`\overbrace{AB}`</pur>
|
||||
`KaTeX:\ddot{a}` <pur>`\ddot{a}`</pur> | `KaTeX:\underleftrightarrow{AB}` <pur>`\underleftrightarrow{AB}`</pur> | `KaTeX:\underbrace{AB}` <pur>`\underbrace{AB}`</pur>
|
||||
`KaTeX:\grave{a}` <pur>`\grave{a}`</pur> | `KaTeX:\overline{AB}` <pur>`\overline{AB}`</pur> | `KaTeX:\overlinesegment{AB}` <pur>`\overlinesegment{AB}`</pur>
|
||||
`KaTeX:\hat{\theta}` <pur>`\hat{\theta}`</pur> | `KaTeX:\underline{AB}` <pur>`\underline{AB}`</pur> | `KaTeX:\underlinesegment{AB}` <pur>`\underlinesegment{AB}`</pur>
|
||||
`KaTeX:\widehat{ac}` <pur>`\widehat{ac}`</pur> | `KaTeX:\widecheck{ac}` <pur>`\widecheck{ac}`</pur> | `KaTeX:\underbar{X}` <pur>`\underbar{X}`</pur>
|
||||
|
||||
### \text{…}中的强调功能
|
||||
|
||||
:- | :- | :-
|
||||
:- | :- | :-
|
||||
`KaTeX:\'{a}` <pur>`\'{a}`</pur> | `KaTeX:\~{a}` <pur>`\~{a}`</pur> |
|
||||
`KaTeX:\.{a}` <pur>`\.{a}`</pur> | `KaTeX:\H{a}` <pur>`\H{a}`</pur> |
|
||||
``KaTeX:\\\`{a}`` <pur><code>\\`{a}</code></pur> | `KaTeX:\={a}` <pur>`\={a}`</pur> |
|
||||
`KaTeX:\"{a}` <pur>`\"{a}`</pur> | `KaTeX:\v{a}` <pur>`\v{a}`</pur> |
|
||||
`KaTeX:\^{a}` <pur>`\^{a}`</pur> | `KaTeX:\u{a}` <pur>`\u{a}`</pur> |
|
||||
`KaTeX:\r{a}` <pur>`\r{a}`</pur> |
|
||||
|
||||
### Delimiter Sizing
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`KaTeX:\left(\LARGE{AB}\right)` | <pur>`\left(\LARGE{AB}\right)`</pur>
|
||||
`KaTeX:( \big( \Big( \bigg( \Bigg(`| <pur>`( \big( \Big( \bigg( \Bigg(`</pur>
|
||||
|
||||
---
|
||||
|
||||
:- | :- | :- | :- | :-
|
||||
:- | :- | :- | :- | :-
|
||||
`\left` | `\big` | `\bigl` | `\bigm` | `\bigr`
|
||||
`\middle` | `\Big` | `\Bigl` | `\Bigm` | `\Bigr`
|
||||
`\right` | `\bigg` | `\biggl` | `\biggm` | `\biggr`
|
||||
`` | `\Bigg` | `\Biggl` | `\Biggm` | `\Biggr`
|
||||
|
||||
### 分隔符 Delimiters
|
||||
<!--rehype:wrap-class=col-span-3-->
|
||||
|
||||
预览 | 方法 | 预览 | 方法 | 预览 | 方法 | 预览| 方法 | 预览 | 方法
|
||||
:- | :- | :- | :- | :- | :- | :- | :- | :- | :-
|
||||
| `KaTeX:()` | <pur>`()`</pur> | `KaTeX:\lparen \rparen` | <pur>`\lparen` `\rparen`</pur> | `KaTex:⌈ ⌉` | <pur>`⌈ ⌉`</pur> | `KaTex:\lceil \rceil` | <pur>`\lceil` `\rceil`</pur> | `KaTex:\uparrow` | <pur>`\uparrow`</pur> |
|
||||
| `KaTeX:[]` | <pur>`[]`</pur> | `KaTeX:\lbrack \rbrack` | <pur>`\lbrack` `\rbrack`</pur> | `KaTex:⌊ ⌋` | <pur>`⌊ ⌋`</pur> | `KaTex:\lfloor \rfloor` | <pur>`\lfloor` `\rfloor`</pur> | `KaTex:\downarrow` | <pur>`\downarrow`</pur> |
|
||||
| `KaTeX:\{ \}` | <pur>`{}`</pur> | `KaTex:\lbrace \rbrace` | <pur>`\lbrace` `\rbrace`</pur> | `KaTex:⎰⎱` | <pur>`⎰⎱`</pur> | `KaTex:\lmoustache \rmoustache` | <pur>`\lmoustache` `\rmoustache`</pur> | `KaTex:\updownarrow` | <pur>`\updownarrow`</pur> |
|
||||
| `KaTeX:⟨ ⟩` | <pur>`⟨⟩`</pur> | `KaTex:\langle \rangle` | <pur>`\langle` `\rangle`</pur> | `KaTex:⟮ ⟯` | <pur>`⟮ ⟯`</pur> | `KaTex:\lgroup \rgroup` | <pur>`\lgroup` `\rgroup`</pur> | `KaTex:\Uparrow` | <pur>`\Uparrow`</pur> |
|
||||
| `KaTeX:∣` | <pur>`\|`</pur> | `KaTex:\vert` | <pur>`\vert`</pur> | `KaTex:┌ ┐` | <pur>`┌ ┐`</pur> | `KaTex:\ulcorner \urcorner` | <pur>`\ulcorner` `\urcorner`</pur> | `KaTex:\Downarrow` | <pur>`\Downarrow`</pur> |
|
||||
| `KaTeX:\|` _(<red>MD语法冲突</red>)_ | <pur><code>\\|</code></pur> | `KaTex:\Vert` | <pur>`\Vert`</pur> | `KaTex:└ ┘` | <pur>`└ ┘`</pur> | `KaTex:\llcorner \lrcorner` | <pur>`\llcorner` `\lrcorner`</pur> | `KaTex:\Updownarrow` | <pur>`\Updownarrow`</pur> |
|
||||
| `KaTeX:∣ ∣` | <pur>`\lvert` `\rvert`</pur> | `KaTex:\lVert \rVert` | <pur>`\lVert` `\rVert`</pur> | | <pur>`\left.`</pur> | | <pur>`\right.`</pur> | `KaTex:\backslash` | <pur>`\backslash`</pur> |
|
||||
| `KaTeX:\lang` `KaTeX:\rang` | <pur>`\lang` `\rang`<pur> | `KaTeX:\lt \gt` | <pur>`\lt \gt`</pur> | `KaTex:⟦ ⟧` | <pur>`⟦ ⟧`</pur> | `KaTex:\llbracket \rrbracket` | <pur>`\llbracket` `\rrbracket`</pur> | `KaTex:\lBrace \rBrace` | <pur>`\lBrace \rBrace`</pur> |
|
||||
<!--rehype:className=show-header left-align-->
|
||||
|
||||
Environments
|
||||
---
|
||||
|
||||
### Environments 1
|
||||
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
|
||||
|
||||
```KaTeX
|
||||
\begin{matrix}
|
||||
a & b \\
|
||||
c & d
|
||||
\end{matrix}
|
||||
```
|
||||
<!--rehype:style=flex:1;-->
|
||||
|
||||
```LaTeX
|
||||
\begin{matrix}
|
||||
a & b \\
|
||||
c & d
|
||||
\end{matrix}
|
||||
```
|
||||
<!--rehype:style=flex:1;-->
|
||||
|
||||
### Environments 2
|
||||
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
|
||||
|
||||
```KaTeX
|
||||
\begin{array}{cc}
|
||||
a & b \\
|
||||
c & d
|
||||
\end{array}
|
||||
```
|
||||
<!--rehype:style=flex:1;-->
|
||||
|
||||
```LaTeX
|
||||
\begin{array}{cc}
|
||||
a & b \\
|
||||
c & d
|
||||
\end{array}
|
||||
```
|
||||
|
||||
### Environments 3
|
||||
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
|
||||
|
||||
```KaTeX
|
||||
\begin{pmatrix}
|
||||
a & b \\
|
||||
c & d
|
||||
\end{pmatrix}
|
||||
```
|
||||
<!--rehype:style=flex:1;-->
|
||||
|
||||
```LaTeX
|
||||
\begin{pmatrix}
|
||||
a & b \\
|
||||
c & d
|
||||
\end{pmatrix}
|
||||
```
|
||||
<!--rehype:style=flex:1;-->
|
||||
|
||||
### Environments 4
|
||||
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
|
||||
|
||||
```KaTeX
|
||||
\begin{bmatrix}
|
||||
a & b \\
|
||||
c & d
|
||||
\end{bmatrix}
|
||||
```
|
||||
|
||||
```LaTeX
|
||||
\begin{bmatrix}
|
||||
a & b \\
|
||||
c & d
|
||||
\end{bmatrix}
|
||||
```
|
||||
|
||||
### Environments 5
|
||||
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
|
||||
|
||||
```KaTeX
|
||||
\begin{vmatrix}
|
||||
a & b \\
|
||||
c & d
|
||||
\end{vmatrix}
|
||||
```
|
||||
<!--rehype:style=flex:1;-->
|
||||
|
||||
```LaTeX
|
||||
\begin{vmatrix}
|
||||
a & b \\
|
||||
c & d
|
||||
\end{vmatrix}
|
||||
```
|
||||
<!--rehype:style=flex:1;-->
|
||||
|
||||
### Environments 6
|
||||
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
|
||||
|
||||
```KaTeX
|
||||
\begin{Vmatrix}
|
||||
a & b \\
|
||||
c & d
|
||||
\end{Vmatrix}
|
||||
```
|
||||
<!--rehype:style=flex:1;-->
|
||||
|
||||
```LaTeX
|
||||
\begin{Vmatrix}
|
||||
a & b \\
|
||||
c & d
|
||||
\end{Vmatrix}
|
||||
```
|
||||
<!--rehype:style=flex:1;-->
|
||||
|
||||
### Environments 7
|
||||
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
|
||||
|
||||
```KaTeX
|
||||
\begin{Bmatrix}
|
||||
a & b \\
|
||||
c & d
|
||||
\end{Bmatrix}
|
||||
```
|
||||
|
||||
```LaTeX
|
||||
\begin{Bmatrix}
|
||||
a & b \\
|
||||
c & d
|
||||
\end{Bmatrix}
|
||||
```
|
||||
|
||||
### Environments 8
|
||||
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
|
||||
|
||||
```KaTeX
|
||||
\def\arraystretch{1.5}
|
||||
\begin{array}{c:c:c}
|
||||
a & b & c \\ \hline
|
||||
d & e & f \\
|
||||
\hdashline
|
||||
g & h & i
|
||||
\end{array}
|
||||
```
|
||||
<!--rehype:style=flex:1;-->
|
||||
|
||||
```LaTeX
|
||||
\def\arraystretch{1.5}
|
||||
\begin{array}{c:c:c}
|
||||
a & b & c \\ \hline
|
||||
d & e & f \\
|
||||
\hdashline
|
||||
g & h & i
|
||||
\end{array}
|
||||
```
|
||||
|
||||
### Environments 9
|
||||
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
|
||||
|
||||
```KaTeX
|
||||
x = \begin{cases}
|
||||
a &\text{if } b \\
|
||||
c &\text{if } d
|
||||
\end{cases}
|
||||
```
|
||||
|
||||
```LaTeX
|
||||
x = \begin{cases}
|
||||
a &\text{if } b \\
|
||||
c &\text{if } d
|
||||
\end{cases}
|
||||
```
|
||||
|
||||
### Environments 10
|
||||
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
|
||||
|
||||
```KaTeX
|
||||
\begin{rcases}
|
||||
a &\text{if } b \\
|
||||
c &\text{if } d
|
||||
\end{rcases}⇒…
|
||||
```
|
||||
|
||||
```LaTeX
|
||||
\begin{rcases}
|
||||
a &\text{if } b \\
|
||||
c &\text{if } d
|
||||
\end{rcases}⇒…
|
||||
```
|
||||
|
||||
### Environments 11
|
||||
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
|
||||
|
||||
```KaTeX
|
||||
\begin{smallmatrix}
|
||||
a & b \\
|
||||
c & d
|
||||
\end{smallmatrix}
|
||||
```
|
||||
<!--rehype:style=flex:1;-->
|
||||
|
||||
```LaTeX
|
||||
\begin{smallmatrix}
|
||||
a & b \\
|
||||
c & d
|
||||
\end{smallmatrix}
|
||||
```
|
||||
|
||||
### Environments 12
|
||||
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
|
||||
|
||||
```KaTeX
|
||||
\sum_{
|
||||
\begin{subarray}{l}
|
||||
i\in\Lambda\\
|
||||
0<j<n
|
||||
\end{subarray}}
|
||||
```
|
||||
<!--rehype:style=flex:1;-->
|
||||
|
||||
```LaTeX
|
||||
\sum_{
|
||||
\begin{subarray}{l}
|
||||
i\in\Lambda\\
|
||||
0<j<n
|
||||
\end{subarray}}
|
||||
```
|
||||
|
||||
### Environments 13
|
||||
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
|
||||
|
||||
```KaTeX
|
||||
\begin{equation}
|
||||
\begin{split} a &=b+c\\
|
||||
&=e+f
|
||||
\end{split}
|
||||
\end{equation}
|
||||
```
|
||||
<!--rehype:style=flex:1;-->
|
||||
|
||||
```LaTeX
|
||||
\begin{equation}
|
||||
\begin{split} a &=b+c\\
|
||||
&=e+f
|
||||
\end{split}
|
||||
\end{equation}
|
||||
```
|
||||
|
||||
### Environments 14
|
||||
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
|
||||
|
||||
```KaTeX
|
||||
\begin{align}
|
||||
a&=b+c \\
|
||||
d+e&=f
|
||||
\end{align}
|
||||
```
|
||||
<!--rehype:style=flex:1;-->
|
||||
|
||||
```LaTeX
|
||||
\begin{align}
|
||||
a&=b+c \\
|
||||
d+e&=f
|
||||
\end{align}
|
||||
```
|
||||
|
||||
### Environments 15
|
||||
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
|
||||
|
||||
```KaTeX
|
||||
\begin{gather}
|
||||
a=b \\
|
||||
e=b+c
|
||||
\end{gather}
|
||||
```
|
||||
<!--rehype:style=flex:1;-->
|
||||
|
||||
```LaTeX
|
||||
\begin{gather}
|
||||
a=b \\
|
||||
e=b+c
|
||||
\end{gather}
|
||||
```
|
||||
|
||||
### Environments 16
|
||||
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
|
||||
|
||||
```KaTeX
|
||||
\begin{alignat}{2}
|
||||
10&x+&3&y=2\\
|
||||
3&x+&13&y=4
|
||||
\end{alignat}
|
||||
```
|
||||
<!--rehype:style=flex:1;-->
|
||||
|
||||
```LaTeX
|
||||
\begin{alignat}{2}
|
||||
10&x+&3&y=2\\
|
||||
3&x+&13&y=4
|
||||
\end{alignat}
|
||||
```
|
||||
|
||||
### Environments 17
|
||||
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
|
||||
|
||||
```KaTeX
|
||||
\begin{CD}
|
||||
A @>a>> B \\
|
||||
@VbVV @AAcA \\
|
||||
C @= D
|
||||
\end{CD}
|
||||
```
|
||||
<!--rehype:style=flex:1;-->
|
||||
|
||||
```LaTeX
|
||||
\begin{CD}
|
||||
A @>a>> B \\
|
||||
@VbVV @AAcA \\
|
||||
C @= D
|
||||
\end{CD}
|
||||
```
|
||||
|
||||
另见
|
||||
----
|
||||
|
||||
- [LaTeX 官网](https://www.latex-project.org/) _(latex-project.org)_
|
||||
- [KaTeX 官网](https://katex.org/) _(katex.org)_
|
@ -239,7 +239,7 @@ Markdown 表格生成器:[tableconvert.com](https://tableconvert.com/)
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
```html
|
||||
目前只支持部分段内 HTML 元素效果,包括 <kdb>, <b>, <i>, <em>, <sup>, <sub>, <br>
|
||||
目前只支持部分段内 HTML 元素效果,包括 <kbd>, <b>, <i>, <em>, <sup>, <sub>, <br>
|
||||
```
|
||||
|
||||
另见
|
||||
|
107
docs/npm.md
107
docs/npm.md
@ -154,6 +154,112 @@ $ nrm ls
|
||||
$ nrm use cnpm
|
||||
```
|
||||
|
||||
npx
|
||||
---
|
||||
|
||||
### 介绍
|
||||
|
||||
从本地或远程 npm 包运行命令
|
||||
|
||||
```bash
|
||||
npx -- <pkg>[@<version>] [args...]
|
||||
npx --package=<pkg>[@<version>] -- <cmd> [args...]
|
||||
npx -c '<cmd> [args...]'
|
||||
npx --package=foo -c '<cmd> [args...]'
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
`npx` 二进制文件在 `npm v7.0.0` 中被重写,并且当时不推荐使用独立的 `npx` 包
|
||||
|
||||
```bash
|
||||
$ npm install eslint
|
||||
# 运行:
|
||||
$ ./node_modules/.bin/eslint
|
||||
```
|
||||
|
||||
上面命令简化,直接运行下面👇命令
|
||||
|
||||
```bash
|
||||
$ npx eslint
|
||||
```
|
||||
|
||||
命令 `npx` 将自动安装并运行 `eslint`
|
||||
|
||||
### npx VS npm exec
|
||||
|
||||
```bash
|
||||
$ npx foo@latest bar --package=@npmcli/foo
|
||||
# npm 将解析 foo 包名,并运行以下命令:
|
||||
$ foo bar --package=@npmcli/foo
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
由于 npm 的参数解析逻辑,运行这个命令是不同的:
|
||||
|
||||
```bash
|
||||
$ npm exec foo@latest bar --package=@npmcli/foo
|
||||
# npm 将首先解析 --package 选项
|
||||
# 解析 @npmcli/foo 包
|
||||
# 然后,它将在该上下文中执行以下命令:
|
||||
$ foo@latest bar
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
下面命令是与 `npx` 等效的
|
||||
|
||||
```bash
|
||||
$ npm exec -- foo@latest bar --package=@npmcli/foo
|
||||
# 等效的
|
||||
$ npx foo@latest bar --package=@npmcli/foo
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### npx VS npm exec 示例
|
||||
|
||||
使用提供的参数在本地依赖项中运行 `tap` 版本:
|
||||
|
||||
```bash
|
||||
$ npm exec -- tap --bail test/foo.js
|
||||
$ npx tap --bail test/foo.js
|
||||
```
|
||||
|
||||
通过指定 `--package` 选项运行名称与包名称匹配的命令以外的命令:
|
||||
|
||||
```bash
|
||||
$ npm exec --package=foo -- bar --bar-argument
|
||||
# ~ or ~
|
||||
$ npx --package=foo bar --bar-argument
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
在当前项目的上下文中运行任意 `shell` 脚本:
|
||||
|
||||
```bash
|
||||
$ npm x -c 'eslint && say "hooray, lint passed"'
|
||||
$ npx -c 'eslint && say "hooray, lint passed"'
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 创建一个 React Naive 项目
|
||||
|
||||
```bash
|
||||
$ npx react-native init AwesomeProject
|
||||
$ npx react-native init AwesomeTSProject --template react-native-template-typescript
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
使用 `npx` 直接创建一个 [React Native]((https://reactnative.dev/docs/environment-setup#creating-a-new-application)) 应用
|
||||
|
||||
### 创建一个 React 应用
|
||||
|
||||
```bash
|
||||
$ npx create-react-app my-app
|
||||
$ npx create-react-app my-app --template typescript
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
使用 `npx` 跳过安装 [CRA](https://reactnative.dev/docs/environment-setup#creating-a-new-application),直接创建一个 [React](./react.md) 应用
|
||||
|
||||
配置
|
||||
---
|
||||
|
||||
@ -292,3 +398,4 @@ ELECTRON_BUILDER_BINARIES_MIRROR=https://npmmirror.com/mirrors/electron-builder-
|
||||
|
||||
- [npm 仓库、网站和命令行界面的文档](https://docs.npmjs.com/) _(npmjs.com)_
|
||||
- [npmmirror 中国镜像站](https://npmmirror.com/) _(npmmirror.com)_
|
||||
- [](https://michaelcurrin.github.io/dev-cheatsheets/cheatsheets/package-managers/javascript/npm/commands/npx.html) _(michaelcurrin.github.io)_
|
||||
|
972
docs/php.md
Normal file
972
docs/php.md
Normal file
@ -0,0 +1,972 @@
|
||||
PHP 备忘清单
|
||||
===
|
||||
|
||||
这份 [PHP](https://www.php.net/manual/zh/index.php) 备忘单为快速查找最常用代码的正确语法提供了参考
|
||||
|
||||
入门
|
||||
------
|
||||
|
||||
### hello.php
|
||||
|
||||
```php
|
||||
<?php // 以 PHP 开放标签开头
|
||||
echo "Hello World\n";
|
||||
print("Hello quickref.me");
|
||||
?>
|
||||
```
|
||||
|
||||
PHP 运行命令
|
||||
|
||||
```shell
|
||||
$ php hello.php
|
||||
```
|
||||
|
||||
### 变量 Variables
|
||||
|
||||
```php
|
||||
$boolean1 = true;
|
||||
$boolean2 = True;
|
||||
$int = 12;
|
||||
$float = 3.1415926;
|
||||
unset($float); // 删除变量
|
||||
$str1 = "How are you?";
|
||||
$str2 = 'Fine, thanks';
|
||||
```
|
||||
|
||||
查看: [Types](#php-类型)
|
||||
|
||||
### 字符串 Strings
|
||||
|
||||
```php
|
||||
$url = "quickref.me";
|
||||
echo "I'm learning PHP at $url";
|
||||
// 连接字符串
|
||||
echo "I'm learning PHP at " . $url;
|
||||
$hello = "Hello, ";
|
||||
$hello .= "World!";
|
||||
echo $hello; # => Hello, World!
|
||||
```
|
||||
|
||||
查看: [Strings](#php-字符串)
|
||||
|
||||
### 数组 Arrays
|
||||
|
||||
```php
|
||||
$num = [1, 3, 5, 7, 9];
|
||||
$num[5] = 11;
|
||||
unset($num[2]); // 删除变量
|
||||
print_r($num); # => 1 3 7 9 11
|
||||
echo count($num); # => 5
|
||||
```
|
||||
|
||||
查看: [Arrays](#php-数组)
|
||||
|
||||
### 运算符 Operators
|
||||
|
||||
```php
|
||||
$x = 1;
|
||||
$y = 2;
|
||||
$sum = $x + $y;
|
||||
echo $sum; # => 3
|
||||
```
|
||||
|
||||
查看: [Operators](#php-运算符)
|
||||
|
||||
### Include
|
||||
<!--rehype:wrap-class=row-span-3-->
|
||||
|
||||
#### vars.php
|
||||
|
||||
```php
|
||||
<?php // 以 PHP 开放标签开头。
|
||||
$fruit = 'apple';
|
||||
echo "I was imported";
|
||||
return 'Anything you like.';
|
||||
?>
|
||||
```
|
||||
|
||||
#### test.php
|
||||
|
||||
```php
|
||||
<?php
|
||||
include 'vars.php';
|
||||
echo $fruit . "\n"; # => apple
|
||||
/* 与 include 相同,
|
||||
如果不能包含则导致错误*/
|
||||
require 'vars.php';
|
||||
// 也有效
|
||||
include('vars.php');
|
||||
require('vars.php');
|
||||
// 通过 HTTP 包含
|
||||
include 'http://x.com/file.php';
|
||||
// 包含和返回语句
|
||||
$result = include 'vars.php';
|
||||
echo $result; # => Anything you like.
|
||||
?>
|
||||
```
|
||||
|
||||
### 功能 Functions
|
||||
|
||||
```php
|
||||
function add($num1, $num2 = 1) {
|
||||
return $num1 + $num2;
|
||||
}
|
||||
echo add(10); # => 11
|
||||
echo add(10, 5); # => 15
|
||||
```
|
||||
|
||||
查看: [Functions](#php-函数)
|
||||
|
||||
### 注释 Comments
|
||||
|
||||
```php
|
||||
# 这是一个单行 shell 样式的注释
|
||||
// 这是一行 c++ 风格的注释
|
||||
/* 这是一个多行注释
|
||||
另一行注释 */
|
||||
```
|
||||
|
||||
### 常数 Constants
|
||||
|
||||
```php
|
||||
const MY_CONST = "hello";
|
||||
echo MY_CONST; # => hello
|
||||
|
||||
# => MY_CONST is: hello
|
||||
echo 'MY_CONST is: ' . MY_CONST;
|
||||
```
|
||||
|
||||
### 类 Classes
|
||||
|
||||
```php
|
||||
class Student {
|
||||
public function __construct($name) {
|
||||
$this->name = $name;
|
||||
}
|
||||
}
|
||||
$alex = new Student("Alex");
|
||||
```
|
||||
|
||||
查看: [Classes](#php-类)
|
||||
|
||||
PHP 类型
|
||||
------
|
||||
|
||||
### 布尔值 Boolean
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```php
|
||||
$boolean1 = true;
|
||||
$boolean2 = TRUE;
|
||||
$boolean3 = false;
|
||||
$boolean4 = FALSE;
|
||||
$boolean5 = (boolean) 1; # => true
|
||||
$boolean6 = (boolean) 0; # => false
|
||||
```
|
||||
|
||||
布尔值不区分大小写
|
||||
|
||||
### 整数 Integer
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```php
|
||||
$int1 = 28; # => 28
|
||||
$int2 = -32; # => -32
|
||||
$int3 = 012; # => 10 (octal)
|
||||
$int4 = 0x0F; # => 15 (hex)
|
||||
$int5 = 0b101; # => 5 (binary)
|
||||
# => 2000100000 (decimal, PHP 7.4.0)
|
||||
$int6 = 2_000_100_000;
|
||||
```
|
||||
|
||||
另见: [Integers](https://www.php.net/manual/en/language.types.integer.php)
|
||||
|
||||
### 字符串 Strings
|
||||
|
||||
```php
|
||||
echo 'this is a simple string';
|
||||
```
|
||||
|
||||
查看: [Strings](#php-字符串)
|
||||
|
||||
### 数组 Arrays
|
||||
|
||||
```php
|
||||
$arr = array("hello", "world", "!");
|
||||
```
|
||||
|
||||
查看: [Arrays](#php-数组)
|
||||
|
||||
### 浮点数 Float (Double)
|
||||
|
||||
```php
|
||||
$float1 = 1.234;
|
||||
$float2 = 1.2e7;
|
||||
$float3 = 7E-10;
|
||||
$float4 = 1_234.567; // as of PHP 7.4.0
|
||||
var_dump($float4); // float(1234.567)
|
||||
$float5 = 1 + "10.5"; # => 11.5
|
||||
$float6 = 1 + "-1.3e3"; # => -1299
|
||||
```
|
||||
|
||||
### Null
|
||||
|
||||
```php
|
||||
$a = null;
|
||||
$b = 'Hello php!';
|
||||
echo $a ?? 'a is unset'; # => a is unset
|
||||
echo $b ?? 'b is unset'; # => Hello php
|
||||
$a = array();
|
||||
$a == null # => true
|
||||
$a === null # => false
|
||||
is_null($a) # => false
|
||||
```
|
||||
|
||||
### 可迭代对象 Iterables
|
||||
|
||||
```php
|
||||
function bar(): iterable {
|
||||
return [1, 2, 3];
|
||||
}
|
||||
function gen(): iterable {
|
||||
yield 1;
|
||||
yield 2;
|
||||
yield 3;
|
||||
}
|
||||
foreach (bar() as $value) {
|
||||
echo $value; # => 123
|
||||
}
|
||||
```
|
||||
|
||||
PHP 字符串
|
||||
------
|
||||
|
||||
### 字符串 String
|
||||
|
||||
```php
|
||||
# => '$String'
|
||||
$sgl_quotes = '$String';
|
||||
# => 'This is a $String.'
|
||||
$dbl_quotes = "This is a $sgl_quotes.";
|
||||
# => a tab character.
|
||||
$escaped = "a \t tab character.";
|
||||
# => a slash and a t: \t
|
||||
$unescaped = 'a slash and a t: \t';
|
||||
```
|
||||
|
||||
### 多行 Multi-line
|
||||
|
||||
```php
|
||||
$str = "foo";
|
||||
// 未插值的多行
|
||||
$nowdoc = <<<'END'
|
||||
Multi line string
|
||||
$str
|
||||
END;
|
||||
// 将执行字符串插值
|
||||
$heredoc = <<<END
|
||||
Multi line
|
||||
$str
|
||||
END;
|
||||
```
|
||||
|
||||
### 操作 Manipulation
|
||||
|
||||
```php
|
||||
$s = "Hello Phper";
|
||||
echo strlen($s); # => 11
|
||||
echo substr($s, 0, 3); # => Hel
|
||||
echo substr($s, 1); # => ello Phper
|
||||
echo substr($s, -4, 3);# => hpe
|
||||
echo strtoupper($s); # => HELLO PHPER
|
||||
echo strtolower($s); # => hello phper
|
||||
echo strpos($s, "l"); # => 2
|
||||
var_dump(strpos($s, "L")); # => false
|
||||
```
|
||||
|
||||
另见: [字符串函数](https://www.php.net/manual/en/ref.strings.php)
|
||||
|
||||
PHP 数组
|
||||
------
|
||||
|
||||
### 定义
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```php
|
||||
$a1 = ["hello", "world", "!"]
|
||||
$a2 = array("hello", "world", "!");
|
||||
$a3 = explode(",", "apple,pear,peach");
|
||||
```
|
||||
|
||||
#### 混合 int 和 string 键
|
||||
|
||||
```php
|
||||
$array = array(
|
||||
"foo" => "bar",
|
||||
"bar" => "foo",
|
||||
100 => -100,
|
||||
-100 => 100,
|
||||
);
|
||||
var_dump($array);
|
||||
```
|
||||
|
||||
#### 短数组语法
|
||||
|
||||
```php
|
||||
$array = [
|
||||
"foo" => "bar",
|
||||
"bar" => "foo",
|
||||
];
|
||||
```
|
||||
|
||||
### 多阵列
|
||||
|
||||
```php
|
||||
$multiArray = [
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
[7, 8, 9],
|
||||
];
|
||||
print_r($multiArray[0][0]) # => 1
|
||||
print_r($multiArray[0][1]) # => 2
|
||||
print_r($multiArray[0][2]) # => 3
|
||||
```
|
||||
|
||||
### 多类型
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```php
|
||||
$array = array(
|
||||
"foo" => "bar",
|
||||
42 => 24,
|
||||
"multi" => array(
|
||||
"dim" => array(
|
||||
"a" => "foo"
|
||||
)
|
||||
)
|
||||
);
|
||||
# => string(3) "bar"
|
||||
var_dump($array["foo"]);
|
||||
# => int(24)
|
||||
var_dump($array[42]);
|
||||
# => string(3) "foo"
|
||||
var_dump($array["multi"]["dim"]["a"]);
|
||||
```
|
||||
|
||||
### 操作
|
||||
|
||||
```php
|
||||
$arr = array(5 => 1, 12 => 2);
|
||||
$arr[] = 56; // 附加
|
||||
$arr["x"] = 42; // 用键添加
|
||||
sort($arr); // 排序
|
||||
unset($arr[5]); // 消除
|
||||
unset($arr); // 移除所有
|
||||
```
|
||||
|
||||
查看: [数组函数](https://www.php.net/manual/en/ref.array.php)
|
||||
|
||||
### 索引迭代
|
||||
|
||||
```php
|
||||
$array = array('a', 'b', 'c');
|
||||
$count = count($array);
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
echo "i:{$i}, v:{$array[$i]}\n";
|
||||
}
|
||||
```
|
||||
|
||||
### 价值迭代
|
||||
|
||||
```php
|
||||
$colors = array('red', 'blue', 'green');
|
||||
foreach ($colors as $color) {
|
||||
echo "Do you like $color?\n";
|
||||
}
|
||||
```
|
||||
|
||||
### 关键迭代
|
||||
|
||||
```php
|
||||
$arr = ["foo" => "bar", "bar" => "foo"];
|
||||
foreach ( $arr as $key => $value )
|
||||
{
|
||||
echo "key: " . $key . "\n";
|
||||
echo "val: {$arr[$key]}\n";
|
||||
}
|
||||
```
|
||||
|
||||
### 串联阵列
|
||||
|
||||
```php
|
||||
$a = [1, 2];
|
||||
$b = [3, 4];
|
||||
// PHP 7.4 以后
|
||||
# => [1, 2, 3, 4]
|
||||
$result = [...$a, ...$b];
|
||||
```
|
||||
|
||||
### Into 函数
|
||||
|
||||
```php
|
||||
$array = [1, 2];
|
||||
function foo(int $a, int $b) {
|
||||
echo $a; # => 1
|
||||
echo $b; # => 2
|
||||
}
|
||||
foo(...$array);
|
||||
```
|
||||
|
||||
### Splat运算符
|
||||
|
||||
```php
|
||||
function foo($first, ...$other) {
|
||||
var_dump($first); # => a
|
||||
var_dump($other); # => ['b', 'c']
|
||||
}
|
||||
foo('a', 'b', 'c' /*, ...*/ );
|
||||
// 或
|
||||
function foo($first, string ...$other){}
|
||||
```
|
||||
|
||||
PHP 运算符
|
||||
-------
|
||||
|
||||
### 算术
|
||||
|
||||
:- | -
|
||||
:- | -
|
||||
`+` | 添加
|
||||
`-` | 减法
|
||||
`*` | 乘法
|
||||
`/` | 分配
|
||||
`%` | 取模
|
||||
`**` | 求幂
|
||||
|
||||
### 分配
|
||||
|
||||
:- | -
|
||||
:- | -
|
||||
`a += b` | 如同 `a = a + b`
|
||||
`a -= b` | 如同 `a = a – b`
|
||||
`a *= b` | 如同 `a = a * b`
|
||||
`a /= b` | 如同 `a = a / b`
|
||||
`a %= b` | 如同 `a = a % b`
|
||||
|
||||
### 比较
|
||||
|
||||
:- | -
|
||||
:- | -
|
||||
`==` | 平等的
|
||||
`===` | 完全相同的
|
||||
`!=` | 不相等
|
||||
`<>` | 不相等
|
||||
`!==` | 不相同
|
||||
`<` | 少于
|
||||
`>` | 比...更棒
|
||||
`<=` | 小于或等于
|
||||
`>=` | 大于或等于
|
||||
`<=>` | 小于/等于/大于
|
||||
|
||||
### 逻辑的
|
||||
|
||||
:- | -
|
||||
:- | -
|
||||
`and` | 和
|
||||
`or` | 或者
|
||||
`xor` | 独家或
|
||||
`!` | 不是
|
||||
`&&` | 和
|
||||
`\|\|` | 或者
|
||||
|
||||
### 算术
|
||||
|
||||
```php
|
||||
// 算术
|
||||
$sum = 1 + 1; // 2
|
||||
$difference = 2 - 1; // 1
|
||||
$product = 2 * 2; // 4
|
||||
$quotient = 2 / 1; // 2
|
||||
// 速记算术
|
||||
$num = 0;
|
||||
$num += 1; // 将 $num 增加 1
|
||||
echo $num++; // 打印 1(评估后的增量)
|
||||
echo ++$num; // 打印 3(评估前的增量)
|
||||
$num /= $float; // 将商除并分配给 $num
|
||||
```
|
||||
|
||||
### 按位
|
||||
|
||||
:- | -
|
||||
:- | -
|
||||
`&` | 和
|
||||
`|` | 或(包括或)
|
||||
`^` | 异或(异或)
|
||||
`~` | 不是
|
||||
`<<` | 左移
|
||||
`>>` | 右移
|
||||
|
||||
PHP 条件
|
||||
------
|
||||
|
||||
### If elseif else
|
||||
|
||||
```php
|
||||
$a = 10;
|
||||
$b = 20;
|
||||
if ($a > $b) {
|
||||
echo "a is bigger than b";
|
||||
} elseif ($a == $b) {
|
||||
echo "a is equal to b";
|
||||
} else {
|
||||
echo "a is smaller than b";
|
||||
}
|
||||
```
|
||||
|
||||
### Switch
|
||||
|
||||
```php
|
||||
$x = 0;
|
||||
switch ($x) {
|
||||
case '0':
|
||||
print "it's zero";
|
||||
break;
|
||||
case 'two':
|
||||
case 'three':
|
||||
// do something
|
||||
break;
|
||||
default:
|
||||
// do something
|
||||
}
|
||||
```
|
||||
|
||||
### 三元运算符
|
||||
|
||||
```php
|
||||
# => Does
|
||||
print (false ? 'Not' : 'Does');
|
||||
$x = false;
|
||||
# => Does
|
||||
print($x ?: 'Does');
|
||||
$a = null;
|
||||
$b = 'Does print';
|
||||
# => a is unsert
|
||||
echo $a ?? 'a is unset';
|
||||
# => print
|
||||
echo $b ?? 'b is unset';
|
||||
```
|
||||
|
||||
### 匹配
|
||||
|
||||
```php
|
||||
$statusCode = 500;
|
||||
$message = match($statusCode) {
|
||||
200, 300 => null,
|
||||
400 => '未找到',
|
||||
500 => '服务器错误',
|
||||
default => '已知状态码',
|
||||
};
|
||||
echo $message; # => 服务器错误
|
||||
```
|
||||
|
||||
查看: [Match](https://www.php.net/manual/en/control-structures.match.php)
|
||||
|
||||
### 匹配表达式
|
||||
|
||||
```php
|
||||
$age = 23;
|
||||
$result = match (true) {
|
||||
$age >= 65 => 'senior',
|
||||
$age >= 25 => 'adult',
|
||||
$age >= 18 => 'young adult',
|
||||
default => 'kid',
|
||||
};
|
||||
echo $result; # => young adult
|
||||
```
|
||||
|
||||
PHP 循环
|
||||
------
|
||||
|
||||
### while 循环
|
||||
|
||||
```php
|
||||
$i = 1;
|
||||
# => 12345
|
||||
while ($i <= 5) {
|
||||
echo $i++;
|
||||
}
|
||||
```
|
||||
|
||||
### do while 循环
|
||||
|
||||
```php
|
||||
$i = 1;
|
||||
# => 12345
|
||||
do {
|
||||
echo $i++;
|
||||
} while ($i <= 5);
|
||||
```
|
||||
|
||||
### for i 循环
|
||||
|
||||
```php
|
||||
# => 12345
|
||||
for ($i = 1; $i <= 5; $i++) {
|
||||
echo $i;
|
||||
}
|
||||
```
|
||||
|
||||
### break 跳出循环
|
||||
|
||||
```php
|
||||
# => 123
|
||||
for ($i = 1; $i <= 5; $i++) {
|
||||
if ($i === 4) {
|
||||
break;
|
||||
}
|
||||
echo $i;
|
||||
}
|
||||
```
|
||||
|
||||
### continue 继续
|
||||
|
||||
```php
|
||||
# => 1235
|
||||
for ($i = 1; $i <= 5; $i++) {
|
||||
if ($i === 4) {
|
||||
continue;
|
||||
}
|
||||
echo $i;
|
||||
}
|
||||
```
|
||||
|
||||
### foreach 循环
|
||||
|
||||
```php
|
||||
$a = ['foo' => 1, 'bar' => 2];
|
||||
# => 12
|
||||
foreach ($a as $k) {
|
||||
echo $k;
|
||||
}
|
||||
```
|
||||
|
||||
查看: [Array iteration](#关键迭代)
|
||||
|
||||
PHP 函数
|
||||
------
|
||||
|
||||
### 返回值
|
||||
|
||||
```php
|
||||
function square($x)
|
||||
{
|
||||
return $x * $x;
|
||||
}
|
||||
echo square(4); # => 16
|
||||
```
|
||||
|
||||
### 返回类型
|
||||
|
||||
```php
|
||||
// 基本返回类型声明
|
||||
function sum($a, $b): float {/*...*/}
|
||||
function get_item(): string {/*...*/}
|
||||
class C {}
|
||||
// 返回一个对象
|
||||
function getC(): C { return new C; }
|
||||
```
|
||||
|
||||
### 可空返回类型
|
||||
|
||||
```php
|
||||
// 在 PHP 7.1 中可用
|
||||
function nullOrString(int $v) : ?string
|
||||
{
|
||||
return $v % 2 ? "odd" : null;
|
||||
}
|
||||
echo nullOrString(3); # => odd
|
||||
var_dump(nullOrString(4)); # => NULL
|
||||
```
|
||||
|
||||
查看: [Nullable types](https://www.php.net/manual/en/migration71.new-features.php)
|
||||
|
||||
### 无效函数
|
||||
|
||||
```php
|
||||
// 在 PHP 7.1 中可用
|
||||
function voidFunction(): void
|
||||
{
|
||||
echo 'Hello';
|
||||
return;
|
||||
}
|
||||
voidFunction(); # => Hello
|
||||
```
|
||||
|
||||
### 变量函数
|
||||
|
||||
```php
|
||||
function bar($arg = '')
|
||||
{
|
||||
echo "In bar(); arg: '$arg'.\n";
|
||||
}
|
||||
$func = 'bar';
|
||||
$func('test'); # => In bar(); arg: test
|
||||
```
|
||||
|
||||
### 匿名函数
|
||||
|
||||
```php
|
||||
$greet = function($name)
|
||||
{
|
||||
printf("Hello %s\r\n", $name);
|
||||
};
|
||||
$greet('World'); # => Hello World
|
||||
$greet('PHP'); # => Hello PHP
|
||||
```
|
||||
|
||||
### 递归函数
|
||||
|
||||
```php
|
||||
function recursion($x)
|
||||
{
|
||||
if ($x < 5) {
|
||||
echo "$x";
|
||||
recursion($x + 1);
|
||||
}
|
||||
}
|
||||
recursion(1); # => 1234
|
||||
```
|
||||
|
||||
### 默认参数
|
||||
|
||||
```php
|
||||
function coffee($type = "cappuccino")
|
||||
{
|
||||
return "Making a cup of $type.\n";
|
||||
}
|
||||
# => 制作一杯卡布奇诺
|
||||
echo coffee();
|
||||
# => 制作一杯
|
||||
echo coffee(null);
|
||||
# => 制作一杯浓缩咖啡
|
||||
echo coffee("espresso");
|
||||
```
|
||||
|
||||
### 箭头函数
|
||||
|
||||
```php
|
||||
$y = 1;
|
||||
|
||||
$fn1 = fn($x) => $x + $y;
|
||||
// 相当于按值使用 $y:
|
||||
$fn2 = function ($x) use ($y) {
|
||||
return $x + $y;
|
||||
};
|
||||
echo $fn1(5); # => 6
|
||||
echo $fn2(5); # => 6
|
||||
```
|
||||
|
||||
PHP 类
|
||||
------
|
||||
|
||||
### 构造函数 Constructor
|
||||
|
||||
```php
|
||||
class Student {
|
||||
public function __construct($name) {
|
||||
$this->name = $name;
|
||||
}
|
||||
public function print() {
|
||||
echo "Name: " . $this->name;
|
||||
}
|
||||
}
|
||||
$alex = new Student("Alex");
|
||||
$alex->print(); # => Name: Alex
|
||||
```
|
||||
|
||||
### 继承 Inheritance
|
||||
|
||||
```php
|
||||
class ExtendClass extends SimpleClass
|
||||
{
|
||||
// 重新定义父方法
|
||||
function displayVar()
|
||||
{
|
||||
echo "Extending class\n";
|
||||
parent::displayVar();
|
||||
}
|
||||
}
|
||||
$extended = new ExtendClass();
|
||||
$extended->displayVar();
|
||||
```
|
||||
|
||||
### 类变量 Classes variables
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```php
|
||||
class MyClass
|
||||
{
|
||||
const MY_CONST = 'value';
|
||||
static $staticVar = 'static';
|
||||
// 可见度
|
||||
public static $var1 = 'pubs';
|
||||
// 仅限类
|
||||
private static $var2 = 'pris';
|
||||
// 类和子类
|
||||
protected static $var3 = 'pros';
|
||||
// 类和子类
|
||||
protected $var6 = 'pro';
|
||||
// 仅限类
|
||||
private $var7 = 'pri';
|
||||
}
|
||||
```
|
||||
|
||||
静态访问
|
||||
|
||||
```php
|
||||
echo MyClass::MY_CONST; # => value
|
||||
echo MyClass::$staticVar; # => static
|
||||
```
|
||||
|
||||
### 魔术方法
|
||||
|
||||
```php
|
||||
class MyClass
|
||||
{
|
||||
// 对象被视为字符串
|
||||
public function __toString()
|
||||
{
|
||||
return $property;
|
||||
}
|
||||
// 与 __construct() 相反
|
||||
public function __destruct()
|
||||
{
|
||||
print "Destroying";
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 接口
|
||||
|
||||
```php
|
||||
interface Foo
|
||||
{
|
||||
public function doSomething();
|
||||
}
|
||||
interface Bar
|
||||
{
|
||||
public function doSomethingElse();
|
||||
}
|
||||
class Cls implements Foo, Bar
|
||||
{
|
||||
public function doSomething() {}
|
||||
public function doSomethingElse() {}
|
||||
}
|
||||
```
|
||||
|
||||
各种各样的
|
||||
------
|
||||
|
||||
### 基本错误处理
|
||||
|
||||
```php
|
||||
try {
|
||||
// 做一点事
|
||||
} catch (Exception $e) {
|
||||
// 处理异常
|
||||
} finally {
|
||||
echo "Always print!";
|
||||
}
|
||||
```
|
||||
|
||||
### PHP 8.0 中的异常
|
||||
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
```php {.wrap}
|
||||
$nullableValue = null;
|
||||
try {
|
||||
$value = $nullableValue ?? throw new InvalidArgumentException();
|
||||
} catch (InvalidArgumentException) { // 变量是可选的
|
||||
// 处理我的异常
|
||||
echo "print me!";
|
||||
}
|
||||
```
|
||||
|
||||
### 自定义异常
|
||||
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
```php
|
||||
class MyException extends Exception {
|
||||
// 做一点事
|
||||
}
|
||||
```
|
||||
|
||||
用法
|
||||
|
||||
```php
|
||||
try {
|
||||
$condition = true;
|
||||
if ($condition) {
|
||||
throw new MyException('bala');
|
||||
}
|
||||
} catch (MyException $e) {
|
||||
// 处理我的异常
|
||||
}
|
||||
```
|
||||
|
||||
### Nullsafe 运算符
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```php
|
||||
// 从 PHP 8.0.0 开始,这一行:
|
||||
$result = $repo?->getUser(5)?->name;
|
||||
// 相当于下面的代码:
|
||||
if (is_null($repo)) {
|
||||
$result = null;
|
||||
} else {
|
||||
$user = $repository->getUser(5);
|
||||
if (is_null($user)) {
|
||||
$result = null;
|
||||
} else {
|
||||
$result = $user->name;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
另见: [Nullsafe 运算符](https://wiki.php.net/rfc/nullsafe_operator)
|
||||
|
||||
### 常用表达
|
||||
|
||||
```php
|
||||
$str = "Visit Quickref.me";
|
||||
echo preg_match("/qu/i", $str); # => 1
|
||||
```
|
||||
|
||||
查看: [PHP中的正则表达式](./regex.md#php中的正则表达式)
|
||||
|
||||
### fopen() 模式
|
||||
|
||||
:- | -
|
||||
:- | -
|
||||
`r` | 读
|
||||
`r+` | 读写,前置
|
||||
`w` | 写入,截断
|
||||
`w+` | 读写,截断
|
||||
`a` | 写,追加
|
||||
`a+` | 读写,追加
|
||||
|
||||
### 运行时定义的常量
|
||||
|
||||
```php
|
||||
define("CURRENT_DATE", date('Y-m-d'));
|
||||
// 一种可能的表示
|
||||
echo CURRENT_DATE; # => 2021-01-05
|
||||
# => CURRENT_DATE is: 2021-01-05
|
||||
echo 'CURRENT_DATE is: ' . CURRENT_DATE;
|
||||
```
|
||||
|
||||
另见
|
||||
----
|
||||
|
||||
- [PHP 官方中文文档](https://www.php.net/manual/zh/index.php) _(php.net)_
|
||||
- [Learn X in Y minutes](https://learnxinyminutes.com/docs/php/) _(learnxinyminutes.com)_
|
@ -623,7 +623,7 @@ $ sudo systemctl restart postgresql
|
||||
|
||||
另见:[复制](https://www.postgresql.org/docs/current/sql-copy.html)
|
||||
|
||||
Also see
|
||||
--------
|
||||
另见
|
||||
----
|
||||
|
||||
- [Posgres-cheatsheet](https://gist.github.com/apolloclark/ea5466d5929e63043dcf#posgres-cheatsheet) _(gist.github.com)_
|
||||
|
@ -1232,3 +1232,10 @@ else: # try/except 块的可选子句。 必须遵循除块
|
||||
finally: # 在所有情况下执行
|
||||
print("我们可以在这里清理资源")
|
||||
```
|
||||
|
||||
另见
|
||||
----
|
||||
|
||||
- [Python](https://www.python.org/) _(python.org)_
|
||||
- [Learn X in Y minutes](https://learnxinyminutes.com/docs/python/) _(learnxinyminutes.com)_
|
||||
- [Regex in python](./regex.md#python-中的正则表达式) _(quickref.me)_
|
||||
|
@ -8,7 +8,7 @@ Quick Reference 备忘清单
|
||||
|
||||
### 本地编译预览
|
||||
|
||||
简单的将仓库克隆下来本地调试页面展示。
|
||||
将仓库克隆到本地调试页面。请参阅[贡献指南](https://github.com/jaywcjlove/reference/blob/main/CONTRIBUTING.md)了解如何开始
|
||||
|
||||
#### 克隆仓库
|
||||
|
||||
@ -22,12 +22,101 @@ git clone git@github.com:jaywcjlove/reference.git
|
||||
```shell
|
||||
npm i # 安装依赖
|
||||
npm run build # 编译输出 HTML
|
||||
npm run start # 监听 md 文件编译输出 HTML
|
||||
```
|
||||
|
||||
HTML 存放在仓库根目录下的 `dist` 目录中,将 `dist/index.html` 静态页面在浏览器中打开预览。
|
||||
|
||||
```shell
|
||||
npm run start # 监听 md 文件编译输出 HTML
|
||||
```
|
||||
|
||||
### 目录结构
|
||||
|
||||
```bash
|
||||
.
|
||||
├── CONTRIBUTING.md # 贡献说明
|
||||
├── Dockerfile
|
||||
├── LICENSE
|
||||
├── README.md # Home(首页) 内容
|
||||
├── dist # 编译后的静态资源目录
|
||||
├── docs # Markdown 文档(速查表)
|
||||
│ ├── bash.md
|
||||
│ ├── ....
|
||||
│ └── yaml.md
|
||||
├── package.json
|
||||
└── scripts # MD 转 HTML 的编译脚本
|
||||
├── assets # LOGO 图标文件资源
|
||||
├── ....
|
||||
└── watch.mjs
|
||||
```
|
||||
|
||||
### 添加一个备忘清单
|
||||
|
||||
一个简单的备忘清单包含 `页面大标题<h1>`,放在大标题下面的 `介绍` 文本,`<h2>` 分类标题,`<h3>` 内容为 `卡片`
|
||||
|
||||
```markdown
|
||||
备忘清单 (页面大标题)
|
||||
===
|
||||
|
||||
这是您可以在当前清单上使用的样式参考!备忘清单介绍
|
||||
|
||||
入门 (分类标题)
|
||||
---
|
||||
|
||||
### 介绍 (卡片)
|
||||
|
||||
卡片内容
|
||||
```
|
||||
|
||||
上面 markdown 内容存放到 `docs` 目录中,命名为 `xxx.md`
|
||||
|
||||
### 首页导航
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
首页(`README.md`)存放在仓库的根目录,通过这个 `README.md` 自动生成首页导航,下面是导航实例:
|
||||
|
||||
```markdown
|
||||
## Linux 命令
|
||||
|
||||
[Cron](./docs/cron.md)<!--rehype:style=background: rgb(239 68 68/var(\-\-bg\-opacity));-->
|
||||
<!--rehype:class=home-card-->
|
||||
```
|
||||
|
||||
首页导航图标存放在 `scripts/assets` 目录中,如果你的备忘清单定义为 `docs/cron.md`,那么你的图标就定义为 `cron.svg` 存放到 `scripts/assets` 目录中,重新编译首页当行菜单就拥有了图标。
|
||||
|
||||
- 图标存放在 [`scripts/assets`](https://github.com/jaywcjlove/reference/blob/main/scripts/assets) 目录中
|
||||
- 图片名称与清单名称保持一致 `cron.md` -> `cron.svg` (注意大小写)
|
||||
- SVG 图标尺寸 `<svg height="1em" width="1em"`
|
||||
- SVG 图标颜色使用继承颜色值 `<svg fill="currentColor"`
|
||||
- 使用 `<!--rehype:class=home-card-->` 标识卡片样式
|
||||
|
||||
### 首页提示配置
|
||||
|
||||
```markdown
|
||||
[Django](./docs/djiango.md)<!--rehype:style=background: rgb(12 75 51/var(\-\-bg\-opacity));&class=contributing-->
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
添加 `contributing` 类名,会在卡片下方默认添加 `👆待完善需要您的参与`
|
||||
|
||||
```markdown
|
||||
class=tag&data-info=👆看看还缺点儿什么?
|
||||
```
|
||||
|
||||
上面示例将默认提示更改为: `👆看看还缺点儿什么?`
|
||||
|
||||
```markdown
|
||||
[Django](./docs/djiango.md)<!--rehype:style=background: rgb(12 75 51/var(\-\-bg\-opacity));&class=tag&data-lang=Python-->
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
添加 `class=tag&data-lang=Python` 类名和参数,会在卡片右上角标记 _`Python`_
|
||||
|
||||
Markdown 语法注释
|
||||
---
|
||||
|
||||
### 介绍
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
在备忘清单采用 `HTML 注释语法`,标识网站布局和一些样式,目的是为了在 `GitHub` 中也是正常毫无瑕疵的预览 [`Markdown`](./markdown.md)。
|
||||
|
||||
@ -38,12 +127,12 @@ HTML 存放在仓库根目录下的 `dist` 目录中,将 `dist/index.html` 静
|
||||
卡片 Markdown 内容展示,下面注释语法为文字内容改变样式
|
||||
<!--rehype:style=color: red;-->
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
使用 `col-span-2` 类标识,卡片占 `2` 列位置
|
||||
上面基础示例,使用 `col-span-2` 类标识,卡片占 `2` 列位置,参考现有备忘清单的源代码是一个好习惯!
|
||||
|
||||
### 注释语法介绍
|
||||
<!--rehype:wrap-class=row-span-3&style=color:black;background-color: #d7a100;-->
|
||||
<!--rehype:wrap-class=row-span-4&style=color:black;background-color: #d7a100;-->
|
||||
|
||||
- 在某个 [`Markdown`](./markdown.md) 语法下方或者后面,添加 HTML注释
|
||||
- 以 `<!--rehype:` 开始,`-->` 结束,包裹参数内容
|
||||
@ -57,7 +146,7 @@ HTML 存放在仓库根目录下的 `dist` 目录中,将 `dist/index.html` 静
|
||||
#### 示例
|
||||
|
||||
```markdown
|
||||
### H2 部分
|
||||
## H2 部分
|
||||
<!--rehype:body-class=cols-2-->
|
||||
|
||||
### H3 部分
|
||||
@ -70,7 +159,7 @@ HTML 存放在仓库根目录下的 `dist` 目录中,将 `dist/index.html` 静
|
||||
### 标题
|
||||
<!--rehype:wrap-class=row-span-3&style=color:red;-->
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
#### 参数说明
|
||||
|
||||
@ -96,7 +185,7 @@ _我是红色_<!--rehype:style=color: red;-->
|
||||
**加粗变大红色**
|
||||
<!--rehype:style=color: red;font-size: 18px-->
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
上面添加注释样式,文字 _加粗变大红色_<!--rehype:style=color: red;font-size: 18px--> 变`红`并且`大`了
|
||||
|
||||
@ -106,7 +195,7 @@ _我是红色_<!--rehype:style=color: red;-->
|
||||
\```js
|
||||
function () {}
|
||||
\```
|
||||
<!--rehype:className=wrap-text -->
|
||||
<!--rehype:className=wrap-text-->
|
||||
```
|
||||
|
||||
如果代码块内容太长,使用强制换行类(`wrap-text`)解决
|
||||
@ -149,11 +238,11 @@ export const Student = (
|
||||
添加注释配置 `<!--rehype:tooltips-->` 添加一个 Tooltips 提示。
|
||||
|
||||
### H3 部分(卡片)背景颜色
|
||||
<!--rehype:wrap-style=background: #00c69357;-->
|
||||
<!--rehype:wrap-style=background: #8dffd42e;-->
|
||||
|
||||
```markdown
|
||||
### H3 部分(卡片)背景颜色
|
||||
<!--rehype:wrap-style=background: #00c69357;-->
|
||||
<!--rehype:wrap-style=background: #8dffd42e;-->
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
@ -214,35 +303,6 @@ const school = <div>学校</div>;
|
||||
`<del>` 或 `~~删除~~` | <del>~~红色~~</del>
|
||||
<!--rehype:className=shortcuts-->
|
||||
|
||||
### 注释类配置
|
||||
<!--rehype:wrap-class=col-span-2 row-span-2-->
|
||||
|
||||
类 | 说明
|
||||
---- | ----
|
||||
`<!--rehype:className=wrap-text-->` | 强制换行
|
||||
`<!--rehype:className=show-header-->` | 展示表格表头
|
||||
`<!--rehype:className=shortcuts-->` | 快捷键样式
|
||||
`<!--rehype:className=auto-wrap-->` | 隐藏表头强制小尺寸自动换行
|
||||
`<!--rehype:className=style-list-arrow-->` | 列表箭头样式展示表格
|
||||
`<!--rehype:className=style-list-->` | 列表样式展示表格
|
||||
`<!--rehype:className=left-align-->` | 表格末尾列左对齐
|
||||
`<!--rehype:className=style-none-->` | \<li> 没有标记
|
||||
`<!--rehype:className=style-timeline-->` | 时间轴样式
|
||||
`<!--rehype:className=style-arrow-->` | 箭头标记
|
||||
|
||||
### 隐藏卡片标题
|
||||
<!--rehype:style=display:none;&wrap-style=padding-top: 0;-->
|
||||
|
||||
```
|
||||
隐藏卡片标题,在 H3 标题下面添加注释样式
|
||||
```
|
||||
|
||||
```markdown {2}
|
||||
### 隐藏卡片标题
|
||||
<!--rehype:style=display:none;&wrap-style=padding-top: 0;-->
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### HTML 代码预览
|
||||
|
||||
```
|
||||
@ -259,6 +319,35 @@ const school = <div>学校</div>;
|
||||
|
||||
上面的 [`markdown`](./markdown.md) 代码在 `meta` 位置添加 `preview` 标识,[HTML](./html.md) 代码将被执行预览
|
||||
|
||||
### 隐藏卡片标题
|
||||
<!--rehype:style=display:none;&wrap-style=padding-top: 0;-->
|
||||
|
||||
```
|
||||
隐藏卡片标题,在 H3 标题下面添加注释样式
|
||||
```
|
||||
|
||||
```markdown {2}
|
||||
### 隐藏卡片标题
|
||||
<!--rehype:style=display:none;&wrap-style=padding-top: 0;-->
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### 注释类配置
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
类 | 说明
|
||||
---- | ----
|
||||
`<!--rehype:className=wrap-text-->` | 强制换行
|
||||
`<!--rehype:className=show-header-->` | 展示表格表头
|
||||
`<!--rehype:className=shortcuts-->` | 快捷键样式
|
||||
`<!--rehype:className=auto-wrap-->` | 隐藏表头强制小尺寸自动换行
|
||||
`<!--rehype:className=style-list-arrow-->` | 列表箭头样式展示表格
|
||||
`<!--rehype:className=style-list-->` | 列表样式展示表格
|
||||
`<!--rehype:className=left-align-->` | 表格末尾列左对齐
|
||||
`<!--rehype:className=style-none-->` | \<li> 没有标记
|
||||
`<!--rehype:className=style-timeline-->` | 时间轴样式
|
||||
`<!--rehype:className=style-arrow-->` | 箭头标记
|
||||
|
||||
### KaTeX 数学渲染
|
||||
|
||||
```KaTeX
|
||||
|
@ -452,7 +452,7 @@ M(?(?=.*?\bher\b)s|r)\.
|
||||
|
||||
表达式 | 匹配示例
|
||||
:- | -
|
||||
`.ar` | The `car` `par`ked in the `gar`age.
|
||||
`.ar` | The `car` <pur>`par`</pur>ked in the `gar`age.
|
||||
`ar[.]` | A garage is a good place to park a c`ar`.
|
||||
<!--rehype:className=show-header-->
|
||||
|
||||
@ -474,7 +474,7 @@ M(?(?=.*?\bher\b)s|r)\.
|
||||
|
||||
表达式 | 匹配示例
|
||||
:- | -
|
||||
`[a-z]*` | T`he` `car` `parked` `in` `the` `garage` #21.
|
||||
`[a-z]*` | T`he` <pur>`car`</pur> `parked` <pur>`in`</pur> `the` <pur>`garage`</pur> #21.
|
||||
`\s*cat\s*` | The fat `cat` sat on the con`cat`enation.
|
||||
|
||||
表达式 `[a-z]*` 匹配一个行中所有以小写字母开头的字符串。
|
||||
@ -503,7 +503,7 @@ M(?(?=.*?\bher\b)s|r)\.
|
||||
`[0-9]{2,3}` | The number was 9.`999`7 but we rounded it off to `10`.0.
|
||||
`[0-9]{2,}` | The number was 9.`9997` but we rounded it off to `10`.0.
|
||||
`[0-9]{3}` | The number was 9.`999`7 but we rounded it off to 10.0.
|
||||
<!--rehype:className=show-header-->
|
||||
<!--rehype:className=style-list-arrow-->
|
||||
|
||||
### `(...)` 特征标群
|
||||
|
||||
@ -616,7 +616,7 @@ M(?(?=.*?\bher\b)s|r)\.
|
||||
表达式 | 匹配示例
|
||||
:- | -
|
||||
`The` | The `fat` cat sat on the mat.
|
||||
`/The/gi` | The `fat` `cat` `sat` on the `mat`.
|
||||
`/The/gi` | `The` fat cat sat on `the` mat.
|
||||
<!--rehype:className=show-header-->
|
||||
|
||||
修饰语 `i` 用于忽略大小写,`g` 表示全局搜索。
|
||||
@ -722,7 +722,7 @@ False
|
||||
函数 | 说明
|
||||
:-|-
|
||||
`re.findall` | 返回包含所有匹配项的列表
|
||||
`re.finditer` | 返回一个可迭代的匹配对象(每个匹配一个)
|
||||
`re.finditer` | 返回一个可迭代的匹配对象<br/> _(每个匹配一个)_
|
||||
`re.search` | 如果字符串中的任何位置存在匹配项,则返回 Match 对象
|
||||
`re.split` | 返回一个列表,其中字符串在每次匹配时被拆分
|
||||
`re.sub` | 用字符串替换一个或多个匹配项
|
||||
|
774
docs/rust.md
774
docs/rust.md
@ -6,6 +6,35 @@ Rust 快速参考备忘单,旨在为编写基本语法和方法提供帮助。
|
||||
入门
|
||||
---
|
||||
|
||||
### 配置 vscode 调试
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
[配置参考](https://github.com/vadimcn/vscode-lldb/blob/master/MANUAL.md#source-path-remapping)。下载 CodeLLDB,选择 rust 自动生成 launch.json 文件
|
||||
|
||||
```json
|
||||
{
|
||||
"configurations": [
|
||||
// 添加一下行,使 vec/hashmap 等类型显示正常
|
||||
"sourceLanguages": ["rust"]
|
||||
]
|
||||
}
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
----
|
||||
|
||||
将编译文件与标准库的位置进行映射
|
||||
|
||||
```json
|
||||
{
|
||||
"lldb.launch.sourceMap": {
|
||||
// 你自己的映射 hash 和映射路径
|
||||
"/rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f": "/Users/feiwu/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust"
|
||||
}
|
||||
}
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### Hello_World.rs
|
||||
|
||||
```rust
|
||||
@ -19,6 +48,7 @@ fn main() {
|
||||
```shell
|
||||
$ rustc Hello_World.rs
|
||||
$ ./Hello_World
|
||||
|
||||
Hello, World!
|
||||
```
|
||||
|
||||
@ -142,25 +172,55 @@ foo!(3);
|
||||
|
||||
### 结构体
|
||||
|
||||
结构体是一个使用关键字 `struct` 定义的标称型(nominal)结构体类型
|
||||
|
||||
```rust
|
||||
struct Point { x: i32, y: i32 }
|
||||
let p = Point { x: 10, y: 11 };
|
||||
let px: i32 = p.x;
|
||||
```
|
||||
|
||||
结构体是一个使用关键字 `struct` 定义的标称型(nominal)结构体类型
|
||||
|
||||
### 枚举
|
||||
#### 元祖结构体
|
||||
|
||||
```rust
|
||||
enum Foo {
|
||||
Bar, // 0
|
||||
Baz = 123, // 123
|
||||
Quux, // 124
|
||||
}
|
||||
struct Color (i32, i32, i32);
|
||||
let black = Color(0,0,0);
|
||||
```
|
||||
|
||||
let baz_discriminant = Foo::Baz as u32;
|
||||
assert_eq!(baz_discriminant, 123);
|
||||
#### 单元结构体
|
||||
|
||||
不关心该类型的内容, 只关心它的行为。
|
||||
|
||||
```rust
|
||||
struct Solution;
|
||||
impl Solution{
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
### 语句与表达式
|
||||
|
||||
在 rust 中,语句无需返回值,而表达式总要返回值
|
||||
|
||||
#### 语句
|
||||
|
||||
```rust
|
||||
let a = "hello".to_string();
|
||||
let b = a + " world";
|
||||
println!("{}", b);
|
||||
```
|
||||
|
||||
#### 表达式
|
||||
|
||||
```rust
|
||||
fn main(){
|
||||
let x = {
|
||||
let a = "hello".to_string();
|
||||
a + " world"
|
||||
};
|
||||
println!("{}", x);
|
||||
// hello world
|
||||
}
|
||||
```
|
||||
|
||||
Rust 类型
|
||||
@ -220,6 +280,9 @@ println!("社区的名称是 {community_name},它有 {no_of_members} 个成员
|
||||
查看: [字符串](#rust-字符串)
|
||||
|
||||
### 数组
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
这里介绍的是固定长度的数组。rust 中常用的是集合类型 vec 表示的[动态数组](#rust-动态数组)
|
||||
|
||||
```rust
|
||||
┌─────┬─────┬─────┬─────┬─────┬─────┐
|
||||
@ -234,28 +297,8 @@ println!("社区的名称是 {community_name},它有 {no_of_members} 个成员
|
||||
let array: [i64; 6] = [92,97,98,99,98,94];
|
||||
```
|
||||
|
||||
### 多维数组
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```rust
|
||||
j0 j1 j2 j3 j4 j5
|
||||
┌────┬────┬────┬────┬────┬────┐
|
||||
i0 | 1 | 2 | 3 | 4 | 5 | 6 |
|
||||
├────┼────┼────┼────┼────┼────┤
|
||||
i1 | 6 | 5 | 4 | 3 | 2 | 1 |
|
||||
└────┴────┴────┴────┴────┴────┘
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
```rust
|
||||
let array: [[i64; 6] ;2] = [
|
||||
[1,2,3,4,5,6],
|
||||
[6,5,4,3,2,1]];
|
||||
```
|
||||
|
||||
### 可变数组
|
||||
|
||||
```rust
|
||||
let mut array: [i32 ; 3] = [2,6,10];
|
||||
array[1] = 4;
|
||||
@ -273,14 +316,6 @@ let mut slices: &[i64] = &array[0..3]
|
||||
println!("切片的元素是:{slices:?}");
|
||||
```
|
||||
|
||||
### 向量
|
||||
|
||||
```rust
|
||||
let some_vector = vec![1,2,3,4,5];
|
||||
```
|
||||
|
||||
使用 `vec!` 宏声明向量
|
||||
|
||||
### 元组
|
||||
|
||||
```rust
|
||||
@ -411,8 +446,28 @@ println!("{:?}", element2);
|
||||
}
|
||||
```
|
||||
|
||||
### 多维数组
|
||||
|
||||
```rust
|
||||
j0 j1 j2 j3 j4 j5
|
||||
┌────┬────┬────┬────┬────┬────┐
|
||||
i0 | 1 | 2 | 3 | 4 | 5 | 6 |
|
||||
├────┼────┼────┼────┼────┼────┤
|
||||
i1 | 6 | 5 | 4 | 3 | 2 | 1 |
|
||||
└────┴────┴────┴────┴────┴────┘
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
```rust
|
||||
let arr = vec![
|
||||
vec![1, 2, 3, 4, 5, 6],
|
||||
vec![6, 5, 4, 3, 2, 1]
|
||||
];
|
||||
```
|
||||
|
||||
### 常用方法
|
||||
<!--rehype:wrap-class=col-span-3-->
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
-|:-
|
||||
-|:-
|
||||
@ -429,6 +484,90 @@ println!("{:?}", element2);
|
||||
`drain(range)` | 删除 `vec` 中指定范围的元素,同时返回一个迭代该范围所有元素的迭代器
|
||||
`split_off(index)` | 切分 `vec`,索引左边的元素保留在原 `vec` 中(含索引),索引右边的元素(不含索引)在返回的 `vec` 中
|
||||
|
||||
枚举
|
||||
--------
|
||||
|
||||
### 在结构体中使用枚举
|
||||
|
||||
```rust
|
||||
enum IpAddrKind {
|
||||
V4,
|
||||
V6,
|
||||
}
|
||||
struct IpAddr {
|
||||
kind: IpAddrKind,
|
||||
address: String,
|
||||
}
|
||||
|
||||
fn main(){
|
||||
let ip = IpAddr{
|
||||
kind: IpAddrKind::V4,
|
||||
address: String::from("127.0.0.1")
|
||||
};
|
||||
}
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### 枚举的变体
|
||||
|
||||
```rust
|
||||
enum IpAddrKind {
|
||||
V4(u8, u8, u8, u8),
|
||||
V6(String),
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let home = IpAddrKind::V4(127, 0, 0, 1);
|
||||
let loopback = IpAddrKind::V6(String::from("::1"));
|
||||
}
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
----
|
||||
|
||||
```rust
|
||||
enum Message{
|
||||
Quit,
|
||||
Move {x:i32, y:i32},
|
||||
Write(String),
|
||||
ChangeColor(i32, i32, i32),
|
||||
}
|
||||
fn main(){
|
||||
let q = Message::Quit;
|
||||
let m = Message::Move {x:10, y:20};
|
||||
let w = Message:: Write(String::from("hello"));
|
||||
let c = Message::ChangeColor(10, 20, 30);
|
||||
}
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### 模式匹配结构体
|
||||
|
||||
```rust
|
||||
#[derive(Debug)]
|
||||
enum Grade {
|
||||
A,
|
||||
B,
|
||||
C,
|
||||
}
|
||||
enum Subject {
|
||||
Math(Grade),
|
||||
English(Grade),
|
||||
}
|
||||
|
||||
fn subject_grade(sub: Subject) {
|
||||
match sub {
|
||||
Subject::Math(grade) => println!("The Math is {:?}", grade),
|
||||
Subject::English(grade) => println!("The Math is {:?}", grade),
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
subject_grade(Subject::Math(Grade::A));
|
||||
}
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
Rust 运算符
|
||||
-----------
|
||||
|
||||
@ -535,29 +674,7 @@ let mut l = k;
|
||||
Rust 流程控制
|
||||
------------
|
||||
|
||||
### If表达式
|
||||
|
||||
```rust
|
||||
let case1: i32 = 81;
|
||||
let case2: i32 = 82;
|
||||
if case1 < case2 {
|
||||
println!("case1 大于 case2");
|
||||
}
|
||||
```
|
||||
|
||||
### If...Else 表达式
|
||||
|
||||
```rust
|
||||
let case3 = 8;
|
||||
let case4 = 9;
|
||||
if case3 >= case4 {
|
||||
println!("case3 优于 case4");
|
||||
} else {
|
||||
println!("case4 大于 case3");
|
||||
}
|
||||
```
|
||||
|
||||
### If...Else...if...Else 表达式
|
||||
### If 表达式
|
||||
|
||||
```rust
|
||||
let foo = 12;
|
||||
@ -573,101 +690,30 @@ if foo == bar {
|
||||
}
|
||||
```
|
||||
|
||||
### If...let 表达式
|
||||
<!--rehype:wrap-class=row-span-3-->
|
||||
|
||||
```rust
|
||||
let mut arr1:[i64 ; 3] = [1,2,3];
|
||||
if let[1,2,_] = arr1{
|
||||
println!("与数组一起使用");
|
||||
}
|
||||
let mut arr2:[&str; 2] = ["one", "two"];
|
||||
if let["Apple", _] = arr2{
|
||||
println!("也适用于 str 数组");
|
||||
}
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
```rust
|
||||
let tuple_1 = ("India", 7, 90, 90.432);
|
||||
if let(_, 7, 9, 78.99) = tuple_1{
|
||||
println!("也适用于元组");
|
||||
}
|
||||
let tuple_2 = ( 9, 7, 89, 12, "Okay");
|
||||
if let(9, 7,89, 12, blank) = tuple_2 {
|
||||
println!("一切{blank}伴侣?");
|
||||
}
|
||||
let tuple_3 = (89, 90, "Yes");
|
||||
if let(9, 89, "Yes") = tuple_3{
|
||||
println!("模式确实匹配");
|
||||
}
|
||||
else {
|
||||
println!("模式不匹配");
|
||||
}
|
||||
```
|
||||
|
||||
### 匹配表达式
|
||||
<!--rehype:wrap-class=row-span-3-->
|
||||
|
||||
```rust
|
||||
let day_of_week = 2;
|
||||
match day_of_week {
|
||||
1 => {
|
||||
println!("兄弟们今天是星期一");
|
||||
},
|
||||
2 => {
|
||||
println!("兄弟们今天是星期二");
|
||||
},
|
||||
3 => {
|
||||
println!("兄弟们今天是星期三");
|
||||
},
|
||||
4 => {
|
||||
println!("兄弟们今天是星期四");
|
||||
},
|
||||
5 => {
|
||||
println!("兄弟们今天是星期五");
|
||||
},
|
||||
6 => {
|
||||
println!("兄弟们今天是星期六");
|
||||
},
|
||||
7 => {
|
||||
println!("兄弟们今天是星期天");
|
||||
},
|
||||
_ => {
|
||||
println!("默认!")
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
### 嵌套...If 表达式
|
||||
|
||||
```rust
|
||||
let nested_conditions = 89;
|
||||
if nested_conditions == 89 {
|
||||
let just_a_value = 98;
|
||||
if just_a_value >= 97 {
|
||||
println!("大于 97");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### For 循环
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
```rust
|
||||
for mut i in 0..15 {
|
||||
i-=1;
|
||||
println!("i 的值为:{i}");
|
||||
let mut vec = [1, 2, 3];
|
||||
for v in &mut vec {
|
||||
*v -= 1;
|
||||
println!("v 的值为:{v}");
|
||||
}
|
||||
```
|
||||
|
||||
使用方法 | 等价使用方式 | 所有权
|
||||
:-|:-:|:-
|
||||
for item in collection | for item in collection.into_iter() | 转移所有权
|
||||
for item in &collection | for item in collection.iter() | 不可变借用
|
||||
for item in &mut collection | for item in collection.iter_mut() | 可变借用
|
||||
|
||||
### While 循环
|
||||
|
||||
```rust
|
||||
let mut check = 0;
|
||||
while check < 11{
|
||||
println!("check 是:{check}");
|
||||
check+=1;
|
||||
check += 1;
|
||||
println!("递增后:{check}");
|
||||
if check == 10{
|
||||
break; // 停止 while
|
||||
@ -675,7 +721,7 @@ while check < 11{
|
||||
}
|
||||
```
|
||||
|
||||
### Loop 关键字
|
||||
### Loop 循环
|
||||
|
||||
```rust
|
||||
loop {
|
||||
@ -685,19 +731,6 @@ loop {
|
||||
|
||||
无限循环表示
|
||||
|
||||
### Break 中断语句
|
||||
|
||||
```rust
|
||||
let mut i = 1;
|
||||
loop {
|
||||
println!("i 是 {i}");
|
||||
if i > 100 {
|
||||
break;
|
||||
}
|
||||
i *= 2;
|
||||
}
|
||||
```
|
||||
|
||||
### Continue 继续声明
|
||||
|
||||
```rust
|
||||
@ -711,116 +744,385 @@ for (v, c) in (0..10+1).enumerate(){
|
||||
}
|
||||
```
|
||||
|
||||
### Break 中断语句
|
||||
|
||||
`break` 可以单独使用,也可以带一个返回值
|
||||
|
||||
```rust
|
||||
let mut i = 1;
|
||||
let res = loop {
|
||||
println!("i 是 {i}");
|
||||
if i > 100 {
|
||||
break i - 100;
|
||||
}
|
||||
i *= 2;
|
||||
}
|
||||
|
||||
println!("{res}"); // 28
|
||||
```
|
||||
|
||||
Rust 模式匹配
|
||||
--------
|
||||
|
||||
### match
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
match 模式匹配,使用 `a | b` 表示匹配 a **或** b,使用 `_`,表示匹配剩余所有选项
|
||||
|
||||
```rust
|
||||
fn main(){
|
||||
let grade = Grade::A;
|
||||
match grade {
|
||||
Grade::A => println!("Good"),
|
||||
Grade::B => println!("Not bad"),
|
||||
Grade::C | Grade::D => println!("Come on"),
|
||||
_ => println!("emmm"),
|
||||
}
|
||||
}
|
||||
|
||||
enum Grade {
|
||||
A,
|
||||
B,
|
||||
C,
|
||||
D,
|
||||
E,
|
||||
F,
|
||||
}
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
#### `matches!` 宏
|
||||
|
||||
它可以将一个表达式跟模式进行匹配,然后返回匹配的结果 `true` 或 `false`
|
||||
|
||||
```rust
|
||||
assert!(matches!('x' ',A'..='Z' | 'a'..='z'));
|
||||
assert!(matches!(Some(101), Some(x) if x > 100));
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### if let 匹配
|
||||
|
||||
match 表达式需要匹配所有的枚举才能结束,但通常我们只需要匹配我们需要的值
|
||||
|
||||
```rust
|
||||
let x = 3;
|
||||
match Some(x) {
|
||||
Some(3) => println!("I guess that x is 3"),
|
||||
_ => ()
|
||||
}
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
使用 `if let`
|
||||
|
||||
```rust
|
||||
let x = 3;
|
||||
if let Some(3) = Some(x) {
|
||||
println!("I guess that x is 3");
|
||||
}
|
||||
```
|
||||
|
||||
### while let
|
||||
|
||||
```rust
|
||||
let mut stack = vec![];
|
||||
|
||||
stack.push(1);
|
||||
stack.push(2);
|
||||
stack.push(3);
|
||||
|
||||
while let Some(top) = stack.pop() {
|
||||
println!("{}", top);
|
||||
}
|
||||
```
|
||||
|
||||
### 其它模式匹配
|
||||
|
||||
#### for 循环迭代器
|
||||
|
||||
```rust
|
||||
for (i, v) in collection.iter().enumerate(){}
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
#### let
|
||||
|
||||
```rust
|
||||
let (x, _, y) = (1, 2, 3);
|
||||
println!("{x},{y}");
|
||||
```
|
||||
|
||||
### 函数中的模式匹配
|
||||
|
||||
```rust
|
||||
fn add((x, y): (i32, i32)) -> i32 {
|
||||
x + y
|
||||
}
|
||||
fn main(){
|
||||
let sum = add(1, 2);
|
||||
println!("{sum}");
|
||||
}
|
||||
```
|
||||
|
||||
### 忽略参数
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
#### 使用 `..` 忽略剩余参数
|
||||
|
||||
```rust
|
||||
struct Point {
|
||||
x: i32,
|
||||
y: i32,
|
||||
z: i32,
|
||||
}
|
||||
|
||||
let origin = Point { x: 0, y: 0, z: 0 };
|
||||
|
||||
match origin {
|
||||
Point { x, .. } => println!("x is {}", x),
|
||||
}
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
#### 使用 `_` 忽略部分参数
|
||||
|
||||
```rust
|
||||
let hello = ('h', 'e', 'l', 'l', 'o');
|
||||
|
||||
match hello {
|
||||
(h, _, _, l, o) => {
|
||||
println!("char: {}, {}, {}", h, l, o)
|
||||
},
|
||||
}
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### 匹配命名变量
|
||||
|
||||
以下代码,只要给定的 x 是 Some 类型,但 Some 中的值不是 1,都会匹配到 y
|
||||
|
||||
```rust
|
||||
let x = Some(10);
|
||||
match x {
|
||||
Some(1) => println!("x = 1"),
|
||||
Some(y) => println!("y = {:?}", y),
|
||||
_ => println!("None"),
|
||||
}// y = 10
|
||||
```
|
||||
|
||||
### `@` 绑定
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
`@` 运算符允许为一个字段绑定另外一个变量。
|
||||
|
||||
```rust
|
||||
let grade = 'A';
|
||||
match grade {
|
||||
good @ 'A'..='C' => println!("your grade is {}", good),
|
||||
_ => println!("Come on"),
|
||||
}
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
----
|
||||
|
||||
```rust
|
||||
#[derive(Debug)]
|
||||
struct Point {
|
||||
x: i32,
|
||||
y: i32,
|
||||
}
|
||||
fn main(){
|
||||
let p @ Point {x: px, y: py } = Point {x: 10, y: 23};
|
||||
println!("x: {}, y: {}", px, py);
|
||||
println!("{:?}", p);
|
||||
}
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
----
|
||||
|
||||
如果使用 `|`,需要使用 `()`,进行多个模式的绑定
|
||||
|
||||
```rust
|
||||
match 1 {
|
||||
num @ (1 | 2) => {
|
||||
println!("{}", num);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
```
|
||||
|
||||
### 使用匹配守卫
|
||||
|
||||
```rust
|
||||
let x = Some(2);
|
||||
match x {
|
||||
Some(1) => println!("x = 1"),
|
||||
Some(y) if y == 2 => println!("y = {:?}", y),
|
||||
_ => println!("No match"),
|
||||
}// y = 2
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
Rust 函数
|
||||
--------
|
||||
|
||||
### 基本函数
|
||||
### 函数命名
|
||||
|
||||
rust 的函数使用蛇形命名法(snake case)
|
||||
|
||||
```rust
|
||||
fn print_message(){
|
||||
println!("Hello, Quick Reference!");
|
||||
}
|
||||
```
|
||||
|
||||
### 参数值
|
||||
|
||||
rust 需要为函数的参数标明确定的类型
|
||||
|
||||
```rust
|
||||
fn another_fn(a:u8, b: &str){
|
||||
println!("我是 u8:{}", a);
|
||||
println!("我是 &str:{}", b);
|
||||
}
|
||||
|
||||
fn main(){
|
||||
// 在 Rust 中调用函数
|
||||
print_message();
|
||||
another_fn(10, "hello")
|
||||
}
|
||||
```
|
||||
|
||||
### 按值传递
|
||||
### 返回值
|
||||
|
||||
如果不指定返回值,rust 默认返回 `()` 类型
|
||||
|
||||
```rust
|
||||
fn main()
|
||||
{
|
||||
let x:u32 = 10;
|
||||
let y:u32 = 20;
|
||||
|
||||
// => 200
|
||||
println!("计算: {}", cal_rect(x, y));
|
||||
}
|
||||
fn cal_rect(x:u32, y:u32) -> u32
|
||||
{
|
||||
x * y
|
||||
// 在 bin 中的入口函数默认返回 ()
|
||||
fn main(){}
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
使用 `->` 指定返回值,如果**表达式**在最后一行,无需使用 return
|
||||
|
||||
```rust
|
||||
fn add(a:i32, b:i32) -> i32 {
|
||||
if a + b < 100 {
|
||||
return a - b;
|
||||
}
|
||||
a + b
|
||||
}
|
||||
```
|
||||
|
||||
### 通过引用传递
|
||||
### 永不返回 `!`
|
||||
|
||||
```rust
|
||||
fn main(){
|
||||
let mut by_ref = 3; // => 3
|
||||
power_of_three(&mut by_ref);
|
||||
println!("{by_ref}"); // => 9
|
||||
}
|
||||
fn power_of_three(by_ref: &mut i32){
|
||||
// 取消引用很重要
|
||||
*by_ref = *by_ref * *by_ref;
|
||||
println!("{by_ref}"); // => 9
|
||||
}
|
||||
```
|
||||
|
||||
### 返回
|
||||
|
||||
```rust
|
||||
fn main(){
|
||||
let (mut radius, mut pi) = (3.0, 3.14);
|
||||
let(area, _perimeter) = calculate (
|
||||
&mut radius,
|
||||
&mut pi
|
||||
);
|
||||
println!("圆的面积和周长为:{area} & {_perimeter}");
|
||||
}
|
||||
fn calculate(radius : &mut f64, pi: &mut f64) -> (f64, f64){
|
||||
let perimeter = 2.0 * *pi * *radius;
|
||||
let area = *pi * *radius * *radius;
|
||||
return (area, perimeter);
|
||||
fn dead_end() -> ! {
|
||||
panic!("panic!!!!!");
|
||||
}
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### 数组作为参数
|
||||
惯用转换
|
||||
-----
|
||||
|
||||
### &str -> String
|
||||
|
||||
```rust
|
||||
fn main(){
|
||||
let mut array: [i32 ; 5] = [1,2,3,4,6];
|
||||
print_arrays(array);
|
||||
println!("元素:{array:?}");
|
||||
}
|
||||
fn print_arrays(mut array:[i32; 5]) {
|
||||
array[0] = 89;
|
||||
array[1] = 90;
|
||||
array[2] = 91;
|
||||
array[3] = 92;
|
||||
array[4] = 93;
|
||||
println!("元素:{array:?}");
|
||||
}
|
||||
String::from("str");
|
||||
"str".to_string();
|
||||
"str".to_owned();
|
||||
```
|
||||
|
||||
### 返回数组
|
||||
### &str -> &[u8]
|
||||
|
||||
```rust
|
||||
fn main(){
|
||||
let mut arr:[i32; 5] = [2,4,6,8,10];
|
||||
multiply(arr);
|
||||
println!("数组是:{:?}", multiply(arr));
|
||||
}
|
||||
fn multiply (mut arr: [i32 ; 5]) -> [i32 ; 5]{
|
||||
arr[2] = 90;
|
||||
for mut i in 0..5 {
|
||||
arr[i] = arr[i] * arr[2];
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
"str".as_bytes();
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### 泛型函数
|
||||
或者你也可以使用 `b""`
|
||||
|
||||
```rust
|
||||
use std::fmt::Debug;
|
||||
fn foo<T>(x: &[T]) where T: Debug {
|
||||
// 省略细节
|
||||
}
|
||||
foo(&[1, 2]);
|
||||
println!("{:?}", b"str");
|
||||
```
|
||||
|
||||
### &str -> Vec<u8>
|
||||
|
||||
```rust
|
||||
"str".as_bytes().to_vec();
|
||||
"str".as_bytes().to_owned();
|
||||
```
|
||||
|
||||
### String -> &str
|
||||
|
||||
```rust
|
||||
let s = String::from("str");
|
||||
let r = s.as_str();
|
||||
```
|
||||
|
||||
### String -> &[u8]
|
||||
|
||||
```rust
|
||||
let s = String::from("str");
|
||||
let v = s.as_bytes();
|
||||
```
|
||||
|
||||
### String -> Vec<u8>
|
||||
|
||||
```rust
|
||||
let s = String::from("str");
|
||||
let v = s.into_bytes();
|
||||
```
|
||||
|
||||
### &[u8] -> &str
|
||||
|
||||
```rust
|
||||
let b = "str".as_bytes();
|
||||
let str = std::str::from_utf8(b).unwrap();
|
||||
```
|
||||
|
||||
### &[u8] -> String
|
||||
|
||||
```rust
|
||||
let b = "str".as_bytes();
|
||||
let str = String::from_utf8(b.to_vec()).unwrap();
|
||||
```
|
||||
|
||||
### &[u8] -> Vec<u8>
|
||||
|
||||
```rust
|
||||
let b = "str".as_bytes();
|
||||
let str = b.to_vec();
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
```rust
|
||||
let b = "str".as_bytes();
|
||||
let str = b.to_owned();
|
||||
```
|
||||
|
||||
### Vec<u8> -> &str
|
||||
|
||||
```rust
|
||||
let b = "str".as_bytes().to_vec();
|
||||
let s = std::str::from_utf8(&b).unwrap();
|
||||
```
|
||||
|
||||
### Vec<u8> -> &[u8]
|
||||
|
||||
```rust
|
||||
let b = "str".as_bytes().to_vec();
|
||||
let s = b.as_slice();
|
||||
```
|
||||
|
||||
### Vec<u8> -> String
|
||||
|
||||
```rust
|
||||
let b = "str".as_bytes().to_vec();
|
||||
let s = String::from_utf8(b).unwrap();
|
||||
```
|
||||
|
||||
杂项
|
||||
|
@ -10,8 +10,8 @@ TypeScript 备忘清单
|
||||
|
||||
TypeScript 是具有类型语法的 JavaScript。Interface 是为了匹配它们的运行时行为而构建的。
|
||||
|
||||
- [JavaScript 备忘清单](./javascript.md)
|
||||
- [TypeScript 官网](https://www.typescriptlang.org/)
|
||||
- [JavaScript 备忘清单](./javascript.md) _(jaywcjlove.github.io)_
|
||||
- [TypeScript 官网](https://www.typescriptlang.org/) _(typescriptlang.org)_
|
||||
|
||||
### 内置类型基元
|
||||
|
||||
@ -1264,3 +1264,68 @@ class Select<T> extends React.Component<SelectProps<T>, any> {}
|
||||
// 使用
|
||||
const Form = () => <Select<string> items={['a', 'b']} />;
|
||||
```
|
||||
|
||||
各种各样的技巧
|
||||
---
|
||||
|
||||
### 类型推导(infer)
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
```ts
|
||||
type Capitalize<T extends string> = T extends `${infer U}${infer V}`
|
||||
? `${Uppercase<U>}${V}`
|
||||
: T
|
||||
type capitalized = Capitalize<"hello world"> // Hello World
|
||||
```
|
||||
|
||||
- 也可以在 infer 中使用条件约束(`extends`)
|
||||
|
||||
```ts
|
||||
type SomeBigInt = "100" extends `${infer U extends bigint}` ? U : never;
|
||||
// 100n
|
||||
```
|
||||
|
||||
### keyof 取 interface 的键
|
||||
|
||||
```ts
|
||||
interface Point {
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
|
||||
// type keys = "x" | "y"
|
||||
type keys = keyof Point;
|
||||
```
|
||||
|
||||
### 索引签名
|
||||
|
||||
```ts
|
||||
interface NumberOrString {
|
||||
[index: string]: string | number;
|
||||
length: number;
|
||||
name: string;
|
||||
}
|
||||
```
|
||||
|
||||
### 从数组中提取类型
|
||||
|
||||
```ts
|
||||
type Point = { x: number; y: number; }
|
||||
type Data = Point[];
|
||||
// Data 是个数组,提取里面的元素类型
|
||||
type PointDetail = Data[number];
|
||||
// type PointDetail = { x: number; y: number; }
|
||||
```
|
||||
|
||||
### 只读元组类型
|
||||
|
||||
```ts
|
||||
const point = [3, 4] as const
|
||||
// type 'readonly [3, 4]'
|
||||
```
|
||||
|
||||
另见
|
||||
----
|
||||
|
||||
- [JavaScript 备忘清单](./javascript.md)
|
||||
- [TypeScript 官网](https://www.typescriptlang.org/) _(typescriptlang.org)_
|
||||
|
@ -408,7 +408,7 @@ Vim 搜索和替换
|
||||
`?foo` | 向后搜索
|
||||
`/\v\d+` | 使用 [regex](./regex.md) 搜索
|
||||
`n` | 下一个匹配的搜索模式
|
||||
`N` | 上一场比赛
|
||||
`N` | 上一个匹配的搜索
|
||||
`*` | 向前搜索当前单词
|
||||
`#` | 向后搜索当前单词
|
||||
|
||||
|
385
docs/vue.md
385
docs/vue.md
@ -275,66 +275,149 @@ v-on:submit.prevent="onSubmit"
|
||||
### 声明状态
|
||||
|
||||
```html
|
||||
<div>{{ count }}</div>
|
||||
<div>{{ state.count }}</div>
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```js {2,4}
|
||||
export default {
|
||||
data() {
|
||||
```js {6,7,11}
|
||||
import { defineComponent, reactive } from 'vue';
|
||||
|
||||
// `defineComponent`用于IDE推导类型
|
||||
export default defineComponent({
|
||||
// `setup` 是一个专门用于组合式 API 的特殊钩子函数
|
||||
setup() {
|
||||
const state = reactive({ count: 0 });
|
||||
|
||||
// 暴露 state 到模板
|
||||
return {
|
||||
count: 0
|
||||
}
|
||||
state
|
||||
};
|
||||
},
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### 声明方法
|
||||
|
||||
```html
|
||||
<button @click="increment">
|
||||
{{ count }}
|
||||
{{ state.count }}
|
||||
</button>
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```js {8-10}
|
||||
export default {
|
||||
data() {
|
||||
```js {7-9,14}
|
||||
import { defineComponent, reactive } from 'vue';
|
||||
|
||||
export default defineComponent({
|
||||
setup() {
|
||||
const state = reactive({ count: 0 });
|
||||
|
||||
function increment() {
|
||||
state.count++;
|
||||
}
|
||||
|
||||
// 不要忘记同时暴露 increment 函数
|
||||
return {
|
||||
count: 0
|
||||
}
|
||||
state,
|
||||
increment
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
increment() {
|
||||
this.count++
|
||||
}
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### `<script setup>` setup语法糖
|
||||
|
||||
```html {1}
|
||||
<script setup>
|
||||
// setup语法糖用于简化代码,尤其是当需要暴露的状态和方法越来越多时
|
||||
import { reactive } from 'vue';
|
||||
|
||||
const state = reactive({ count: 0 })
|
||||
|
||||
function increment() {
|
||||
state.count++
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<button @click="increment">
|
||||
{{ state.count }}
|
||||
</button>
|
||||
</template>
|
||||
```
|
||||
|
||||
### 用 `ref()` 定义响应式变量
|
||||
|
||||
```js
|
||||
// `reactive`只能用于对象、数组和 Map、Set 这样的集合类型,对 string、number 和 boolean 这样的原始类型则需要使用`ref`
|
||||
import { ref } from 'vue';
|
||||
|
||||
const count = ref(0);
|
||||
|
||||
console.log(count); // { value: 0 }
|
||||
console.log(count.value); // 0
|
||||
|
||||
count.value++;
|
||||
console.log(count.value); // 1
|
||||
|
||||
const objectRef = ref({ count: 0 });
|
||||
|
||||
// 这是响应式的替换
|
||||
objectRef.value = { count: 1 };
|
||||
|
||||
const obj = {
|
||||
foo: ref(1),
|
||||
bar: ref(2)
|
||||
};
|
||||
|
||||
// 该函数接收一个 ref
|
||||
// 需要通过 .value 取值
|
||||
// 但它会保持响应性
|
||||
callSomeFunction(obj.foo);
|
||||
|
||||
// 仍然是响应式的
|
||||
const { foo, bar } = obj;
|
||||
```
|
||||
|
||||
```html
|
||||
<!-- PS: 在html模板中不需要带.value就可以使用 -->
|
||||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
|
||||
const count = ref(0);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
{{ count }}
|
||||
</div>
|
||||
</template>
|
||||
```
|
||||
|
||||
### 有状态方法
|
||||
|
||||
```js
|
||||
import { debounce } from 'lodash-es'
|
||||
export default {
|
||||
created() {
|
||||
import { reactive, defineComponent, onUnmounted } from 'vue';
|
||||
import { debounce } from 'lodash-es';
|
||||
|
||||
export default defineComponent({
|
||||
setup() {
|
||||
// 每个实例都有了自己的预置防抖的处理函数
|
||||
this.debouncedClick = debounce(this.click, 500)
|
||||
},
|
||||
unmounted() {
|
||||
// 最好是在组件卸载时
|
||||
// 清除掉防抖计时器
|
||||
this.debouncedClick.cancel()
|
||||
},
|
||||
methods: {
|
||||
click() {
|
||||
const debouncedClick = debounce(click, 500);
|
||||
|
||||
function click() {
|
||||
// ... 对点击的响应 ...
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 最好是在组件卸载时
|
||||
// 清除掉防抖计时器
|
||||
onUnmounted(() => {
|
||||
debouncedClick.cancel();
|
||||
});
|
||||
},
|
||||
});
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
@ -346,32 +429,32 @@ API 参考
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`createApp()` | [#](https://cn.vuejs.org/api/application.html#create-app)
|
||||
`createSSRApp()` | [#](https://cn.vuejs.org/api/application.html#create-ssr-app)
|
||||
`app.mount()` | [#](https://cn.vuejs.org/api/application.html#app-mount)
|
||||
`app.unmount()` | [#](https://cn.vuejs.org/api/application.html#app-unmount)
|
||||
`app.provide()` | [#](https://cn.vuejs.org/api/application.html#app-provide)
|
||||
`app.component()` | [#](https://cn.vuejs.org/api/application.html#app-component)
|
||||
`app.directive()` | [#](https://cn.vuejs.org/api/application.html#app-directive)
|
||||
`app.use()` | [#](https://cn.vuejs.org/api/application.html#app-use)
|
||||
`app.mixin()` | [#](https://cn.vuejs.org/api/application.html#app-mixin)
|
||||
`app.version` | [#](https://cn.vuejs.org/api/application.html#app-version)
|
||||
`app.config` | [#](https://cn.vuejs.org/api/application.html#app-config)
|
||||
`app.config.errorHandler` | [#](https://cn.vuejs.org/api/application.html#app-config-errorhandler)
|
||||
`app.config.warnHandler` | [#](https://cn.vuejs.org/api/application.html#app-config-warnhandler)
|
||||
`app.config.performance` | [#](https://cn.vuejs.org/api/application.html#app-config-performance)
|
||||
`app.config.compilerOptions` | [#](https://cn.vuejs.org/api/application.html#app-config-compileroptions)
|
||||
`app.config.globalProperties` | [#](https://cn.vuejs.org/api/application.html#app-config-globalproperties)
|
||||
`app.config.optionMergeStrategies` | [#](https://cn.vuejs.org/api/application.html#app-config-optionmergestrategies)
|
||||
`createApp()` | 创建一个应用实例 [#](https://cn.vuejs.org/api/application.html#create-app)
|
||||
`createSSRApp()` | 以 [SSR 激活](https://cn.vuejs.org/guide/scaling-up/ssr.html#client-hydration)模式创建一个应用实例 [#](https://cn.vuejs.org/api/application.html#create-ssr-app)
|
||||
`app.mount()` | 将应用实例挂载在一个容器元素中 [#](https://cn.vuejs.org/api/application.html#app-mount)
|
||||
`app.unmount()` | 卸载一个已挂载的应用实例 [#](https://cn.vuejs.org/api/application.html#app-unmount)
|
||||
`app.provide()` | 提供一个可以在应用中的所有后代组件中注入使用的值 [#](https://cn.vuejs.org/api/application.html#app-provide)
|
||||
`app.component()` | 注册或获取全局组件 [#](https://cn.vuejs.org/api/application.html#app-component)
|
||||
`app.directive()` | 注册或获取全局指令 [#](https://cn.vuejs.org/api/application.html#app-directive)
|
||||
`app.use()` | 安装一个插件 [#](https://cn.vuejs.org/api/application.html#app-use)
|
||||
`app.mixin()` | 全局注册一个混入 [#](https://cn.vuejs.org/api/application.html#app-mixin)
|
||||
`app.version` | 当前应用所使用的 Vue 版本号 [#](https://cn.vuejs.org/api/application.html#app-version)
|
||||
`app.config` | 获得应用实例的配置设定 [#](https://cn.vuejs.org/api/application.html#app-config)
|
||||
`app.config.errorHandler` | 为应用内抛出的未捕获错误指定一个全局处理函数 [#](https://cn.vuejs.org/api/application.html#app-config-errorhandler)
|
||||
`app.config.warnHandler` | 为 Vue 的运行时警告指定一个自定义处理函数 [#](https://cn.vuejs.org/api/application.html#app-config-warnhandler)
|
||||
`app.config.performance` | 在浏览器开发工具中追踪性能表现 [#](https://cn.vuejs.org/api/application.html#app-config-performance)
|
||||
`app.config.compilerOptions` | 配置运行时编译器的选项 [#](https://cn.vuejs.org/api/application.html#app-config-compileroptions)
|
||||
`app.config.globalProperties` | 注册全局属性对象 [#](https://cn.vuejs.org/api/application.html#app-config-globalproperties)
|
||||
`app.config.optionMergeStrategies` | 定义自定义组件选项的合并策略的对象 [#](https://cn.vuejs.org/api/application.html#app-config-optionmergestrategies)
|
||||
|
||||
### 全局 API - 通用
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`version` | [#](https://cn.vuejs.org/api/general.html#version)
|
||||
`nextTick()` | [#](https://cn.vuejs.org/api/general.html#nexttick)
|
||||
`defineComponent()` | [#](https://cn.vuejs.org/api/general.html#definecomponent)
|
||||
`defineAsyncComponent()` | [#](https://cn.vuejs.org/api/general.html#defineasynccomponent)
|
||||
`version` | Vue 版本号 [#](https://cn.vuejs.org/api/general.html#version)
|
||||
`nextTick()` | 等待下一次 DOM 更新后执行回调 [#](https://cn.vuejs.org/api/general.html#nexttick)
|
||||
`defineComponent()` | 在定义 Vue 组件时提供类型推导的辅助函数 [#](https://cn.vuejs.org/api/general.html#definecomponent)
|
||||
`defineAsyncComponent()` | 定义一个异步组件 [#](https://cn.vuejs.org/api/general.html#defineasynccomponent)
|
||||
`defineCustomElement()` | [#](https://cn.vuejs.org/api/general.html#definecustomelement)
|
||||
|
||||
### 组合式 API - setup()
|
||||
@ -387,13 +470,13 @@ API 参考
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`isRef()` | [#](https://cn.vuejs.org/api/reactivity-utilities.html#isref)
|
||||
`unref()` | [#](https://cn.vuejs.org/api/reactivity-utilities.html#unref)
|
||||
`toRef()` | [#](https://cn.vuejs.org/api/reactivity-utilities.html#toref)
|
||||
`toRefs()` | [#](https://cn.vuejs.org/api/reactivity-utilities.html#torefs)
|
||||
`isProxy()` | [#](https://cn.vuejs.org/api/reactivity-utilities.html#isproxy)
|
||||
`isReactive()` | [#](https://cn.vuejs.org/api/reactivity-utilities.html#isreactive)
|
||||
`isReadonly()` | [#](https://cn.vuejs.org/api/reactivity-utilities.html#isreadonly)
|
||||
`isRef()` | 判断是否为 ref [#](https://cn.vuejs.org/api/reactivity-utilities.html#isref)
|
||||
`unref()` | 是 ref,返回内部值,否则返回参数本身 [#](https://cn.vuejs.org/api/reactivity-utilities.html#unref)
|
||||
`toRef()` | 创建一个属性对应的 ref [#](https://cn.vuejs.org/api/reactivity-utilities.html#toref)
|
||||
`toRefs()` | 将对象上的每一个可枚举属性转换为 ref [#](https://cn.vuejs.org/api/reactivity-utilities.html#torefs)
|
||||
`isProxy()` | 检查一个对象是否是由 `reactive()`、`readonly()`、`shallowReactive()` 或 `shallowReadonly()` 创建的代理 [#](https://cn.vuejs.org/api/reactivity-utilities.html#isproxy)
|
||||
`isReactive()` | 检查一个对象是否是由 `reactive()` 或 `shallowReactive()` 创建的代理。 [#](https://cn.vuejs.org/api/reactivity-utilities.html#isreactive)
|
||||
`isReadonly()` | 检查传入的值是否为只读对象 [#](https://cn.vuejs.org/api/reactivity-utilities.html#isreadonly)
|
||||
|
||||
### 组合式 API - 生命周期钩子
|
||||
<!--rehype:wrap-class=row-span-3-->
|
||||
@ -418,144 +501,144 @@ API 参考
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`provide()` | [#](https://cn.vuejs.org/api/composition-api-dependency-injection.html#provide)
|
||||
`inject()` | [#](https://cn.vuejs.org/api/composition-api-dependency-injection.html#inject)
|
||||
`provide()` | 提供一个可以被后代组件中注入使用的值 [#](https://cn.vuejs.org/api/composition-api-dependency-injection.html#provide)
|
||||
`inject()` | 注入一个由祖先组件提供的值 [#](https://cn.vuejs.org/api/composition-api-dependency-injection.html#inject)
|
||||
|
||||
### 组合式 API - 响应式: 核心
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`ref()` | [#](https://cn.vuejs.org/api/reactivity-core.html#ref)
|
||||
`computed ()` | [#](https://cn.vuejs.org/api/reactivity-core.html#computed)
|
||||
`reactive()` | [#](https://cn.vuejs.org/api/reactivity-core.html#reactive)
|
||||
`readonly()` | [#](https://cn.vuejs.org/api/reactivity-core.html#readonly)
|
||||
`watchEffect()` | [#](https://cn.vuejs.org/api/reactivity-core.html#watcheffect)
|
||||
`watchPostEffect()` | [#](https://cn.vuejs.org/api/reactivity-core.html#watchposteffect)
|
||||
`watchSyncEffect()` | [#](https://cn.vuejs.org/api/reactivity-core.html#watchsynceffect)
|
||||
`watch()` | [#](https://cn.vuejs.org/api/reactivity-core.html#watch)
|
||||
`ref()` | 返回一个 ref 对象 [#](https://cn.vuejs.org/api/reactivity-core.html#ref)
|
||||
`computed ()` | 定义一个计算属性 [#](https://cn.vuejs.org/api/reactivity-core.html#computed)
|
||||
`reactive()` | 返回一个对象的响应式代理 [#](https://cn.vuejs.org/api/reactivity-core.html#reactive)
|
||||
`readonly()` | 返回一个原值的只读代理 [#](https://cn.vuejs.org/api/reactivity-core.html#readonly)
|
||||
`watchEffect()` | 立即运行一个函数,同时监听 [#](https://cn.vuejs.org/api/reactivity-core.html#watcheffect)
|
||||
`watchPostEffect()` | `watchEffect()` 使用 `flush: 'post'` 选项时的别名。 [#](https://cn.vuejs.org/api/reactivity-core.html#watchposteffect)
|
||||
`watchSyncEffect()` | `watchEffect()` 使用 `flush: 'sync'` 选项时的别名。 [#](https://cn.vuejs.org/api/reactivity-core.html#watchsynceffect)
|
||||
`watch()` | 侦听一个或多个响应式数据源 [#](https://cn.vuejs.org/api/reactivity-core.html#watch)
|
||||
|
||||
### 选项式 API - 状态选项
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`data` | [#](https://cn.vuejs.org/api/options-state.html#data)
|
||||
`props` | [#](https://cn.vuejs.org/api/options-state.html#props)
|
||||
`computed` | [#](https://cn.vuejs.org/api/options-state.html#computed)
|
||||
`methods` | [#](https://cn.vuejs.org/api/options-state.html#methods)
|
||||
`watch` | [#](https://cn.vuejs.org/api/options-state.html#watch)
|
||||
`emits` | [#](https://cn.vuejs.org/api/options-state.html#emits)
|
||||
`expose` | [#](https://cn.vuejs.org/api/options-state.html#expose)
|
||||
`data` | 声明组件初始响应式状态 [#](https://cn.vuejs.org/api/options-state.html#data)
|
||||
`props` | 声明一个组件的 props [#](https://cn.vuejs.org/api/options-state.html#props)
|
||||
`computed` | 声明要在组件实例上暴露的计算属性 [#](https://cn.vuejs.org/api/options-state.html#computed)
|
||||
`methods` | 声明要混入到组件实例中的方法 [#](https://cn.vuejs.org/api/options-state.html#methods)
|
||||
`watch` | 声明在数据更改时调用的侦听回调 [#](https://cn.vuejs.org/api/options-state.html#watch)
|
||||
`emits` | 声明由组件触发的自定义事件 [#](https://cn.vuejs.org/api/options-state.html#emits)
|
||||
`expose` | 声明当组件实例被父组件通过模板引用访问时暴露的公共属性 [#](https://cn.vuejs.org/api/options-state.html#expose)
|
||||
|
||||
### 选项式 API - 生命周期选项
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`beforeCreate` | [#](https://cn.vuejs.org/api/options-lifecycle.html#beforecreate)
|
||||
`created` | [#](https://cn.vuejs.org/api/options-lifecycle.html#created)
|
||||
`beforeMount` | [#](https://cn.vuejs.org/api/options-lifecycle.html#beforemount)
|
||||
`mounted` | [#](https://cn.vuejs.org/api/options-lifecycle.html#mounted)
|
||||
`beforeUpdate` | [#](https://cn.vuejs.org/api/options-lifecycle.html#beforeupdate)
|
||||
`updated` | [#](https://cn.vuejs.org/api/options-lifecycle.html#updated)
|
||||
`beforeUnmount` | [#](https://cn.vuejs.org/api/options-lifecycle.html#beforeunmount)
|
||||
`unmounted` | [#](https://cn.vuejs.org/api/options-lifecycle.html#unmounted)
|
||||
`errorCaptured` | [#](https://cn.vuejs.org/api/options-lifecycle.html#errorcaptured)
|
||||
`renderTracked` | [#](https://cn.vuejs.org/api/options-lifecycle.html#rendertracked)
|
||||
`renderTriggered` | [#](https://cn.vuejs.org/api/options-lifecycle.html#rendertriggered-sup-classvt-badge-dev-only)
|
||||
`activated` | [#](https://cn.vuejs.org/api/options-lifecycle.html#activated)
|
||||
`deactivated` | [#](https://cn.vuejs.org/api/options-lifecycle.html#deactivated)
|
||||
`serverPrefetch` | [#](https://cn.vuejs.org/api/options-lifecycle.html#serverprefetch)
|
||||
`beforeCreate` | 组件实例初始化完成之后立即调用 [#](https://cn.vuejs.org/api/options-lifecycle.html#beforecreate)
|
||||
`created` | 组件实例处理完所有与状态相关的选项后调用 [#](https://cn.vuejs.org/api/options-lifecycle.html#created)
|
||||
`beforeMount` | 组件被挂载之前调用 [#](https://cn.vuejs.org/api/options-lifecycle.html#beforemount)
|
||||
`mounted` | 组件被挂载之后调用 [#](https://cn.vuejs.org/api/options-lifecycle.html#mounted)
|
||||
`beforeUpdate` | 状态变更而更新其 DOM 树之前调用 [#](https://cn.vuejs.org/api/options-lifecycle.html#beforeupdate)
|
||||
`updated` | 状态变更而更新其 DOM 树之后调用 [#](https://cn.vuejs.org/api/options-lifecycle.html#updated)
|
||||
`beforeUnmount` | 组件实例被卸载之前调用 [#](https://cn.vuejs.org/api/options-lifecycle.html#beforeunmount)
|
||||
`unmounted` | 组件实例被卸载之后调用 [#](https://cn.vuejs.org/api/options-lifecycle.html#unmounted)
|
||||
`errorCaptured` | 捕获了后代组件传递的错误时调用 [#](https://cn.vuejs.org/api/options-lifecycle.html#errorcaptured)
|
||||
`renderTracked` _Dev only_ | 组件渲染过程中追踪到响应式依赖时调用 [#](https://cn.vuejs.org/api/options-lifecycle.html#rendertracked)
|
||||
`renderTriggered` _Dev only_ | 响应式依赖的变更触发了组件渲染时调用 [#](https://cn.vuejs.org/api/options-lifecycle.html#rendertriggered-sup-classvt-badge-dev-only)
|
||||
`activated` | 若组件实例是 <KeepAlive> 缓存树的一部分,当组件被插入到 DOM 中时调用 [#](https://cn.vuejs.org/api/options-lifecycle.html#activated)
|
||||
`deactivated` | 若组件实例是 <KeepAlive> 缓存树的一部分,当组件从 DOM 中被移除时调用 [#](https://cn.vuejs.org/api/options-lifecycle.html#deactivated)
|
||||
`serverPrefetch` _SSR only_ | 组件实例在服务器上被渲染之前调用 [#](https://cn.vuejs.org/api/options-lifecycle.html#serverprefetch)
|
||||
|
||||
### 选项式 API - 其他杂项
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`name` | 显式声明组件展示时的名称 [#](https://cn.vuejs.org/api/options-misc.html#name)
|
||||
`inheritAttrs` | 默认的组件 `attribute` 透传行为 [#](https://cn.vuejs.org/api/options-misc.html#inheritattrs)
|
||||
`components` | [#](https://cn.vuejs.org/api/options-misc.html#components)
|
||||
`directives` | [#](https://cn.vuejs.org/api/options-misc.html#directives)
|
||||
`inheritAttrs` | 是否启用默认的组件 `attribute` 透传行为 [#](https://cn.vuejs.org/api/options-misc.html#inheritattrs)
|
||||
`components` | 注册对当前组件实例可用的组件 [#](https://cn.vuejs.org/api/options-misc.html#components)
|
||||
`directives` | 注册对当前组件实例可用的指令 [#](https://cn.vuejs.org/api/options-misc.html#directives)
|
||||
|
||||
### 选项式 API - 渲染选项
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`template` | [#](https://cn.vuejs.org/api/options-rendering.html#template)
|
||||
`render` | [#](https://cn.vuejs.org/api/options-rendering.html#render)
|
||||
`compilerOptions` | [#](https://cn.vuejs.org/api/options-rendering.html#compileroptions)
|
||||
`template` | 声明组件的字符串模板 [#](https://cn.vuejs.org/api/options-rendering.html#template)
|
||||
`render` | 编程式地创建组件虚拟 DOM 树的函数 [#](https://cn.vuejs.org/api/options-rendering.html#render)
|
||||
`compilerOptions` | 配置组件模板的运行时编译器选项 [#](https://cn.vuejs.org/api/options-rendering.html#compileroptions)
|
||||
|
||||
### 选项式 API - 组件实例
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`$data` | [#](https://cn.vuejs.org/api/component-instance.html#data)
|
||||
`$props` | [#](https://cn.vuejs.org/api/component-instance.html#props)
|
||||
`$el` | [#](https://cn.vuejs.org/api/component-instance.html#el)
|
||||
`$options` | [#](https://cn.vuejs.org/api/component-instance.html#options)
|
||||
`$parent` | [#](https://cn.vuejs.org/api/component-instance.html#parent)
|
||||
`$root` | [#](https://cn.vuejs.org/api/component-instance.html#root)
|
||||
`$slots` | [#](https://cn.vuejs.org/api/component-instance.html#slots)
|
||||
`$refs` | [#](https://cn.vuejs.org/api/component-instance.html#refs)
|
||||
`$attrs` | [#](https://cn.vuejs.org/api/component-instance.html#attrs)
|
||||
`$watch()` | [#](https://cn.vuejs.org/api/component-instance.html#watch)
|
||||
`$emit()` | [#](https://cn.vuejs.org/api/component-instance.html#emit)
|
||||
`$forceUpdate()` | [#](https://cn.vuejs.org/api/component-instance.html#forceupdate)
|
||||
`$nextTick()` | [#](https://cn.vuejs.org/api/component-instance.html#nexttick)
|
||||
`$data` | 观察的数据对象 [#](https://cn.vuejs.org/api/component-instance.html#data)
|
||||
`$props` | 组件已解析的 props 对象 [#](https://cn.vuejs.org/api/component-instance.html#props)
|
||||
`$el` | 实例管理的 DOM 根节点 [#](https://cn.vuejs.org/api/component-instance.html#el)
|
||||
`$options` | 实例的初始化选项 [#](https://cn.vuejs.org/api/component-instance.html#options)
|
||||
`$parent` | 父实例 [#](https://cn.vuejs.org/api/component-instance.html#parent)
|
||||
`$root` | 当前组件树的根实例 [#](https://cn.vuejs.org/api/component-instance.html#root)
|
||||
`$slots` | 访问被插槽分发的内容 [#](https://cn.vuejs.org/api/component-instance.html#slots)
|
||||
`$refs` | DOM 元素和组件实例 [#](https://cn.vuejs.org/api/component-instance.html#refs)
|
||||
`$attrs` | 包含了组件所有[透传 attributes](https://cn.vuejs.org/guide/components/attrs.html) [#](https://cn.vuejs.org/api/component-instance.html#attrs)
|
||||
`$watch()` | 观察 Vue 实例上的一个表达式或者一个函数计算结果的变化 [#](https://cn.vuejs.org/api/component-instance.html#watch)
|
||||
`$emit()` | 触发一个自定义事件 [#](https://cn.vuejs.org/api/component-instance.html#emit)
|
||||
`$forceUpdate()` | 强制该组件重新渲染 [#](https://cn.vuejs.org/api/component-instance.html#forceupdate)
|
||||
`$nextTick()` | 回调延迟执行 [#](https://cn.vuejs.org/api/component-instance.html#nexttick)
|
||||
|
||||
### 选项式 API - 组合选项
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`provide` | [#](https://cn.vuejs.org/api/options-composition.html#provide)
|
||||
`inject` | [#](https://cn.vuejs.org/api/options-composition.html#inject)
|
||||
`mixins` | [#](https://cn.vuejs.org/api/options-composition.html#mixins)
|
||||
`extends` | [#](https://cn.vuejs.org/api/options-composition.html#extends)
|
||||
`provide` | 提供可以被后代组件注入的值 [#](https://cn.vuejs.org/api/options-composition.html#provide)
|
||||
`inject` | 注入一个由祖先组件提供的值 [#](https://cn.vuejs.org/api/options-composition.html#inject)
|
||||
`mixins` | 接收一个混入对象的数组 [#](https://cn.vuejs.org/api/options-composition.html#mixins)
|
||||
`extends` | 要继承的“基类”组件 [#](https://cn.vuejs.org/api/options-composition.html#extends)
|
||||
|
||||
### 内置内容 - 指令
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`v-text` | [#](https://cn.vuejs.org/api/built-in-directives.html#v-text)
|
||||
`v-html` | [#](https://cn.vuejs.org/api/built-in-directives.html#v-html)
|
||||
`v-show` | [#](https://cn.vuejs.org/api/built-in-directives.html#v-show)
|
||||
`v-if` | [#](https://cn.vuejs.org/api/built-in-directives.html#v-if)
|
||||
`v-text` | 更新元素的 `textContent` [#](https://cn.vuejs.org/api/built-in-directives.html#v-text)
|
||||
`v-html` | 更新元素的 `innerHTML` [#](https://cn.vuejs.org/api/built-in-directives.html#v-html)
|
||||
`v-show` | 切换元素的 `display` css 属性 [#](https://cn.vuejs.org/api/built-in-directives.html#v-show)
|
||||
`v-if` | 有条件地渲染元素 [#](https://cn.vuejs.org/api/built-in-directives.html#v-if)
|
||||
`v-else` | [#](https://cn.vuejs.org/api/built-in-directives.html#v-else)
|
||||
`v-else-if` | [#](https://cn.vuejs.org/api/built-in-directives.html#v-else-if)
|
||||
`v-for` | [#](https://cn.vuejs.org/api/built-in-directives.html#v-for)
|
||||
`v-on` | [#](https://cn.vuejs.org/api/built-in-directives.html#v-on)
|
||||
`v-bind` | [#](https://cn.vuejs.org/api/built-in-directives.html#v-bind)
|
||||
`v-model` | [#](https://cn.vuejs.org/api/built-in-directives.html#v-model)
|
||||
`v-slot` | [#](https://cn.vuejs.org/api/built-in-directives.html#v-slot)
|
||||
`v-pre` | [#](https://cn.vuejs.org/api/built-in-directives.html#v-pre)
|
||||
`v-once` | [#](https://cn.vuejs.org/api/built-in-directives.html#v-once)
|
||||
`v-memo` | [#](https://cn.vuejs.org/api/built-in-directives.html#v-memo)
|
||||
`v-cloak` | [#](https://cn.vuejs.org/api/built-in-directives.html#v-cloak)
|
||||
`v-for` | 多次渲染元素或模板块 [#](https://cn.vuejs.org/api/built-in-directives.html#v-for)
|
||||
`v-on` | 绑定事件监听器 [#](https://cn.vuejs.org/api/built-in-directives.html#v-on)
|
||||
`v-bind` | 动态地绑定一个或多个属性 [#](https://cn.vuejs.org/api/built-in-directives.html#v-bind)
|
||||
`v-model` | 创建双向绑定 [#](https://cn.vuejs.org/api/built-in-directives.html#v-model)
|
||||
`v-slot` | 提供插槽或接收 props 的插槽 [#](https://cn.vuejs.org/api/built-in-directives.html#v-slot)
|
||||
`v-pre` | 跳过元素和它的子元素编译过程 [#](https://cn.vuejs.org/api/built-in-directives.html#v-pre)
|
||||
`v-once` | 只渲染元素和组件一次 [#](https://cn.vuejs.org/api/built-in-directives.html#v-once)
|
||||
`v-memo` _(3.2+)_ | 缓存一个模板的子树 [#](https://cn.vuejs.org/api/built-in-directives.html#v-memo)
|
||||
`v-cloak` | 保持在元素上直到实例结束编译 [#](https://cn.vuejs.org/api/built-in-directives.html#v-cloak)
|
||||
|
||||
### 内置内容 - 组件
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`<Transition>` | [#](https://cn.vuejs.org/api/built-in-components.html#transition)
|
||||
`<TransitionGroup>` | [#](https://cn.vuejs.org/api/built-in-components.html#transitiongroup)
|
||||
`<KeepAlive>` | [#](https://cn.vuejs.org/api/built-in-components.html#keepalive)
|
||||
`<Teleport>` | [#](https://cn.vuejs.org/api/built-in-components.html#teleport)
|
||||
`<Suspense>` | [#](https://cn.vuejs.org/api/built-in-components.html#suspense)
|
||||
`<Transition>` | 单个元素/组件的过渡效果 [#](https://cn.vuejs.org/api/built-in-components.html#transition)
|
||||
`<TransitionGroup>` | 多个元素/组件的过渡效果 [#](https://cn.vuejs.org/api/built-in-components.html#transitiongroup)
|
||||
`<KeepAlive>` | 缓存包裹在其中的动态切换组件 [#](https://cn.vuejs.org/api/built-in-components.html#keepalive)
|
||||
`<Teleport>` | 将其插槽内容渲染到 DOM 中的另一个位置 [#](https://cn.vuejs.org/api/built-in-components.html#teleport)
|
||||
`<Suspense>` _(Experimental)_ | 协调对组件树中嵌套的异步依赖的处理 [#](https://cn.vuejs.org/api/built-in-components.html#suspense)
|
||||
|
||||
### 内置内容 - 特殊 Attributes
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`key` | [#](https://cn.vuejs.org/api/built-in-special-attributes.html#key)
|
||||
`ref` | [#](https://cn.vuejs.org/api/built-in-special-attributes.html#ref)
|
||||
`is` | [#](https://cn.vuejs.org/api/built-in-special-attributes.html#is)
|
||||
`key` | 用在 Vue 的虚拟 DOM 算法 [#](https://cn.vuejs.org/api/built-in-special-attributes.html#key)
|
||||
`ref` | 元素或子组件注册引用信息 [#](https://cn.vuejs.org/api/built-in-special-attributes.html#ref)
|
||||
`is` | 绑定动态组件 [#](https://cn.vuejs.org/api/built-in-special-attributes.html#is)
|
||||
|
||||
### 内置内容 - 特殊元素
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`<component>` | [#](https://cn.vuejs.org/api/built-in-special-elements.html#component)
|
||||
`<slot>` | [#](https://cn.vuejs.org/api/built-in-special-elements.html#slot)
|
||||
`<component>` | 渲染一个“元组件”用于动态组件或元素 [#](https://cn.vuejs.org/api/built-in-special-elements.html#component)
|
||||
`<slot>` | 组件模板中的插槽内容出口 [#](https://cn.vuejs.org/api/built-in-special-elements.html#slot)
|
||||
|
||||
### 单文件组件 - 语法定义
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
@ -598,14 +681,14 @@ API 参考
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`h()` | [#](https://cn.vuejs.org/api/render-function.html#h)
|
||||
`mergeProps()` | [#](https://cn.vuejs.org/api/render-function.html#mergeprops)
|
||||
`cloneVNode()` | [#](https://cn.vuejs.org/api/render-function.html#clonevnode)
|
||||
`isVNode()` | [#](https://cn.vuejs.org/api/render-function.html#isvnode)
|
||||
`resolveComponent()` | [#](https://cn.vuejs.org/api/render-function.html#resolvecomponent)
|
||||
`resolveDirective()` | [#](https://cn.vuejs.org/api/render-function.html#resolvedirective)
|
||||
`withDirectives()` | [#](https://cn.vuejs.org/api/render-function.html#withdirectives)
|
||||
`withModifiers()` | [#](https://cn.vuejs.org/api/render-function.html#withmodifiers)
|
||||
`h()` | 创建虚拟 DOM 节点 [#](https://cn.vuejs.org/api/render-function.html#h)
|
||||
`mergeProps()` | 合并多个 props 对象 [#](https://cn.vuejs.org/api/render-function.html#mergeprops)
|
||||
`cloneVNode()` | 克隆一个 vnode [#](https://cn.vuejs.org/api/render-function.html#clonevnode)
|
||||
`isVNode()` | 判断一个值是否为 vnode 类型 [#](https://cn.vuejs.org/api/render-function.html#isvnode)
|
||||
`resolveComponent()` | 按名称手动解析已注册的组件 [#](https://cn.vuejs.org/api/render-function.html#resolvecomponent)
|
||||
`resolveDirective()` | 按名称手动解析已注册的指令 [#](https://cn.vuejs.org/api/render-function.html#resolvedirective)
|
||||
`withDirectives()` | 用于给 vnode 增加自定义指令 [#](https://cn.vuejs.org/api/render-function.html#withdirectives)
|
||||
`withModifiers()` | 用于向事件处理函数添加内置 `v-on 修饰符` [#](https://cn.vuejs.org/api/render-function.html#withmodifiers)
|
||||
|
||||
### 进阶 API - 服务端渲染
|
||||
|
||||
@ -623,17 +706,17 @@ API 参考
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`PropType<T>` | [#](https://cn.vuejs.org/api/utility-types.html#proptypet)
|
||||
`ComponentCustomProperties` | [#](https://cn.vuejs.org/api/utility-types.html#componentcustomproperties)
|
||||
`ComponentCustomOptions` | [#](https://cn.vuejs.org/api/utility-types.html#componentcustomoptions)
|
||||
`ComponentCustomProps` | [#](https://cn.vuejs.org/api/utility-types.html#componentcustomprops)
|
||||
`CSSProperties` | [#](https://cn.vuejs.org/api/utility-types.html#cssproperties)
|
||||
`PropType<T>` | 在用运行时 props 声明时给一个 prop 标注更复杂的类型定义 [#](https://cn.vuejs.org/api/utility-types.html#proptypet)
|
||||
`ComponentCustomProperties` | 增强组件实例类型以支持自定义全局属性 [#](https://cn.vuejs.org/api/utility-types.html#componentcustomproperties)
|
||||
`ComponentCustomOptions` | 扩展组件选项类型以支持自定义选项 [#](https://cn.vuejs.org/api/utility-types.html#componentcustomoptions)
|
||||
`ComponentCustomProps` | 扩展全局可用的 TSX props [#](https://cn.vuejs.org/api/utility-types.html#componentcustomprops)
|
||||
`CSSProperties` | 扩展在样式属性绑定上允许的值的类型 [#](https://cn.vuejs.org/api/utility-types.html#cssproperties)
|
||||
|
||||
### 进阶 API - 自定义渲染
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`createRenderer()` | [#](https://cn.vuejs.org/api/custom-renderer.html#create-renderer)
|
||||
`createRenderer()` | 创建一个自定义渲染器 [#](https://cn.vuejs.org/api/custom-renderer.html#create-renderer)
|
||||
|
||||
另见
|
||||
---
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@wcj/reference",
|
||||
"version": "1.19.0",
|
||||
"version": "1.21.0",
|
||||
"description": "为开发人员分享快速参考备忘单(主要是方便自己)。",
|
||||
"author": "jaywcjlove",
|
||||
"license": "MIT",
|
||||
|
3
scripts/assets/cocoapods.svg
Normal file
3
scripts/assets/cocoapods.svg
Normal file
@ -0,0 +1,3 @@
|
||||
<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="currentColor" height="1em" width="1em">
|
||||
<path d="M8.812 17.176c-2.968 0-4.956-2.308-4.956-5.176 0-2.705 1.776-5.176 4.91-5.176 2.407 0 3.856 1.445 4.207 3.357h3.95C16.479 6.427 13.51 3.42 8.718 3.42 3.131 3.42 0 7.523 0 12c0 4.57 3.295 8.58 8.766 8.58 4.58 0 7.549-2.822 8.18-6.272h-4.02c-.467 1.609-1.916 2.868-4.114 2.868zM24 12.068l-3.466 8.055-2.38-1.022 2.992-7.055-3.01-7.096 2.433-1.042Z"/>
|
||||
</svg>
|
After Width: | Height: | Size: 473 B |
2
scripts/assets/cs.svg
Normal file
2
scripts/assets/cs.svg
Normal file
@ -0,0 +1,2 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" width="1em" height="1em" viewBox="0 0 200 218">
|
||||
<path d="M100,0.44 L100,0.455333333 L199.666667,58.5993333 L199.666667,159.400667 L100,217.56 L0.333333333,159.400667 L0.333333333,58.5993333 L100,0.44 Z M82.0833333,55.333 C53.8740706,55.3333333 31,78.2074039 31,106.424 L31,111.576 C31.0041913,129.277326 40.1707165,145.7152 55.2277239,155.022373 C70.2847313,164.329546 89.0864906,165.17968 104.922,157.269333 L111.101333,154.202667 L104.232,140.479333 L98.068,143.546 C86.9899096,149.088667 73.8317911,148.500121 63.2927817,141.99055 C52.7537723,135.480978 46.336719,123.978635 46.3333333,111.591333 L46.3333333,106.439333 C46.3346881,94.0500894 52.7491422,82.5443897 63.2870103,76.0292762 C73.8248785,69.5141628 86.9843283,68.9181542 98.068,74.454 L104.232,77.536 L111.101333,63.828 L104.922,60.746 C98.0448161,57.3003013 90.4812112,55.4533442 82.7961467,55.3389754 L82.0833333,55.333 Z M138.333333,70.6666667 L123,70.6666667 L123,86 L107.666667,86 L107.666667,101.333333 L123,101.333333 L123,116.666667 L107.666667,116.666667 L107.666667,132 L123,132 L123,147.333333 L138.333333,147.333333 L138.333333,132 L153.666667,132 L153.666667,147.333333 L169,147.333333 L169,132 L184.333333,132 L184.333333,116.666667 L169,116.666667 L169,101.333333 L184.333333,101.333333 L184.333333,86 L169,86 L169,70.6666667 L153.666667,70.6666667 L153.666667,86 L138.333333,86 L138.333333,70.6666667 Z M153.666667,101.333333 L153.666667,116.666667 L138.333333,116.666667 L138.333333,101.333333 L153.666667,101.333333 Z"/></svg>
|
After Width: | Height: | Size: 1.5 KiB |
3
scripts/assets/dart.svg
Normal file
3
scripts/assets/dart.svg
Normal file
@ -0,0 +1,3 @@
|
||||
<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="currentColor" height="1em" width="1em">
|
||||
<path d="M4.105 4.105S9.158 1.58 11.684.316a3.079 3.079 0 0 1 1.481-.315c.766.047 1.677.788 1.677.788L24 9.948v9.789h-4.263V24H9.789l-9-9C.303 14.5 0 13.795 0 13.105c0-.319.18-.818.316-1.105l3.789-7.895zm.679.679v11.787c.002.543.021 1.024.498 1.508L10.204 23h8.533v-4.263L4.784 4.784zm12.055-.678c-.899-.896-1.809-1.78-2.74-2.643-.302-.267-.567-.468-1.07-.462-.37.014-.87.195-.87.195L6.341 4.105l10.498.001z"/>
|
||||
</svg>
|
After Width: | Height: | Size: 526 B |
2
scripts/assets/julia.svg
Normal file
2
scripts/assets/julia.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 7.3 KiB |
3
scripts/assets/latex.svg
Normal file
3
scripts/assets/latex.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 5.6 KiB |
3
scripts/assets/php.svg
Normal file
3
scripts/assets/php.svg
Normal file
@ -0,0 +1,3 @@
|
||||
<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="currentColor" height="1em" width="1em">
|
||||
<path d="M7.01 10.207h-.944l-.515 2.648h.838c.556 0 .97-.105 1.242-.314.272-.21.455-.559.55-1.049.092-.47.05-.802-.124-.995-.175-.193-.523-.29-1.047-.29zM12 5.688C5.373 5.688 0 8.514 0 12s5.373 6.313 12 6.313S24 15.486 24 12c0-3.486-5.373-6.312-12-6.312zm-3.26 7.451c-.261.25-.575.438-.917.551-.336.108-.765.164-1.285.164H5.357l-.327 1.681H3.652l1.23-6.326h2.65c.797 0 1.378.209 1.744.628.366.418.476 1.002.33 1.752a2.836 2.836 0 0 1-.305.847c-.143.255-.33.49-.561.703zm4.024.715.543-2.799c.063-.318.039-.536-.068-.651-.107-.116-.336-.174-.687-.174H11.46l-.704 3.625H9.388l1.23-6.327h1.367l-.327 1.682h1.218c.767 0 1.295.134 1.586.401s.378.7.263 1.299l-.572 2.944h-1.389zm7.597-2.265a2.782 2.782 0 0 1-.305.847c-.143.255-.33.49-.561.703a2.44 2.44 0 0 1-.917.551c-.336.108-.765.164-1.286.164h-1.18l-.327 1.682h-1.378l1.23-6.326h2.649c.797 0 1.378.209 1.744.628.366.417.477 1.001.331 1.751zm-2.595-1.382h-.943l-.516 2.648h.838c.557 0 .971-.105 1.242-.314.272-.21.455-.559.551-1.049.092-.47.049-.802-.125-.995s-.524-.29-1.047-.29z"/>
|
||||
</svg>
|
After Width: | Height: | Size: 1.1 KiB |
@ -10,6 +10,17 @@ body {
|
||||
'Segoe UI Emoji';
|
||||
}
|
||||
|
||||
::-webkit-scrollbar {
|
||||
background: transparent;
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb {
|
||||
background: var(--color-fg-muted);
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
[data-color-mode*='dark'] body .dark {
|
||||
display: none;
|
||||
}
|
||||
@ -162,14 +173,17 @@ menu {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
yel {
|
||||
color: var(--color-prettylights-syntax-variable);
|
||||
yel,
|
||||
yel code {
|
||||
color: var(--color-prettylights-syntax-variable) !important;
|
||||
}
|
||||
red {
|
||||
color: var(--color-danger-fg);
|
||||
red,
|
||||
red code {
|
||||
color: var(--color-danger-fg) !important;
|
||||
}
|
||||
pur {
|
||||
color: var(--color-prettylights-syntax-entity);
|
||||
pur,
|
||||
pur code {
|
||||
color: var(--color-prettylights-syntax-entity) !important;
|
||||
}
|
||||
|
||||
:is(.h3wrap-body, .wrap-body) p > code,
|
||||
@ -720,6 +734,16 @@ body:not(.home) .h2wrap-body > .wrap:hover .h3wrap > h3 a::after {
|
||||
background-color: var(--color-bg-subtle);
|
||||
}
|
||||
|
||||
.wrap-header.h3wrap > .wrap-body > p:only-child,
|
||||
.h3wrap-body p:only-child {
|
||||
background-color: transparent !important;
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
|
||||
.wrap-header.h3wrap > .wrap-body > p:only-child:before {
|
||||
background-color: transparent !important;
|
||||
}
|
||||
|
||||
.wrap-header.h3wrap > .wrap-body > p:first-child:before {
|
||||
background-color: var(--color-bg-subtle);
|
||||
color: rgb(30 41 59/0);
|
||||
|
@ -107,7 +107,7 @@ export function getTocsTree(arr = [], result = []) {
|
||||
{
|
||||
type: 'element',
|
||||
tagName: 'div',
|
||||
properties: { class: 'wrap-body' },
|
||||
properties: { class: ['wrap-body'] },
|
||||
children: [...header],
|
||||
},
|
||||
],
|
||||
@ -133,7 +133,12 @@ export function getTocsTree(arr = [], result = []) {
|
||||
children: [...resultChilds],
|
||||
});
|
||||
} else {
|
||||
panle.children[0].children[1].properties?.class.push(bodyClass);
|
||||
panle.children[0].children[1].children = panle.children[0].children[1].children.concat(resultChilds);
|
||||
if (panle.children[0].children[1].properties && bodyStyle) {
|
||||
const initStyle = panle.children[0].children[1].properties?.style || '';
|
||||
panle.children[0].children[1].properties.style = initStyle + bodyStyle;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user