Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
string-pixel-width
Advanced tools
String pixel width measurement on the backend in Javascript.
Why I created this package? Read more about purpose
To install the stable version:
npm install --save string-pixel-width
var pixelWidth = require('string-pixel-width');
const width = pixelWidth('My text ...', { size: 10 });
console.log('This text is ' + width + 'px long in the size of 10px.');
// This text is 43.5px long in the size of 10px.
var pixelWidth = require('string-pixel-width');
const width = pixelWidth('My text ...', { font: 'impact', size: 10 });
console.log('This text is ' + width + 'px long in the size of 10px.');
// This text is 42px long in the size of 10px.
var pixelWidth = require('string-pixel-width');
const width = pixelWidth('My text ...', { font: 'open sans', size: 10, bold: true, italic: true });
console.log('This text is ' + width + 'px long in the size of 10px.');
// This text is 47px long in the size of 10px using bold and italic proportions.
PRs are welcome :) This library uses static map of width of every ASCII letter for all supported fonts.
src/pixelWidthCalculator.html
in your editorsrc/pixelWidthCalculator.html
in Google Chrome. It should look like this:
src/widthsMap.js
Please everytime make sure you don't broke existing fonts - remove any font or broke his widths.
FAQs
String pixel width measurement on the backend in Javascript
The npm package string-pixel-width receives a total of 12,683 weekly downloads. As such, string-pixel-width popularity was classified as popular.
We found that string-pixel-width 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.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.