# promise-font

> Get a promise that will resolve when a specified font has been loaded and reject if the font fails to load before the timeout.

Latest version **1.0.1** (published 2018-02-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install promise-font
pnpm add promise-font
yarn add promise-font
bun add promise-font
```

## 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.0.1 |
| Published | 2018-02-24 |
| First published | 2018-02-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 11.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Jeff Sneden |
| Maintainers | jsneden |

## Links

- npm: https://www.npmjs.com/package/promise-font
- Repository: https://github.com/jsneden/promise-font
- npm.io page: https://npm.io/package/promise-font

## Recent versions

- 1.0.1 (latest) — 2018-02-24
- 1.0.0 — 2018-02-21

## README

# promise-font
Get a promise that will resolve when a specified font has been loaded and reject if the font fails to load before the timeout. This is mostly useful for handling complex UX issues resulting from the difference between the default font's size and the specified font's size.

This package was heavily inspired by Patrick Marabeas's [jQuery-FontSpy](https://github.com/patrickmarabeas/jQuery-FontSpy.js). This package takes the same approach but modernizes the project by:
* Removing the jQuery dependency
* Providing support for AMD, CommonJS and ES6 includes
* Providing support for yarn/npm
* Using promises instead of callbacks

## Installation
```
yarn add promise-font
```

### ES6
```js
import promiseFont from 'promise-font';
```

### CommonJS
```js
var promiseFont = require('promise-font');
```

### Global Script Include
```html
<script src="promise-font.js">
```

## Usage
### Basic Example
```js
promiseFont('Archivo Narrow').then(() => {
  console.log('Font loaded!');
}).catch(() => {
  console.log('Font failed to load before timeout exceeded');
});
```

### API
`promiseFont` is a function which takes a font name and optionally a config object. The config object can take the following options:
* Integer `timeout` - Stop checking for the font to load after specified milliseconds. Default `2000`.
* Integer `interval` - Check to see if the font is loaded every specified interval in milliseconds. Default `50`.
* String `baselineFont` - The default font to use for width baseline comparison. Default `'Courier New'`.
* String `glyphs` - Additional characters to include in the font test. Default `undefined`.

### Complete Example
```js
promiseFont('Archivo Narrow', {
  timeout: 10 * 1000,        // 10 second timeout
  interval: 10,              // 10 millisecond interval
  glyphs: '\t',              // Include the tab character in the font test
  baselineFont: 'sans-serif' // Change the baseline font test to sans-serif
}).then(() => {
  console.log('Font loaded!');
}).catch(() => {
  console.log('Font failed to load before timeout exceeded');
});
```

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