Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
adapttext.js
Advanced tools
adapttext.js is a dependency free and simple javascript solution capable to fit your text inside the parent element.
adapttext.js is a dependency free and simple javascript solution capable to fit your text inside the parent element.
It calculates the maximum font-size possibile in order to keep the text's width and height inside the parent.
It's very useful in responsive situation and where we don't know in advance the text's length (text pulled from a CMS?). It is also very handy when we need to display text along an image and we want to avoid overlaps.
adapttext.js supports AMD, CommonJS and Browser global (it uses UMD)
You can install it using bower: bower install adapttext.js --save-dev
You can install it using npm: npm install adapttext.js --save-dev
or just including the script in your page:
<script src="adapttext.js" type="text/javascript"></script>
new AdaptText(element, options);
Example:
<div id="mybox">
<span>This is an example test...</span>
</div>
<style>
#mybox {
width: 50%;
height: 30%;
}
</style>
<script>
var el = document.getElementById('mybox');
var adapt = new AdaptText(el);
</script>
If you're using jQuery in your project you can use
$('.mybox').adaptText(options);
If you need the adapttext.js instance later:
var instance = $('.mybox').data('adaptText');
instance.destroy();
adapttext.js also accept some optional options:
new AdaptText(el, {
minFontSize: 10, //define in px the minimum font size possible
maxFontSize: 200, //define in px the maximum font size possible
tollerance: 10, //define a number of px of allowed exceed
callback: function(newpx) {
//this callback is called everytime a new font size is set
//the first argument is the new font-size px value
}
});
display: inline-block
and margin: 0
.destroy()
Removes the event listener attached to the window resize.
.elaborate()
Force the recalculation of the correct font-size.
Most solutions (flowtype.js, fitText.js...) uses jquery as dependency and just fit the text based on parent's width, without the height constraint.
adapttext.js is released under the MIT License and it's made by Luigi De Rosa.
The photo used in the demo is courtesy of https://unsplash.com/danielacuevas
Issue & Pull Requests are more than welcome!!
FAQs
adapttext.js is a dependency free and simple javascript solution capable to fit your text inside the parent element.
We found that adapttext.js demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.