Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
ember-text-measurer
Advanced tools
Ember addon with a service to calculate text dimensions on a canvas
This addon provides a very simple service to measure the width of a string using an in-memory canvas, so it doesn't cause any layout reflow for max performance.
ember install ember-text-measurer
This addon just provides a service that you can inject wherever you need.
The service for now has three methods:
width(string, font = null)
will return the width of the text with the given font information.textMeasurer.width('foobar', '24px Arial'); // ~ 68.02px
textMeasurer.width('foobar', '20px Arial'); // ~ 56.64px
textMeasurer.width('foobar', '20px Times New Roman'); // ~ 52.19px
fitTextSize(string, width, font = null)
will return the font size with which the given text
will fully fit in the available width with the given (option) font information.textMeasurer.fitTextSize('foobar this is too long', 200, 'normal 24px Times'); // 22px
textMeasurer.fitTextSize('foobar this is too long', 200, 'normal 24px Helvetica'); // 21px
textMeasurer.fitTextSize('foobar this is too long', 200, 'normal 24px Georgia'); // 20px
Note: The font size passed to this method is irrelevant, the important part is the font style and family.
lines(string, width, font = null)
will return the number of lines that this text would
require when rendered in a container of the given width with the given font.const sampleMultilineText = `Lorem
ipsum dolor sit amet, ex legimus mandamus sea, qui no doctus option. Ei pri commune maiestatis. Mea at facete appetere tincidunt. Et sea quaestio expetendis. No eius virtute delenit per.
Ea mel error latine, usu harum delicata forensibus id, ut est probo quodsi regione. Sumo definitiones ex has, percipit voluptatum an qui. Eius solet aeterno sea ut, qui ex inani persequeris. In nostro facilis consetetur mea. Ut audiam virtute nostrum eam, omnes luptatum splendide eam at.
Veri zril ex vel, pri habemus delicata et. Te minimum expetenda dissentiet est, homero omnium expetenda no pri, enim fuisset usu ei. Mel ex quidam scripserit, pri aliquip debitis id. Vis ea legere persius recteque, utamur blandit volutpat ea vel.`;
textMeasurer.lines(sampleMultilineText, 400, 'normal 24px Helvetica'); // 26 lines
textMeasurer.lines(sampleMultilineText, 600, 'normal 24px Helvetica'); // 19 lines
textMeasurer.lines(sampleMultilineText, 600, 'normal 14px Helvetica'); // 14 lines
Please note than measuring the lines is significantly more expensive than measuting the width and might take a non-negligible amount of time when performed on text over a few thousands words, and results might not be accurate on browsers that don't have subpixel precission on text measurements
Check THE DEMO for some ideas ;-)
Pretty good, in theory all back to IE9, although IE9 might give slightly unnacurate results, probably not innacurate enough to be a problem.
FAQs
Ember addon with a service to calculate text dimensions on a canvas
The npm package ember-text-measurer receives a total of 28,466 weekly downloads. As such, ember-text-measurer popularity was classified as popular.
We found that ember-text-measurer 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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.