Skip to content

kapetan/text-width

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

text-width

A small utility for measuring the text width in browsers that support the canvas API.

Usage

Install through npm and require it with browserify. It uses the ctx.measureText method for acquiring the text width.

var width = require('text-width');

var w = width('hello world', {
	family: 'Arial',
	size: 10
});

It supports following font options, style, variant, weight, size and family. Each corresponding to a similarly named CSS property. The size option can either be a number (size in pixels) or a string, e.g. 10pt.

About

Measure the text width in browsers

Resources

Stars

Watchers

Forks

Packages

No packages published