npm.io
1.2.0 • Published 5 months ago

@sr-connect/convert

Licence
UNLICENSED
Version
1.2.0
Deps
0
Size
19 kB
Vulns
0
Weekly
0

An utility library for ScriptRunner Connect runtime that provides bunch of conversion functions.

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?: string = 'utf8'): string;
convertBufferToBase64(buffer: ArrayBuffer): string;
convertBufferToText(buffer: ArrayBuffer, encoding?: string = 'utf8'): string;
convertTextToBase64(text: string, encoding?: string = 'utf8'): string;
convertTextToBuffer(text: string, encoding?: string = 'utf8'): UInt8Array;
convertTextToText(text: string, sourceEncoding: string, targetEncoding?: string = 'utf8');
convertArrayBufferToFormDataBuffer(...chunks: chunks): BufferedFormData;

Changelog

1.2.0

  • Introduced fastTransfer mode for convertBufferToText and convertBufferToBase64 functions. This option is only functional in runtime V2 and up. When enabled, ArrayBuffer will be transferred instead of being copied, which makes it faster, but as a result the ArrayBuffer will become invalidated (can no longer be read or edited).

Changelog

1.1.1

  • Internal package.json fix, no functional changes were introduced with this update.

1.1.0

  • Added convertArrayBufferToFormDataBuffer (or Convert.arrayBufferToFormDataBuffer) function that allows to convert form data into encoded array buffer more efficiently than using FormData and Blob classes together.