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

docs: add file docs #19

Merged
merged 3 commits into from
Nov 1, 2024
Merged
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
9 changes: 9 additions & 0 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
collectionItems,
mathItems,
elementItems,
fileItems,
} from './items'

function withI18n(items: { link: string; text: string }[], locale: 'zh') {
Expand Down Expand Up @@ -72,6 +73,10 @@ export default defineConfig({
text: '元素',
items: withI18n(elementItems, 'zh'),
},
{
text: '文件',
items: withI18n(fileItems, 'zh'),
},
],

docFooter: {
Expand Down Expand Up @@ -130,6 +135,10 @@ export default defineConfig({
text: 'Element',
items: elementItems,
},
{
text: 'File',
items: fileItems,
},
],

socialLinks: [{ icon: 'github', link: 'https://github.com/varletjs/rattail' }],
Expand Down
5 changes: 5 additions & 0 deletions docs/.vitepress/items/file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const fileItems = [
{ text: 'toDataURL', link: '/file/to-data-url' },
{ text: 'toText', link: '/file/to-text' },
{ text: 'toArrayBuffer', link: '/file/to-array-buffer' },
]
1 change: 1 addition & 0 deletions docs/.vitepress/items/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export * from './collection'
export * from './function'
export * from './math'
export * from './element'
export * from './file'
26 changes: 26 additions & 0 deletions docs/file/to-array-buffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# toArrayBuffer

Converts a `File` object to an `ArrayBuffer`.

### Usage

```ts
import { toArrayBuffer } from 'rattail'

const file = new File(['Hello, world!'], 'hello.txt', { type: 'text/plain' })
toArrayBuffer(file).then((arrayBuffer) => {
console.log(arrayBuffer)
})
```

### Arguments

| Arg | Type | Defaults |
| ------ | ------ | -------- |
| `file` | `File` | |

### Return

| Type |
| ---------------------- |
| `Promise<ArrayBuffer>` |
26 changes: 26 additions & 0 deletions docs/file/to-data-url.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# toDataURL

Converts a `File` object to a Data URL string.

### Usage

```ts
import { toDataURL } from 'rattail'

const file = new File(['Hello, world!'], 'hello.txt', { type: 'text/plain' })
toDataURL(file).then((dataUrl) => {
console.log(dataUrl)
})
```

### Arguments

| Arg | Type | Defaults |
| ------ | ------ | -------- |
| `file` | `File` | |

### Return

| Type |
| ----------------- |
| `Promise<string>` |
26 changes: 26 additions & 0 deletions docs/file/to-text.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# toText

Converts a `File` object to a text string.

### Usage

```ts
import { toText } from 'rattail'

const file = new File(['Hello, world!'], 'hello.txt', { type: 'text/plain' })
toText(file).then((text) => {
console.log(text)
})
```

### Arguments

| Arg | Type | Defaults |
| ------ | ------ | -------- |
| `file` | `File` | |

### Return

| Type |
| ----------------- |
| `Promise<string>` |
26 changes: 26 additions & 0 deletions docs/zh/file/to-array-buffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# toArrayBuffer

将 `File` 对象转换为 `ArrayBuffer`。

### 用法

```ts
import { toArrayBuffer } from 'rattail'

const file = new File(['Hello, world!'], 'hello.txt', { type: 'text/plain' })
toArrayBuffer(file).then((arrayBuffer) => {
console.log(arrayBuffer)
})
```

### 参数

| 参数 | 类型 | 默认值 |
| ------ | ------ | ------ |
| `file` | `File` | |

### 返回值

| 类型 |
| ---------------------- |
| `Promise<ArrayBuffer>` |
26 changes: 26 additions & 0 deletions docs/zh/file/to-data-url.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# toDataURL

将 `File` 对象转换为 Data URL 字符串。

### 用法

```ts
import { toDataURL } from 'rattail'

const file = new File(['Hello, world!'], 'hello.txt', { type: 'text/plain' })
toDataURL(file).then((dataUrl) => {
console.log(dataUrl)
})
```

### 参数

| 参数 | 类型 | 默认值 |
| ------ | ------ | ------ |
| `file` | `File` | |

### 返回值

| 类型 |
| ----------------- |
| `Promise<string>` |
26 changes: 26 additions & 0 deletions docs/zh/file/to-text.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# toText

将 `File` 对象转换为文本字符串。

### 用法

```ts
import { toText } from 'rattail'

const file = new File(['Hello, world!'], 'hello.txt', { type: 'text/plain' })
toText(file).then((text) => {
console.log(text)
})
```

### 参数

| 参数 | 类型 | 默认值 |
| ------ | ------ | ------ |
| `file` | `File` | |

### 返回值

| 类型 |
| ----------------- |
| `Promise<string>` |
Loading