
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
text-field-edit
Advanced tools
Insert text in a textarea and input[text] (supports Firefox and Undo, where possible)
Insert text in a
textarea
andinput[type=text]
(supports Firefox and Undo, where possible)
The text will be inserted after the cursor or it will replace any text that's selected, acting like a paste
would.
You should use this instead of setting the field.value
directly because:
input
event (with event.inputType === 'insertText'
)It uses document.execCommand('insertText')
in Chrome (which has Undo support) and it replicates its behavior in Firefox (without Undo support until this bug is solved).
If you need IE support, use insert-text-at-cursor.
You can just download the standalone bundle
Or use npm
:
npm install text-field-edit
// This module is only offered as a ES Module
import insertText from 'text-field-edit';
Insert text at the cursor, replacing any possible selected text:
const textarea = document.querySelector('textarea');
const button = document.querySelector('.js-add-signature');
button.addEventListener(event => {
insertText(textarea, 'Made by 🐝 with pollen.');
});
This will wrap the selected text (if any) with **
on both sides:
const textarea = document.querySelector('textarea');
const button = document.querySelector('.js-markdown-make-text-bold');
button.addEventListener(event => {
// Don't use `getSelection()` if you want Firefox support
const selectedText = value.slice(
textarea.selectionStart,
textarea.selectionEnd
);
insertText(textarea, '**' + selectedText + '**');
});
This will replace the entire content, equivalent to field.value = 'New text!'
but with undo support:
const textarea = document.querySelector('textarea');
textarea.select(); // The text needs to be selected so it will be replaced
insertText(textarea, 'New text!');
<textarea>
, in a few bytes. Uses this module.<textarea>
to fit its content, in a few bytes.FAQs
Insert text in a `<textarea>`, `` and `contenteditable` elements (including Undo support)
The npm package text-field-edit receives a total of 7,500 weekly downloads. As such, text-field-edit popularity was classified as popular.
We found that text-field-edit demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.