Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chinese document translation. #396

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 13 additions & 33 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,20 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'prettier'],
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react-hooks/recommended",
],
ignorePatterns: ["dist", ".eslintrc.cjs"],
parser: "@typescript-eslint/parser",
plugins: ["react-refresh"],
rules: {
'@typescript-eslint/ban-types': [
'error',
{
types: { '{}': false },
extendDefaults: true,
},
"react-refresh/only-export-components": [
"warn",
{ allowConstantExport: true },
],
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/member-delimiter-style': [
'error',
{
singleline: { delimiter: 'semi' },
multiline: { delimiter: 'none' },
},
],
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-unused-vars': [
'warn',
{
argsIgnorePattern: '^_',
},
],
'@typescript-eslint/no-use-before-define': 'off',
'no-constant-condition': 'off',
'no-inner-declarations': 'off',
'prettier/prettier': 'error',
"@typescript-eslint/no-unused-vars": "off",
"no-unused-vars": "off",
},
}
};
9 changes: 0 additions & 9 deletions .github/dependabot.yml

This file was deleted.

3 changes: 0 additions & 3 deletions .github/pr-labeler.yml

This file was deleted.

18 changes: 0 additions & 18 deletions .github/release-drafter.yml

This file was deleted.

13 changes: 0 additions & 13 deletions .github/workflows/automerge.yml

This file was deleted.

15 changes: 0 additions & 15 deletions .github/workflows/docs.yml

This file was deleted.

12 changes: 0 additions & 12 deletions .github/workflows/pr-labeler.yml

This file was deleted.

16 changes: 0 additions & 16 deletions .github/workflows/release-drafter.yml

This file was deleted.

25 changes: 0 additions & 25 deletions .github/workflows/tests.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ dist-test
.idea
*.d.ts
venv
site
5 changes: 1 addition & 4 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"semi": false,
"singleQuote": true,
"trailingComma": "es5",
"proseWrap": "always"

}
90 changes: 40 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,38 @@
# optics-ts

[![Build](https://github.com/akheron/optics-ts/workflows/tests/badge.svg)](https://github.com/akheron/optics-ts/actions/workflows/tests.yml)
[![构建](https://github.com/akheron/optics-ts/workflows/tests/badge.svg)](https://github.com/akheron/optics-ts/actions/workflows/tests.yml)

`optics-ts` provides type-safe, ergonomic, polymorphic optics for TypeScript:
`optics-ts`为TypeScript提供类型安全、人性化、多态的光学特性:

- **Optics** allow you to read or modify values from deeply nested data
structures, while keeping all data immutable.
- **Ergonomic**: Optics are composed with method chaining, making it easy and
fun!
- **Polymorphic**: When writing through the optics, you can change the data
types in the nested structure.
- **Type-safe**: The compiler will type check all operations you do. No `any`,
ever.
- **光学特性**允许你从深层嵌套的数据结构中读取或修改值,同时保持所有数据的不变性。
- **人性化**:光学特性通过方法链进行组合,使其易用且有趣!
- **多态**:通过光学特性写入时,你可以改变嵌套结构中的数据类型。
- **类型安全**:编译器将对你执行的所有操作进行类型检查。永远不会有 `any`。

➡ [Documentation](https://akheron.github.io/optics-ts) ⬅
➡ [官方文档:https://akheron.github.io/optics-ts](https://akheron.github.io/optics-ts) ⬅
➡ [中文文档:https://ouweiya.github.io/optics-ts-zh](https://ouweiya.github.io/optics-ts-zh) ⬅

## Features
## 特性

`optics-ts` supports lenses, prisms, traversals, removing items from containers,
and much more!
`optics-ts`支持镜头、棱镜、遍历、从容器中移除项目,等等!

Since optics-ts v2.2.0, there are two syntaxes for defining optics: method
chaining (the default) and standalone optics (experimental). See
[the docs](https://akheron.github.io/optics-ts) for more info!
自 optics-ts v2.2.0起,定义光学特性有两种语法:方法链(默认)和独立光学特性(实验性)。查看[文档](https://ouweiya.github.io/optics-ts-zh)获取更多信息!

## Getting started
## 入门

Installation:
安装:

```
```bash
npm install optics-ts
```

or
或者

```
```bash
yarn add optics-ts
```

Here's a simple example demonstrating how lenses can be used to drill into a
nested data structure:
这是一个简单的示例,演示了如何使用镜头深入到嵌套的数据结构中:

```typescript
import * as O from 'optics-ts'
Expand All @@ -52,10 +45,10 @@ type Book = {
}
}

// Create a lens that focuses on author.name
// 创建一个聚焦于 author.name 的镜头
const optic = O.optic_<Book>().prop('author').prop('name')

// This is the input data
// 这是输入数据
const input: Book = {
title: "The Hitchhiker's Guide to the Galaxy",
isbn: '978-0345391803',
Expand All @@ -64,11 +57,11 @@ const input: Book = {
},
}

// Read through the optic
// 通过光学特性读取
O.get(optic)(input)
// "Douglas Adams"

// Write through the optic
// 通过光学特性写入
O.set(optic)('Arthur Dent')(input)
// {
// title: "The Hitchhiker’s Guide to the Galaxy"
Expand All @@ -78,7 +71,7 @@ O.set(optic)('Arthur Dent')(input)
// }
// }

// Update the existing value through the optic, while also changing the data type
// 通过光学特性更新现有值,同时改变数据类型
O.modify(optic)((str) => str.length + 29)(input)
// {
// title: "The Hitchhiker’s Guide to the Galaxy"
Expand All @@ -89,61 +82,58 @@ O.modify(optic)((str) => str.length + 29)(input)
// }
```

Another example that converts all words longer than 5 characters to upper case:
另一个示例,将所有长度大于5个字符的单词转换为大写:

```typescript
import * as O from 'optics-ts/standalone'

const optic = O.optic<string>().words().when(s => s.length >= 5)

const input = 'This is a string with some shorter and some longer words'
O.modify(optic)((s) => s.toUpperCase()(input)
O.modify(optic)((s) => s.toUpperCase())(input)
// "This is a STRING with some SHORTER and some LONGER WORDS"
```

See the [documentation](https://akheron.github.io/optics-ts) for a tutorial and
a detailed reference of all supported optics.
查看[文档](https://ouweiya.github.io/optics-ts-zh)获取教程和所有支持的光学特性的详细参考。

## Development
## 开发

Run `yarn` to install dependencies.
运行 `yarn` 安装依赖。

### Running the test suite
### 运行测试套件

Run `yarn test`.
运行 `yarn test`

For compiling and running the tests when files change, run these commands in
separate terminals:
为了在文件更改时编译和运行测试,分别在不同的终端运行以下命令:

```
```bash
yarn build:test --watch
yarn jest dist-test/ --watchAll
```

### Documentation
### 文档

You need Python 3 to build the docs.
你需要Python 3来构建文档。

```
```bash
python3 -m venv venv
./venv/bin/pip install mkdocs-material
```

Run a live reloading server for the documentation:
运行一个实时重载的文档服务器:

```
```bash
./venv/bin/mkdocs serve
```

Open http://localhost:8000/ in the browser.
在浏览器中打开 http://localhost:8000/

### Releasing
### 发布

```
```bash
$ yarn version --new-version <major|minor|patch>
$ yarn publish
$ git push origin main --tags
```

Open https://github.com/akheron/optics-ts/releases, edit the draft release,
select the newest version tag, adjust the description as needed.
打开 https://github.com/akheron/optics-ts/releases ,编辑草稿发布,选择最新的版本标签,根据需要调整描述。
23 changes: 23 additions & 0 deletions addAnchorsToHeadings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { readFileSync, writeFileSync } from "node:fs";
import { globSync } from "glob";

// 使用 glob 匹配所有的 .md 和 .mdx 文件
const files = globSync("./docs/**/*.{md,mdx}");

files.forEach((file) => {
const data = readFileSync(file, "utf8");

const updatedData = data.replace(
/^(#{1,6}) (.*?)( \{#.*?\})?$/gm,
(match, p1, p2, p3) => {
// 如果标题已经包含自定义锚点,不作任何操作
if (p3) return match;

const id = p2.toLowerCase().replace(/\s+/g, "-");
return `${p1} ${p2} {#${id}}`;
},
);

// 将更新后的数据写回文件
writeFileSync(file, updatedData);
});
Loading