Skip to content

Function: copyCode()

ts
function copyCode(code, language?): Promise<boolean>;

Copies a code snippet to the clipboard as both HTML and plain text.

Parameters

ParameterTypeDescription
codestringThe code string to copy.
language?stringOptional language hint for the class attribute on the <code> element.

Returns

Promise<boolean>

true when the copy succeeded.

Example

ts
console.log(await copyCode('const x = 1', 'javascript'))

Since

1.0.0

Released under the MIT License.