From 56de10116041c36096ddf511d3b10901425469db Mon Sep 17 00:00:00 2001 From: saqqdy Date: Fri, 27 Oct 2023 19:38:18 +0800 Subject: [PATCH] Blob arrayBuffer base64 file blobUrl --- CHANGELOG.md | 14 ++ README-zh_CN.md | 14 +- README.md | 311 +++++++++++++++++++++++++++++++++++++ src/arrayBufferToBase64.ts | 11 ++ src/arrayBufferToBlob.ts | 11 ++ src/base64ToArrayBuffer.ts | 11 ++ src/base64ToBlob.ts | 11 ++ src/base64ToFile.ts | 11 ++ src/blobToArrayBuffer.ts | 11 ++ src/blobToBase64.ts | 11 ++ src/blobToUrl.ts | 11 ++ src/fileToBase64.ts | 11 ++ src/index.default.ts | 24 +++ src/index.mjs | 22 +++ src/index.ts | 13 ++ src/svgToBlob.ts | 11 ++ src/urlToBlob.ts | 11 ++ 17 files changed, 518 insertions(+), 1 deletion(-) create mode 100644 src/arrayBufferToBase64.ts create mode 100644 src/arrayBufferToBlob.ts create mode 100644 src/base64ToArrayBuffer.ts create mode 100644 src/base64ToBlob.ts create mode 100644 src/base64ToFile.ts create mode 100644 src/blobToArrayBuffer.ts create mode 100644 src/blobToBase64.ts create mode 100644 src/blobToUrl.ts create mode 100644 src/fileToBase64.ts create mode 100644 src/svgToBlob.ts create mode 100644 src/urlToBlob.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 402d99bb..d47d1b0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Change logs +## 2023.10.27 v5.13.0 + +1. new `arrayBufferToBase64` function, see: [arrayBufferToBase64](https://github.com/saqqdy/js-cool#arraybuffertobase64) +2. new `arrayBufferToBlob` function, see: [arrayBufferToBlob](https://github.com/saqqdy/js-cool#arraybuffertoblob) +3. new `base64ToArrayBuffer` function, see: [base64ToArrayBuffer](https://github.com/saqqdy/js-cool#base64toarraybuffer) +4. new `base64ToBlob` function, see: [base64ToBlob](https://github.com/saqqdy/js-cool#base64toblob) +5. new `base64ToFile` function, see: [base64ToFile](https://github.com/saqqdy/js-cool#base64tofile) +6. new `blobToArrayBuffer` function, see: [blobToArrayBuffer](https://github.com/saqqdy/js-cool#blobtoarraybuffer) +7. new `blobToBase64` function, see: [blobToBase64](https://github.com/saqqdy/js-cool#blobtobase64) +8. new `blobToUrl` function, see: [blobToUrl](https://github.com/saqqdy/js-cool#blobtourl) +9. new `fileToBase64` function, see: [fileToBase64](https://github.com/saqqdy/js-cool#filetobase64) +10. new `svgToBlob` function, see: [svgToBlob](https://github.com/saqqdy/js-cool#svgtoblob) +11. new `urlToBlob` function, see: [urlToBlob](https://github.com/saqqdy/js-cool#urltoblob) + ## 2023.10.09 v5.12.0 1. new `isEqual` function, see: [isEqual](https://github.com/saqqdy/js-cool#isequal) diff --git a/README-zh_CN.md b/README-zh_CN.md index 688e2d18..18c8e897 100755 --- a/README-zh_CN.md +++ b/README-zh_CN.md @@ -174,7 +174,19 @@ const functionList = { mountStyle, // 动态加载css样式 preloader, // 图片预加载 waiting, // 等待一段时间 - awaitTo // 替代try catch处理promise错误 + awaitTo, // 替代try catch处理promise错误 + // 二进制 + arrayBufferToBase64, // arrayBuffer转Base64 + arrayBufferToBlob, // arrayBuffer转Blob + base64ToArrayBuffer, // base64转ArrayBuffer + base64ToBlob, // base64转Blob + base64ToFile, // base64转File + blobToArrayBuffer, // blob转ArrayBuffer + blobToBase64, // blob转Base64 + blobToUrl, // blob转Url + fileToBase64, // file转Base64 + svgToBlob, // svg转Blob + urlToBlob // url转Blob } ``` diff --git a/README.md b/README.md index acb9e375..e5b970a6 100755 --- a/README.md +++ b/README.md @@ -141,6 +141,18 @@ Collection of common JavaScript / TypeScript utilities - [preloader](#preloader) - [waiting](#waiting) - [awaitTo](#awaitto) + - [Blob arrayBuffer base64 file blobUrl](#blob-arraybuffer-base64-file-bloburl) + - [arrayBufferToBase64](#arraybuffertobase64) + - [arrayBufferToBlob](#arraybuffertoblob) + - [base64ToArrayBuffer](#base64toarraybuffer) + - [base64ToBlob](#base64toblob) + - [base64ToFile](#base64tofile) + - [blobToArrayBuffer](#blobtoarraybuffer) + - [blobToBase64](#blobtobase64) + - [blobToUrl](#blobtourl) + - [fileToBase64](#filetobase64) + - [svgToBlob](#svgtoblob) + - [urlToBlob](#urltoblob) - [Support & Issues](#support--issues) - [License](#license) @@ -3572,6 +3584,305 @@ const [err, data] = await to([promise1, promise2]) declare function awaitTo(promise: Promise): Promise<[E, undefined] | [null, T]> ``` +### Blob arrayBuffer base64 file blobUrl + +#### arrayBufferToBase64 + +arrayBuffer转Base64 + +- Since: `5.13.0` + +- Arguments: + +| Parameters | Description | Type | Optional | Required | Default | +| ---------- | ----------- | -------- | -------- | -------- | ------- | +| source | source data | `String` | - | `false` | - | + +- Returns: `Object` + +- Example: + +```ts +arrayBufferToBase64() +// result +``` + +- Types: + +```ts +declare function arrayBufferToBase64(source: T): any +``` + +#### arrayBufferToBlob + +arrayBuffer转Blob + +- Since: `5.13.0` + +- Arguments: + +| Parameters | Description | Type | Optional | Required | Default | +| ---------- | ----------- | -------- | -------- | -------- | ------- | +| source | source data | `String` | - | `false` | - | + +- Returns: `Object` + +- Example: + +```ts +arrayBufferToBlob() +// result +``` + +- Types: + +```ts +declare function arrayBufferToBlob(source: T): any +``` + +#### base64ToArrayBuffer + +base64转ArrayBuffer + +- Since: `5.13.0` + +- Arguments: + +| Parameters | Description | Type | Optional | Required | Default | +| ---------- | ----------- | -------- | -------- | -------- | ------- | +| source | source data | `String` | - | `false` | - | + +- Returns: `Object` + +- Example: + +```ts +base64ToArrayBuffer() +// result +``` + +- Types: + +```ts +declare function base64ToArrayBuffer(source: T): any +``` + +#### base64ToBlob + +base64转Blob + +- Since: `5.13.0` + +- Arguments: + +| Parameters | Description | Type | Optional | Required | Default | +| ---------- | ----------- | -------- | -------- | -------- | ------- | +| source | source data | `String` | - | `false` | - | + +- Returns: `Object` + +- Example: + +```ts +base64ToBlob() +// result +``` + +- Types: + +```ts +declare function base64ToBlob(source: T): any +``` + +#### base64ToFile + +base64转File + +- Since: `5.13.0` + +- Arguments: + +| Parameters | Description | Type | Optional | Required | Default | +| ---------- | ----------- | -------- | -------- | -------- | ------- | +| source | source data | `String` | - | `false` | - | + +- Returns: `Object` + +- Example: + +```ts +base64ToFile() +// result +``` + +- Types: + +```ts +declare function base64ToFile(source: T): any +``` + +#### blobToArrayBuffer + +blob转ArrayBuffer + +- Since: `5.13.0` + +- Arguments: + +| Parameters | Description | Type | Optional | Required | Default | +| ---------- | ----------- | -------- | -------- | -------- | ------- | +| source | source data | `String` | - | `false` | - | + +- Returns: `Object` + +- Example: + +```ts +blobToArrayBuffer() +// result +``` + +- Types: + +```ts +declare function blobToArrayBuffer(source: T): any +``` + +#### blobToBase64 + +blob转Base64 + +- Since: `5.13.0` + +- Arguments: + +| Parameters | Description | Type | Optional | Required | Default | +| ---------- | ----------- | -------- | -------- | -------- | ------- | +| source | source data | `String` | - | `false` | - | + +- Returns: `Object` + +- Example: + +```ts +blobToBase64() +// result +``` + +- Types: + +```ts +declare function blobToBase64(source: T): any +``` + +#### blobToUrl + +blob转Url + +- Since: `5.13.0` + +- Arguments: + +| Parameters | Description | Type | Optional | Required | Default | +| ---------- | ----------- | -------- | -------- | -------- | ------- | +| source | source data | `String` | - | `false` | - | + +- Returns: `Object` + +- Example: + +```ts +blobToUrl() +// result +``` + +- Types: + +```ts +declare function blobToUrl(source: T): any +``` + +#### fileToBase64 + +file转Base64 + +- Since: `5.13.0` + +- Arguments: + +| Parameters | Description | Type | Optional | Required | Default | +| ---------- | ----------- | -------- | -------- | -------- | ------- | +| source | source data | `String` | - | `false` | - | + +- Returns: `Object` + +- Example: + +```ts +fileToBase64() +// result +``` + +- Types: + +```ts +declare function fileToBase64(source: T): any +``` + +#### svgToBlob + +svg转Blob + +- Since: `5.13.0` + +- Arguments: + +| Parameters | Description | Type | Optional | Required | Default | +| ---------- | ----------- | -------- | -------- | -------- | ------- | +| source | source data | `String` | - | `false` | - | + +- Returns: `Object` + +- Example: + +```ts +svgToBlob() +// result +``` + +- Types: + +```ts +declare function svgToBlob(source: T): any +``` + +#### urlToBlob + +url转Blob + +- Since: `5.13.0` + +- Arguments: + +| Parameters | Description | Type | Optional | Required | Default | +| ---------- | ----------- | -------- | -------- | -------- | ------- | +| source | source data | `String` | - | `false` | - | + +- Returns: `Object` + +- Example: + +```ts +urlToBlob() +// result +``` + +- Types: + +```ts +declare function urlToBlob(source: T): any +``` + ## Support & Issues Please open an issue [here](https://github.com/saqqdy/js-cool/issues). diff --git a/src/arrayBufferToBase64.ts b/src/arrayBufferToBase64.ts new file mode 100644 index 00000000..1622c048 --- /dev/null +++ b/src/arrayBufferToBase64.ts @@ -0,0 +1,11 @@ +/** + * String, number to base64 + * + * @param input - the string to be encoded + * @returns - the BASE64 encoding + */ +function arrayBufferToBase64(input: string) { + // +} + +export default arrayBufferToBase64 diff --git a/src/arrayBufferToBlob.ts b/src/arrayBufferToBlob.ts new file mode 100644 index 00000000..0898daab --- /dev/null +++ b/src/arrayBufferToBlob.ts @@ -0,0 +1,11 @@ +/** + * String, number to base64 + * + * @param input - the string to be encoded + * @returns - the BASE64 encoding + */ +function arrayBufferToBlob(input: string) { + // +} + +export default arrayBufferToBlob diff --git a/src/base64ToArrayBuffer.ts b/src/base64ToArrayBuffer.ts new file mode 100644 index 00000000..25149ba3 --- /dev/null +++ b/src/base64ToArrayBuffer.ts @@ -0,0 +1,11 @@ +/** + * String, number to base64 + * + * @param input - the string to be encoded + * @returns - the BASE64 encoding + */ +function base64ToArrayBuffer(input: string) { + // +} + +export default base64ToArrayBuffer diff --git a/src/base64ToBlob.ts b/src/base64ToBlob.ts new file mode 100644 index 00000000..dce90579 --- /dev/null +++ b/src/base64ToBlob.ts @@ -0,0 +1,11 @@ +/** + * String, number to base64 + * + * @param input - the string to be encoded + * @returns - the BASE64 encoding + */ +function base64ToBlob(input: string) { + // +} + +export default base64ToBlob diff --git a/src/base64ToFile.ts b/src/base64ToFile.ts new file mode 100644 index 00000000..40626d9b --- /dev/null +++ b/src/base64ToFile.ts @@ -0,0 +1,11 @@ +/** + * String, number to base64 + * + * @param input - the string to be encoded + * @returns - the BASE64 encoding + */ +function base64ToFile(input: string) { + // +} + +export default base64ToFile diff --git a/src/blobToArrayBuffer.ts b/src/blobToArrayBuffer.ts new file mode 100644 index 00000000..1c781199 --- /dev/null +++ b/src/blobToArrayBuffer.ts @@ -0,0 +1,11 @@ +/** + * String, number to base64 + * + * @param input - the string to be encoded + * @returns - the BASE64 encoding + */ +function blobToArrayBuffer(input: string) { + // +} + +export default blobToArrayBuffer diff --git a/src/blobToBase64.ts b/src/blobToBase64.ts new file mode 100644 index 00000000..d4bf1ea6 --- /dev/null +++ b/src/blobToBase64.ts @@ -0,0 +1,11 @@ +/** + * String, number to base64 + * + * @param input - the string to be encoded + * @returns - the BASE64 encoding + */ +function blobToBase64(input: string) { + // +} + +export default blobToBase64 diff --git a/src/blobToUrl.ts b/src/blobToUrl.ts new file mode 100644 index 00000000..0f58564b --- /dev/null +++ b/src/blobToUrl.ts @@ -0,0 +1,11 @@ +/** + * String, number to base64 + * + * @param input - the string to be encoded + * @returns - the BASE64 encoding + */ +function blobToUrl(input: string) { + // +} + +export default blobToUrl diff --git a/src/fileToBase64.ts b/src/fileToBase64.ts new file mode 100644 index 00000000..e53cd531 --- /dev/null +++ b/src/fileToBase64.ts @@ -0,0 +1,11 @@ +/** + * String, number to base64 + * + * @param input - the string to be encoded + * @returns - the BASE64 encoding + */ +function fileToBase64(input: string) { + // +} + +export default fileToBase64 diff --git a/src/index.default.ts b/src/index.default.ts index 01638c6d..d7ec9779 100644 --- a/src/index.default.ts +++ b/src/index.default.ts @@ -111,6 +111,19 @@ import preloader from './preloader' import waiting from './waiting' import awaitTo from './awaitTo' +// Blob arrayBuffer base64 file blobUrl +import arrayBufferToBase64 from './arrayBufferToBase64' +import arrayBufferToBlob from './arrayBufferToBlob' +import base64ToArrayBuffer from './base64ToArrayBuffer' +import base64ToBlob from './base64ToBlob' +import base64ToFile from './base64ToFile' +import blobToArrayBuffer from './blobToArrayBuffer' +import blobToBase64 from './blobToBase64' +import blobToUrl from './blobToUrl' +import fileToBase64 from './fileToBase64' +import svgToBlob from './svgToBlob' +import urlToBlob from './urlToBlob' + import { loadSource, mountCss, mountImg, mountJs, mountStyle } from './' export default { @@ -197,6 +210,17 @@ export default { promiseFactory, waiting, awaitTo, + arrayBufferToBase64, + arrayBufferToBlob, + base64ToArrayBuffer, + base64ToBlob, + base64ToFile, + blobToArrayBuffer, + blobToBase64, + blobToUrl, + fileToBase64, + svgToBlob, + urlToBlob, openUrl, copy, pattern, diff --git a/src/index.mjs b/src/index.mjs index f8d3880c..a4e36182 100644 --- a/src/index.mjs +++ b/src/index.mjs @@ -87,6 +87,17 @@ const { promiseFactory, waiting, awaitTo, + arrayBufferToBase64, + arrayBufferToBlob, + base64ToArrayBuffer, + base64ToBlob, + base64ToFile, + blobToArrayBuffer, + blobToBase64, + blobToUrl, + fileToBase64, + svgToBlob, + urlToBlob, openUrl, copy, pattern, @@ -195,6 +206,17 @@ export { promiseFactory, waiting, awaitTo, + arrayBufferToBase64, + arrayBufferToBlob, + base64ToArrayBuffer, + base64ToBlob, + base64ToFile, + blobToArrayBuffer, + blobToBase64, + blobToUrl, + fileToBase64, + svgToBlob, + urlToBlob, openUrl, copy, pattern, diff --git a/src/index.ts b/src/index.ts index 7d5fac38..0453012f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -140,5 +140,18 @@ export { default as preloader } from './preloader' export { default as waiting } from './waiting' export { default as awaitTo } from './awaitTo' +// Blob arrayBuffer base64 file blobUrl +export { default as arrayBufferToBase64 } from './arrayBufferToBase64' +export { default as arrayBufferToBlob } from './arrayBufferToBlob' +export { default as base64ToArrayBuffer } from './base64ToArrayBuffer' +export { default as base64ToBlob } from './base64ToBlob' +export { default as base64ToFile } from './base64ToFile' +export { default as blobToArrayBuffer } from './blobToArrayBuffer' +export { default as blobToBase64 } from './blobToBase64' +export { default as blobToUrl } from './blobToUrl' +export { default as fileToBase64 } from './fileToBase64' +export { default as svgToBlob } from './svgToBlob' +export { default as urlToBlob } from './urlToBlob' + export { default } from './index.default' export const version = '__VERSION__' as string diff --git a/src/svgToBlob.ts b/src/svgToBlob.ts new file mode 100644 index 00000000..720b23b4 --- /dev/null +++ b/src/svgToBlob.ts @@ -0,0 +1,11 @@ +/** + * String, number to base64 + * + * @param input - the string to be encoded + * @returns - the BASE64 encoding + */ +function svgToBlob(input: string) { + // +} + +export default svgToBlob diff --git a/src/urlToBlob.ts b/src/urlToBlob.ts new file mode 100644 index 00000000..ec8b54f3 --- /dev/null +++ b/src/urlToBlob.ts @@ -0,0 +1,11 @@ +/** + * String, number to base64 + * + * @param input - the string to be encoded + * @returns - the BASE64 encoding + */ +function urlToBlob(input: string) { + // +} + +export default urlToBlob