Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@creately/inner-text
Advanced tools
Cross Browser `innerText` function based on innerHTML with replacements.
Cross Browser innerText
function based on innerHTML with replacements.
innerText is a function, that is not standardized, but Chrome and IE support. Firefox doesn't.
There is different ways to implement the innerText functionality.
You can get a selection
window.getSelection()
, select all the elementsselection.selectAllChildren(el)
and callselection.toString()
.The problem is, that it is based on the user selection, and you can mess it up.
If you want to go this route: inner-text-shim is for you.
Otherwise this function can be helpful.
npm install @creately/inner-text
All innerText does is get the el.innerText
from the element
, even when the browser does not support it.
You can pass an html element or a string with html as input to this function. you can't set the innerText
with this module.
var innerText = require('inner-text');
// get the dom element with plain javascript
var el = document.querySelector('body');
// or with jquery:
el = $('body')[0];
// set the innerHTML (only for this example)
el.innerHTML = 'hello<br/>world';
var text = innerText(el)
assert.equal(text, 'hello\nworld');
You can specify the tags to replace with
el.innerHTML = 'hello<p>world</p>';
var text = innerText(el)
assert.equal(text, 'hello\nworld');
el.innerHTML = 'hello<div>world</div>';
var text = innerText(el, { tags: { div : '\n' }} )
assert.equal(text, 'hello\nworld');
el.innerHTML = 'hello<p>world</p>';
var text = innerText(el, { tags: { p : '\n' }})
assert.equal(text, 'helloworld');
el.innerHTML = 'hello<p>world</p>hi<p>there</p>';
var text = innerText(el, { tags: { p : '\n', div : '\n\n' }})
assert.equal(text, 'hello\nworldhi\n\nthere');
npm test
MIT
Andi Neck | @andineck
FAQs
Cross Browser `innerText` function based on innerHTML with replacements.
The npm package @creately/inner-text receives a total of 5 weekly downloads. As such, @creately/inner-text popularity was classified as not popular.
We found that @creately/inner-text demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.