Skip to content

Commit

Permalink
docs: add file docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Aybrea committed Nov 1, 2024
1 parent a0dc915 commit 4e654dc
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 0 deletions.
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>` |

0 comments on commit 4e654dc

Please sign in to comment.