Copyable
Updated on August 22, 2024Source codeTests
Copyable
is a class that enriches a string, allowing it to:
- Be copied to the clipboard
- Store its status (
ready
,copying
,copied
, orerrored
) - Tell you whether it matches the current clipboard text
Construct a Copyable
instance
The Copyable
constructor accepts two parameters:
Parameter
Type
Required
Description
string
String
yes
The string that will be made copyable.
options
Object
no
Options for the
Copyable
instance. See the Copyable
constructor options section for more guidance.Copyable
constructor options
Copyable
currently does not accept any options, only any empty options object.
State and methods
Property
Type
Description
Parameters
Return value
string
Getter/Setter
See return value
N/A
The string
passed to the constructor.
If you assign a value directly to string
, a setter will pass the new value to setString
.
status
Getter
See return value
N/A
Indicates the current status (String) of the
Copyable
instance. status
is ready
after the instance is constructed, copying
immediately after the copy
method is called, and copied
after the string
has been successfully copied. status
can also be errored
if there is an error during the copy
operation.isClipboardText
Getter
See return value
N/A
A Boolean that indicates whether or not the string
currently matches the users clipboard text.
copy(options)
Function
Copies the string.
For more guidance on the copy
method, see the How to copy text section.
An options object, as explained in the How to copy text section.
The
Copyable
instanceUsing with TypeScript
Nothing special to know about using Copyable
with TypeScript 🚀
API design compliance
Spec
Compliance status
Notes
Access functionality by constructing an instance
Constructor accepts two parameters: a piece of state, and an
options
object.Constructor does not access the DOM
Takes the form of a JavaScript Object
State and methods are accessible through properties of the object
Methods always return the instance
Stores the constructor's state in a public getter named after the state's type
string
Has a public method you can use to set a new value for that public getter
setString
Has a setter for that getter so you can assign a new value directly
Any other public getters that should be set by you in some cases also have setters and
set<Property>
methodsnone
Has at least one additional getter property that you can't (and shouldn't) set directly
status
, isClipboardText
Has one or more public methods that expose core functionality
copy
Either has no side effects or has side effects that can be cleaned up with a
stop
methodUses the sentence template to decide what state type should be accepted by a constructor
"A string can be copied."
Constructor does not accept options that only customize the behavior of public methods, it allows those options to be passed to the method itself as a parameter.
Named after its core action, proper-cased and suffixed with
able