# text-width

> Measure the text width in browsers

Latest version **1.2.0** (published 2015-02-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install text-width
pnpm add text-width
yarn add text-width
bun add text-width
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2015-02-03 |
| First published | 2014-11-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 21 |
| Maintainers | kapetan |
| Keywords | measure, text, width, canvas, context, 2d |

## Links

- npm: https://www.npmjs.com/package/text-width
- Repository: https://github.com/kapetan/text-width
- Issues: https://github.com/kapetan/text-width/issues
- npm.io page: https://npm.io/package/text-width

## Dependencies (1)

- [xtend](https://npm.io/package/xtend.md) ~4.0.0

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.2.0 (latest) — 2015-02-03
- 1.1.0 — 2014-12-07
- 1.0.0 — 2014-11-17
- 0.0.2 — 2014-11-16
- 0.0.1 — 2014-11-16

## README

# 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][mt] method for acquiring the text width.

```javascript
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][font]. The size option can either be a number (size in pixels) or a string, e.g. `10pt`.

[mt]: https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Drawing_text
[font]: https://developer.mozilla.org/en-US/docs/Web/CSS/font

---
_Source: https://npm.io/package/text-width · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
