Compare commits

...

44 Commits

Author SHA1 Message Date
1fda256237 released v1.21.0 2022-11-15 21:23:33 +08:00
f9ca460565 doc: update cron.md 2022-11-15 21:22:45 +08:00
8e265becb5 feat: add cocoapods.md cheatsheet. 2022-11-15 21:12:49 +08:00
e1639d0ce0 doc: update cargo.md #82 2022-11-15 19:59:48 +08:00
f5f05aacf5 doc: modify README.md. 2022-11-15 11:54:33 +00:00
90c80e720e doc: modify CONTRIBUTING.md. 2022-11-15 11:54:32 +00:00
823b3163d4 doc: add cargo test in cargo.md (#82) 2022-11-15 19:53:36 +08:00
fe562e5fb1 doc: modify vue.md. (#81) 2022-11-15 19:00:56 +08:00
85c4149e1c doc: update golang.md #78 2022-11-15 18:12:59 +08:00
e849f19712 doc: update java.md #80 2022-11-15 15:02:37 +08:00
71e5470efd doc: modify README.md. 2022-11-15 06:52:02 +00:00
38d79cd2a0 doc: modify CONTRIBUTING.md. 2022-11-15 06:52:01 +00:00
0e0eb9c628 doc: Update java.md (#80) 2022-11-15 14:50:57 +08:00
7b46142372 doc: update es6.md, add import assertions (#79)
* feat: add import assertions

* update
2022-11-15 14:28:54 +08:00
41b42c17b7 doc: modify README.md. 2022-11-15 05:44:59 +00:00
cfb0b98673 doc: modify CONTRIBUTING.md. 2022-11-15 05:44:58 +00:00
8a9d9de14b feat: update es6.md about private class (#76)
* feat: update es6 about private class

* update
2022-11-15 13:44:01 +08:00
c2cb9fa3d7 doc: modify README.md. 2022-11-15 05:14:59 +00:00
11edef0d1b doc: modify CONTRIBUTING.md. 2022-11-15 05:14:58 +00:00
b13ca7ee0a feat: update vue.md (#75) 2022-11-15 13:14:06 +08:00
5f6029a051 fix: fix typo content in markdown.md (#74) 2022-11-15 11:34:07 +08:00
8592dff419 doc: modify README.md. 2022-11-15 01:48:16 +00:00
bb817cbb40 doc: modify CONTRIBUTING.md. 2022-11-15 01:48:15 +00:00
0bc31c68c3 doc: update rust.md #70 2022-11-15 09:46:55 +08:00
aab4d3bcff doc: modify README.md. 2022-11-15 00:54:30 +00:00
a3ddc58b0a doc: modify CONTRIBUTING.md. 2022-11-15 00:54:30 +00:00
c4398d5220 doc: update typescript.md (#69)
* feat: update typescript

* update
2022-11-15 08:53:28 +08:00
ada64ac643 doc: about rust content (#70) 2022-11-15 08:52:37 +08:00
84876edb2e doc: modify README.md. 2022-11-15 00:52:20 +00:00
0c8dddf8e7 doc: modify CONTRIBUTING.md. 2022-11-15 00:52:20 +00:00
edaf531b50 doc: Update javascript.md (#72)
decodeURI(enc); encodeURI(uri); 注释修正
2022-11-15 08:51:15 +08:00
2200972ce7 feat: add cs.md #66 2022-11-14 23:25:43 +08:00
aaa0f1f523 doc: modify README.md. 2022-11-14 13:58:57 +00:00
465cdc7bc1 doc: modify CONTRIBUTING.md. 2022-11-14 13:58:57 +00:00
c97f6a7bca feat: add julia.md #59 2022-11-14 21:57:57 +08:00
8f980a92c1 doc: update latex.md #47 2022-11-14 21:57:57 +08:00
4f0198877b doc: update npm.md #65 2022-11-14 21:57:57 +08:00
e0ccae5659 doc: update css.md. 2022-11-14 21:57:57 +08:00
c40b5ecb85 style: optimize scrollbars style (#68) 2022-11-14 18:23:02 +08:00
9c3ad5a300 doc: add npx document in npm.md #65 2022-11-14 18:21:04 +08:00
3bac78a4d0 doc: modify CONTRIBUTING.md. 2022-11-13 15:33:10 +00:00
9db2ce1974 chore: update workflows config. 2022-11-13 23:32:13 +08:00
345bb9013d chore: add .gitattributes file. 2022-11-13 23:31:02 +08:00
4eedb2bcbe doc: modify CONTRIBUTING.md. 2022-11-13 15:27:22 +00:00
25 changed files with 1948 additions and 239 deletions

1
.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
*.md linguist-detectable=true

View File

@ -29,7 +29,7 @@ jobs:
with:
path: CONTRIBUTING.md
body: |
${{steps.contributors.outputs.htmlTable}}
${{steps.contributors.outputs.htmlList}}
- name: Modify README.md
uses: jaywcjlove/github-action-modify-file-content@main

View File

@ -99,15 +99,30 @@ npm run start # 监听 md 文件编译输出 HTML
<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>
@ -122,6 +137,9 @@ npm run start # 监听 md 文件编译输出 HTML
</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) 自动生成贡献者图片。

View File

@ -21,6 +21,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=👆看看还缺点儿什么?-->
[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-->
@ -32,6 +33,7 @@ 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-->
@ -41,6 +43,7 @@ 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(1 117 143/var(\-\-bg\-opacity));&class=tag&data-lang=SQL-->
@ -106,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));-->
@ -166,15 +170,30 @@ Quick Reference
<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>
@ -189,6 +208,9 @@ Quick Reference
</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) 自动生成

View File

@ -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
View 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)*

View File

@ -16,8 +16,8 @@ Min Hour Day Mon Weekday
-------
```
* * * * * 要执行的命令
```bash
* * * * * <要执行的命令>
┬ ┬ ┬ ┬ ┬
│ │ │ │ └─ 星期几 (0=周日 .. 6=星期六)
│ │ │ └────── 月 (1..12)
@ -30,11 +30,12 @@ Min Hour Day Mon Weekday
| 字段 | 范围 | 特殊字符 |
|--------------|--------|--------------------|
| 分钟 Minute | 0 - 59 | , - * / |
| 小时 Hour | 0 - 23 | , - * / |
| 月份中的某天 | 1 - 31 | , - * ? / L W |
| 月 Month | 1 - 12 | , - * / |
| 星期几 | 0 - 6 | , - * ? / L # |
| 分钟 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 | 19702099 | <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,9 +90,9 @@ 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 表达式中的 `月份中的某天``星期几`

200
docs/cs.md Normal file
View 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-->

View File

@ -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 字体
------

View File

@ -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
----------

View File

@ -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-->
另见
--------

View File

@ -783,6 +783,20 @@ try {
}
```
### util工具类
- `ArrayDeque` 提供 resizable-array 并实现 Deque 接
- `Arrays` 包含一个静态工厂,允许将数组视为列表
- `Collections` 包含对集合进行操作或返回集合的静态方法
- `Date` 表示特定的时间瞬间,精度为毫秒
- `Dictionary` 是任何类的抽象父类,例如 Hashtable它将键映射到值
- `EnumMap` 一个专门用于枚举键的 Map 实现
- `EnumSet` 一个专门用于枚举键的 Set 实现
- `Formatter` 提供对布局对齐和对齐、数字、字符串和日期/时间数据的常用格式以及特定于语言环境的输出的支持
- `Random` 实例用于生成伪随机数流
- `UUID` 表示一个不可变的通用唯一标识符
- `Vector` 实现了一个可增长的对象数组
另见
---

View File

@ -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
View 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/)

View File

@ -117,6 +117,7 @@ Environments
c & d
\end{matrix}
```
<!--rehype:style=flex:1;-->
```LaTeX
\begin{matrix}
@ -124,6 +125,7 @@ Environments
c & d
\end{matrix}
```
<!--rehype:style=flex:1;-->
### Environments 2
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
@ -134,6 +136,7 @@ Environments
c & d
\end{array}
```
<!--rehype:style=flex:1;-->
```LaTeX
\begin{array}{cc}
@ -151,6 +154,7 @@ Environments
c & d
\end{pmatrix}
```
<!--rehype:style=flex:1;-->
```LaTeX
\begin{pmatrix}
@ -158,6 +162,7 @@ Environments
c & d
\end{pmatrix}
```
<!--rehype:style=flex:1;-->
### Environments 4
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
@ -185,6 +190,7 @@ Environments
c & d
\end{vmatrix}
```
<!--rehype:style=flex:1;-->
```LaTeX
\begin{vmatrix}
@ -192,6 +198,7 @@ Environments
c & d
\end{vmatrix}
```
<!--rehype:style=flex:1;-->
### Environments 6
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
@ -202,6 +209,7 @@ Environments
c & d
\end{Vmatrix}
```
<!--rehype:style=flex:1;-->
```LaTeX
\begin{Vmatrix}
@ -209,6 +217,7 @@ Environments
c & d
\end{Vmatrix}
```
<!--rehype:style=flex:1;-->
### Environments 7
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
@ -239,6 +248,7 @@ Environments
g & h & i
\end{array}
```
<!--rehype:style=flex:1;-->
```LaTeX
\def\arraystretch{1.5}
@ -293,6 +303,7 @@ x = \begin{cases}
c & d
\end{smallmatrix}
```
<!--rehype:style=flex:1;-->
```LaTeX
\begin{smallmatrix}
@ -311,6 +322,7 @@ x = \begin{cases}
0<j<n
\end{subarray}}
```
<!--rehype:style=flex:1;-->
```LaTeX
\sum_{
@ -320,7 +332,7 @@ x = \begin{cases}
\end{subarray}}
```
### Environments 12
### Environments 13
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
```KaTeX
@ -340,7 +352,7 @@ x = \begin{cases}
\end{equation}
```
### Environments 12
### Environments 14
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
```KaTeX
@ -358,7 +370,7 @@ x = \begin{cases}
\end{align}
```
### Environments 12
### Environments 15
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
```KaTeX
@ -376,7 +388,7 @@ x = \begin{cases}
\end{gather}
```
### Environments 12
### Environments 16
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
```KaTeX
@ -394,7 +406,7 @@ x = \begin{cases}
\end{alignat}
```
### Environments 12
### Environments 17
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
```KaTeX

View File

@ -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>
```
另见

View File

@ -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)_

View File

@ -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
@ -477,6 +506,7 @@ fn main(){
};
}
```
<!--rehype:className=wrap-text -->
### 枚举的变体
@ -491,6 +521,7 @@ fn main() {
let loopback = IpAddrKind::V6(String::from("::1"));
}
```
<!--rehype:className=wrap-text -->
----
@ -508,6 +539,7 @@ fn main(){
let c = Message::ChangeColor(10, 20, 30);
}
```
<!--rehype:className=wrap-text -->
### 模式匹配结构体
@ -534,6 +566,7 @@ fn main() {
subject_grade(Subject::Math(Grade::A));
}
```
<!--rehype:className=wrap-text -->
Rust 运算符
-----------
@ -756,6 +789,7 @@ enum Grade {
F,
}
```
<!--rehype:className=wrap-text -->
#### `matches!` 宏
@ -765,6 +799,7 @@ enum Grade {
assert!(matches!('x' ',A'..='Z' | 'a'..='z'));
assert!(matches!(Some(101), Some(x) if x > 100));
```
<!--rehype:className=wrap-text -->
### if let 匹配
@ -777,6 +812,7 @@ match Some(x) {
_ => ()
}
```
<!--rehype:className=wrap-text -->
使用 `if let`
@ -808,6 +844,7 @@ while let Some(top) = stack.pop() {
```rust
for (i, v) in collection.iter().enumerate(){}
```
<!--rehype:className=wrap-text -->
#### let
@ -846,6 +883,7 @@ match origin {
Point { x, .. } => println!("x is {}", x),
}
```
<!--rehype:className=wrap-text -->
#### 使用 `_` 忽略部分参数
@ -858,6 +896,7 @@ match hello {
},
}
```
<!--rehype:className=wrap-text -->
### 匹配命名变量
@ -884,6 +923,7 @@ match grade {
_ => println!("Come on"),
}
```
<!--rehype:className=wrap-text -->
----
@ -899,6 +939,7 @@ fn main(){
println!("{:?}", p);
}
```
<!--rehype:className=wrap-text -->
----
@ -923,6 +964,7 @@ match x {
_ => println!("No match"),
}// y = 2
```
<!--rehype:className=wrap-text -->
Rust 函数
--------
@ -981,9 +1023,108 @@ fn dead_end() -> ! {
panic!("panic!!!!!");
}
```
<!--rehype:className=wrap-text -->
惯用转换
-----
### &str -> String
```rust
String::from("str");
"str".to_string();
"str".to_owned();
```
### &str -> &[u8]
```rust
"str".as_bytes();
```
或者你也可以使用 `b""`
```rust
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();
```
杂项
-----

View File

@ -1268,8 +1268,24 @@ 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 的键
<!--rehype:wrap-class=row-span-2-->
```ts
interface Point {

View File

@ -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)
另见
---

View File

@ -1,6 +1,6 @@
{
"name": "@wcj/reference",
"version": "1.20.0",
"version": "1.21.0",
"description": "为开发人员分享快速参考备忘单(主要是方便自己)。",
"author": "jaywcjlove",
"license": "MIT",

View 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
View 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

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

View File

@ -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;
}
@ -723,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);