Skip to content
On this page

[mxcad_2d API documentation] (../README. md)/tools

Module: tools

This module contains exports related to the MXCAD helper tool, and all exported content can be imported directly using the MXCAD package

Example

js
import { getJsonFromUrl } from "mxcad"

Table of contents

Variables

Functions

Variables

MxTools

Const MxTools: Object

Type declaration

NameType
IsZero(val: number) => boolean
_ML_String(strId: string, str: string) => string
b64Decode(str: string) => string
b64Encode(str: string) => string
createCursor(cursorSize: number, targetFrameSize: number, color: string) => any
downloadFile(blob: any, filename: string) => void
downloadFileFromUrl(url: string, filename: string) => void
getFileFromUrl(url: string) => Promise<undefined | Response>
getJsonFromUrl(url: string) => Promise<any>
postEmscriptenIndexedDBFile(filekey: string, url: string, retCall: (code: number, message: string) => void, param?: any) => void
postMemoryFile(memoryData: any, url: string, filename: string, retCall: (code: number, message: string) => void, param?: any) => void
saveAsFileDialog(__namedParameters: { blob: Blob ; filename?: string ; types?: FileTypes }) => Promise<undefined | FileSystemFileHandle & { createWritable: () => Promise<WritableStreamDefaultWriter<any>> }>

Functions

IsZero

IsZero(val): boolean

Check if a value is close to zero

Parameters

NameTypeDescription
Valnumbernumerical value

Returns

boolean

Boolean value


_ML_String

_ML_String(strId, str): string

Receive input prompt string

Parameters

NameTypeDescription
StrIdstringThe ID of a string starts with a defined ID name
Strstringprompt string

Returns

string


b64Decode

b64Decode(str): string

Decoding Base64 encoded strings into raw data

Parameters

NameTypeDescription
StrstringBase64 encoding

Returns

string

raw data


b64Encode

b64Encode(str): string

Base64 encoding of data

Parameters

NameTypeDescription
StrStringTarget Data

Returns

string

Base64 encoding


createCursor

createCursor(cursorSize?, targetFrameSize?, color?): any

Parameters

NameTypeDefault value
cursorSizenumber128
targetFrameSizenumber10
colorstring"#ffffff"

Returns

any


downloadFile

downloadFile(blob, filename): void

Download a file in the browser

Parameters

NameTypeDescription
BlobanyBlob object, which contains the data of the file to be downloaded
FilenamestringThe file name of the file to be saved

Returns

void


downloadFileFromUrl

downloadFileFromUrl(url, filename): void

Download files from the specified URL to the user's computer

Parameters

NameTypeDescription
UrlstringURL address for downloading files
FilenamestringThe file name of the file to be saved

Returns

void


getFileFromUrl

getFileFromUrl(url): Promise<undefined | Response>

Retrieve files from the specified URL

Parameters

NameTypeDescription
URL address of file 'url''string'

Returns

Promise<undefined | Response>

Target file


getJsonFromUrl

getJsonFromUrl(url): Promise<any>

Retrieve the file JSON string from the specified URL

Parameters

NameTypeDescription
URL address of file 'url''string'

Returns

Promise<any>

JSON string


postEmscriptenIndexedDBFile

postEmscriptenIndexedDBFile(filekey, url, retCall, param?): void

Retrieve files from IndexedDB (Indexed Database) and upload them to the specified URL

Parameters

NameTypeDescription
FilekeystringThe key of the file obtained from IndexedDB
URL address to which the data will be sent, used for uploading files
RetCall(code: number, message: string)=>voidcallback function
param?AnyOptional additional parameters that can be used to pass additional data or configuration information to the upload function

Returns

void


postMemoryFile

postMemoryFile(memoryData, url, filename, retCall, param?): void

Send data from memory to the specified URL for file upload functionality

Parameters

NameTypeDescription
MemoryDataanyObjects or data structures of data in memory
URL address to which the data will be sentstring
FilenamestringThe file name of the uploaded file
RetCall(code: number, message: string)=>voidcallback function
param?AnyOptional additional parameters that can be used to pass additional data or configuration information to the upload function

Returns

void


saveAsFileDialog

saveAsFileDialog(«destructured»): Promise<undefined | FileSystemFileHandle & { createWritable: () => Promise<WritableStreamDefaultWriter<any>> }>

File download and save (save as only compatible with Chrome 86, Edge 86, and Opera 72) compatible with lower versions of browsers such as iE10

Parameters

NameType
«destructured»Object
› blobBlob
› filename?string
› types?FileTypes

Returns

Promise<undefined | FileSystemFileHandle & { createWritable: () => Promise<WritableStreamDefaultWriter<any>> }>