1.3.0 • Published 1 month ago
@sr-connect/convert
Licence
UNLICENSED
Version
1.3.0
Deps
0
Size
22 kB
Vulns
0
Weekly
0
A utility library for the ScriptRunner Connect runtime that provides conversion functions for text, buffers, base64 and form data.
Usage
Either import individual functions:
import { convertTextToBase64 } from '@sr-connect/convert';
export default async function(event: any, context: Context): Promise<void> {
console.log(convertTextToBase64('HELLO WORLD', 'utf8'));
}
or import the entire namespace:
import { Convert } from '@sr-connect/convert';
export default async function(event: any, context: Context): Promise<void> {
console.log(Convert.textToBase64('HELLO WORLD', 'utf8'));
}
Available functions
convertBase64ToBuffer(base64: string): Uint8Array;
convertBase64ToText(base64: string, encoding?: TextEncoding): string;
convertBufferToBase64(buffer: ArrayBuffer, fastTransfer?: boolean): string;
convertBufferToText(buffer: ArrayBuffer, encoding?: TextEncoding, fastTransfer?: boolean): string;
convertTextToBase64(text: string, encoding?: TextEncoding): string;
convertTextToBuffer(text: string, encoding?: TextEncoding): Uint8Array;
convertTextToText(text: string, sourceEncoding: TextEncoding, targetEncoding?: TextEncoding): string;
convertArrayBufferToFormDataBuffer(...chunks: FormDataChunk[]): BufferedFormData;
Every encoding parameter defaults to utf8. The same functions are available on the Convert namespace without the convert prefix, so convertTextToBase64 is Convert.textToBase64.
Changelog
1.3.0
Convert.bufferToTextandConvert.bufferToBase64now acceptfastTransfer, matching the standaloneconvertBufferToTextandconvertBufferToBase64functions.TextEncodingnow covers every encoding the runtime accepts, addingutf-16leandbase64url.- Removed the unused
delimiterproperty from the object returned byconvertArrayBufferToFormDataBuffer. It was never part of the encoded payload. convertArrayBufferToFormDataBuffernow terminates the payload with a closing boundary, which strict servers require.- Corrected the documentation of several functions.
1.2.0
- Introduced
fastTransfermode forconvertBufferToTextandconvertBufferToBase64. When enabled, the call consumes the buffer you pass in, which makes the conversion faster but leaves the buffer unreadable afterwards.
1.1.1
- Internal
package.jsonfix, no functional changes were introduced with this update.
1.1.0
- Added
convertArrayBufferToFormDataBuffer(orConvert.arrayBufferToFormDataBuffer) which encodes form data into a buffer using less memory and CPU than theFormDataandBlobclasses.