Functions

Helpful functions for common interactions.

Clipboard Clipboard function. Demo

copyToClipboard

Assign a text value to the system clipboard. Note: Due to browser security restrictions, the copy will only succeed if this method is invoked as a result of a user action (eg. user button click).

Code

HTML:

{{ clipboardCodeHtml }}

Typescript:

{{ clipboardCodeTypescript }}
Convert Type conversion functions. Demo

convertCSVToJSON

Conversion function that takes a CSV representation of objects and converts them to JSON. The first row in the input must be the object keys. Custom key separator and line separator can be specified. Space indentation size for output JSON can be specified.

Input CSV:

Output JSON:

convertObjectsToCSV

Conversion function that takes an array of objects and converts them to CSV format. Custom key and line separators can be specified.

Input Objects:

Output CSV:

Code

HTML:

{{ convertCodeHtml }}

Typescript:

{{ convertCodeTypescript }}
Download Content download functions. Demo

downloadCSV

Download CSV content to the specified file with .csv extension appended to the provided base file name.

CSV:

downloadJSON

Download JSON content to the specified file with .json extension appended to the provided base file name.

JSON:

downloadObjectsToCSV

Convert objects to CSV format and download to file with .csv extension appended to the provided base file name. Custom key separator and line separator can be specified.

Objects:

downloadObjectsToJSON

Convert objects to JSON format and download to file with .json extension appended to the provided base file name.

Objects:

download

Download string content to the specified file with desired mime type.

Code

HTML:

{{ downloadCodeHtml }}

Typescript:

{{ downloadCodeTypescript }}
File File handling functions. Demo

readFile

Read file as UTF-8 text. Return string contents on read completion.

File Content:

Code

HTML

{{ fileCodeHtml }}

Typescript

{{ fileCodeTypescript }}