From 616f3692b030d4c36642fb2387d3edb9a0ee663f Mon Sep 17 00:00:00 2001 From: tangshutong Date: Fri, 12 Dec 2025 10:29:29 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E6=B7=BB=E5=8A=A0=E8=BF=81=E7=A7=BB?= =?UTF-8?q?=E5=A3=B0=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: tangshutong --- README.md | 20 +- doc/en.md | 545 +++++++++++++++++++++++++++++++++++++++++++++++ doc/zh-cn.md | 592 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1147 insertions(+), 10 deletions(-) create mode 100644 doc/en.md create mode 100644 doc/zh-cn.md diff --git a/README.md b/README.md index 9aaaf4f..ba8e3a1 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ -# @react-native-oh-tpl/react-native-quick-base64 +# 迁移声明 -This project is based on [react-native-quick-base64](https://github.com/craftzdog/react-native-quick-base64) +- 本仓库已迁移至 GitCode:[OpenHarmony-SIG/rntpc_react-native-quick-base64](https://gitcode.com/openharmony-sig/rntpc_react-native-quick-base64)。 +- 包名已更改为 `@react-native-ohos/react-native-quick-base64`,支持直接从 npm 下载。 +- 更多详情请查阅新仓库的 README 文件。 +- 本仓库旧版本的文档已归档:[链接](/doc/zh-cn.md) -## Documentation +# Migration Announcement -- [中文](https://gitee.com/react-native-oh-library/usage-docs/blob/master/zh-cn/react-native-quick-base64.md) - -- [English](https://gitee.com/react-native-oh-library/usage-docs/blob/master/en/react-native-quick-base64.md) - -## License - -This library is licensed under [The MIT License (MIT)](https://github.com/craftzdog/react-native-quick-base64/blob/master/LICENSE) +- This repository has been migrated to GitCode:[OpenHarmony-SIG/rntpc_react-native-quick-base64](https://gitcode.com/openharmony-sig/rntpc_react-native-quick-base64) +- The package name has been changed to `@react-native-ohos/react-native-quick-base64` and is now available for direct download from npm. +- For more details, please refer to the README in the new repository. +- Archived documentation for versions in this repository can be found here: [Link](/doc/en.md) diff --git a/doc/en.md b/doc/en.md new file mode 100644 index 0000000..ab33c78 --- /dev/null +++ b/doc/en.md @@ -0,0 +1,545 @@ +> Template version: v0.2.2 + +

+

react-native-quick-base64

+

+

+ + Supported platforms + + + License + +

+ +> [!TIP] [ GitHub address](https://github.com/react-native-oh-library/react-native-quick-base64) + +## Installation and Usage + +Find the matching version information in the release address of a third-party library: [@react-native-oh-tpl/react-native-quick-base64 Releases](https://github.com/react-native-oh-library/react-native-quick-base64/releases).For older versions that are not published to npm, please refer to the [installation guide](/en/tgz-usage-en.md) to install the tgz package. + +Go to the project directory and execute the following instruction: + + + +#### **npm** + +```bash +npm install @react-native-oh-tpl/react-native-quick-base64 +``` + +#### **yarn** + +```bash +yarn add @react-native-oh-tpl/react-native-quick-base64 +``` + + + +The following code shows the basic use scenario of the repository: + +> [!WARNING] The name of the imported repository remains unchanged. + +```js +import React, { useState } from 'react'; +import { Text, View, TextInput, ScrollView, StyleSheet, Button } from 'react-native'; +import { byteLength, btoa, atob, toByteArray, fromByteArray, getNative, trimBase64Padding, shim } from '@react-native-oh-tpl/react-native-quick-base64'; + +type FuncBase64ToArrayBuffer = ( + data: string, + removeLinebreaks?: boolean +) => ArrayBuffer +type FuncBase64FromArrayBuffer = ( + data: string | ArrayBuffer, + urlSafe?: boolean +) => string + + +interface NativeModule { + base64FromArrayBuffer: FuncBase64FromArrayBuffer | undefined; + base64ToArrayBuffer: FuncBase64ToArrayBuffer | undefined; +} + +const PALETTE = { + REACT_CYAN_LIGHT: 'hsl(193, 95%, 68%)', + REACT_CYAN_DARK: 'hsl(193, 95%, 30%)', +}; + +export function QuickBase64Test() { + const [textTobase64, onChangeTextToBase64] = useState(''); + + const [base64ToTextLength, onChangeBase64TextLength] = useState(0); + + const [base64ToText, onChangeBase64Text] = useState(''); + + const [byteArray, onChangeByteArray] = useState(new Uint8Array(0)); + + const [byteArrayRemove, onChangeByteArrayRemove] = useState(new Uint8Array(0)); + + const [fbArrayBase64Str, onChangeFbArrayBase64Str] = useState(''); + + const [fbArrayBase64StrUrlSafe, onChangeFbArrayBase64StrUrlSafe] = useState(''); + + const [testShimBtoA, onChangeTestShimBtoA] = useState(''); + + const [testShimAtoB, onChangeTestShimAtoB] = useState(''); + + const [nativeModule, onChangeNativeModule] = useState({ + base64FromArrayBuffer: undefined, + base64ToArrayBuffer: undefined + }); + + const [nativeBFABText, onChangeNBFABText] = useState(''); + + const [nativeBFABTextUrlSafe, onChangeNBFABTextUrlSafe] = useState(''); + + const [nativeBTABText, onChangeNBTABText] = useState(new Uint8Array(0)); + + const [nativeBTABTextRemoveLinebreaks, onChangeNBTABTextRemoveLinebreaks] = useState(new Uint8Array(0)); + + const [trimBase64PaddingText, onChangeTrimBase64PaddingText] = useState(''); + + const byArray = new Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33]); + const onPressBtoA = (text: string) => { + let b64 = btoa(text); + console.log(`Convert string to base64 ${b64}`); + onChangeTextToBase64(b64) + } + + const [testText, onChangeTestText] = React.useState(''); + + const onPressAtoB = (text: string) => { + let textA = atob(text); + console.log(`Base64 to string conversion ${textA}`); + onChangeBase64Text(textA) + } + + const onPressBase64Length = (text: string) => { + console.log(`Print base64 length 1 ${text}`); + onChangeBase64TextLength(byteLength(text)) + } + + const onPressToByteArray = (text: string) => { + let btArray = toByteArray(text); + console.log(`toByteArray ${btArray}`); + onChangeByteArray(btArray) + } + + const onPressToByteArrayRemove = (text: string, removeLinebreaks: boolean = false) => { + let btArray = toByteArray(text, removeLinebreaks); + console.log(`toByteArray ${btArray}`); + onChangeByteArrayRemove(btArray) + } + + const onPressFromByteArray = ( + uint8: Uint8Array, + urlSafe: boolean = false) => { + let b64 = fromByteArray(uint8); + console.log(`fromByteArray ${b64}`); + onChangeFbArrayBase64Str(b64) + } + + const onPressFromByteArrayUrlSafe = ( + uint8: Uint8Array, + urlSafe: boolean = false) => { + let b64 = fromByteArray(uint8, urlSafe); + console.log(`fromByteArray ${b64}`); + onChangeFbArrayBase64StrUrlSafe(b64) + } + + const handleAddShimToGlobal = () => { + shim(); + console.log(typeof global.btoa); + console.log(typeof global.atob); + } + + const onPressTestShimBtoA = (text: string) => { + const encodeBase64 = global.btoa(text); + console.log(`shim global btoa ${encodeBase64}`); + onChangeTestShimBtoA(encodeBase64) + } + + const onPressTestShimAtoB = (text: string) => { + const decodeBase64 = global.atob(text); + console.log(`shim global atob ${decodeBase64}`); + onChangeTestShimAtoB(decodeBase64) + } + + const onPressTrimBase64Padding = (text: string) => { + let trimBase64 = trimBase64Padding(text); + console.log(`shim global atob ${trimBase64}`); + onChangeTrimBase64PaddingText(trimBase64) + } + + const onPressGetNative = () => { + const native = getNative() as NativeModule; + onChangeNativeModule(native) + } + + const onPressNBFAB = (text: string | ArrayBuffer) => { + if (nativeModule?.base64FromArrayBuffer) { + let base64FromArrayBuffer = nativeModule.base64FromArrayBuffer(text); + onChangeNBFABText(base64FromArrayBuffer) + } + } + + const onPressNBFABUrlSafe = (text: string | ArrayBuffer, urlSafe: boolean = false) => { + if (nativeModule?.base64FromArrayBuffer) { + let base64FromArrayBuffer = nativeModule.base64FromArrayBuffer(text, urlSafe); + onChangeNBFABTextUrlSafe(base64FromArrayBuffer) + } + } + + const onPressNBTAB = (text: string) => { + if (nativeModule?.base64ToArrayBuffer) { + let base64ToArrayBuffer = new Uint8Array(nativeModule.base64ToArrayBuffer(text)); + onChangeNBTABText(base64ToArrayBuffer) + } + } + + const onPressNBTABRemoveLinebreaks = (text: string, removeLinebreaks: boolean = false) => { + if (nativeModule?.base64ToArrayBuffer) { + let base64ToArrayBuffer = new Uint8Array(nativeModule.base64ToArrayBuffer(text, removeLinebreaks)); + onChangeNBTABTextRemoveLinebreaks(base64ToArrayBuffer) + } + } + + return ( + + + + onChangeTestText(text)} + placeholder="please input test text" + placeholderTextColor={'#674651'} + value={testText} + /> + + + BtoA Encodes a character string into a Base64 character string. + + test string transform base64, testing the text: {testText} +