diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index e86b4ab..dff0a85 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -8,6 +8,7 @@ import { collectionItems, mathItems, elementItems, + fileItems, } from './items' function withI18n(items: { link: string; text: string }[], locale: 'zh') { @@ -72,6 +73,10 @@ export default defineConfig({ text: '元素', items: withI18n(elementItems, 'zh'), }, + { + text: '文件', + items: withI18n(fileItems, 'zh'), + }, ], docFooter: { @@ -130,6 +135,10 @@ export default defineConfig({ text: 'Element', items: elementItems, }, + { + text: 'File', + items: fileItems, + }, ], socialLinks: [{ icon: 'github', link: 'https://github.com/varletjs/rattail' }], diff --git a/docs/.vitepress/items/file.ts b/docs/.vitepress/items/file.ts new file mode 100644 index 0000000..e0f043d --- /dev/null +++ b/docs/.vitepress/items/file.ts @@ -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' }, +] diff --git a/docs/.vitepress/items/index.ts b/docs/.vitepress/items/index.ts index 702ac4c..02268e5 100644 --- a/docs/.vitepress/items/index.ts +++ b/docs/.vitepress/items/index.ts @@ -6,3 +6,4 @@ export * from './collection' export * from './function' export * from './math' export * from './element' +export * from './file' diff --git a/docs/file/to-array-buffer.md b/docs/file/to-array-buffer.md new file mode 100644 index 0000000..5dc723c --- /dev/null +++ b/docs/file/to-array-buffer.md @@ -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` | diff --git a/docs/file/to-data-url.md b/docs/file/to-data-url.md new file mode 100644 index 0000000..04219f6 --- /dev/null +++ b/docs/file/to-data-url.md @@ -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` | diff --git a/docs/file/to-text.md b/docs/file/to-text.md new file mode 100644 index 0000000..3ea7943 --- /dev/null +++ b/docs/file/to-text.md @@ -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` | diff --git a/docs/zh/file/to-array-buffer.md b/docs/zh/file/to-array-buffer.md new file mode 100644 index 0000000..849edad --- /dev/null +++ b/docs/zh/file/to-array-buffer.md @@ -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` | diff --git a/docs/zh/file/to-data-url.md b/docs/zh/file/to-data-url.md new file mode 100644 index 0000000..c9ac4b9 --- /dev/null +++ b/docs/zh/file/to-data-url.md @@ -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` | diff --git a/docs/zh/file/to-text.md b/docs/zh/file/to-text.md new file mode 100644 index 0000000..18db8eb --- /dev/null +++ b/docs/zh/file/to-text.md @@ -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` |