https://github.com/dy/add-font
Attach font to the page by url or from array buffer
https://github.com/dy/add-font
Last synced: 8 months ago
JSON representation
Attach font to the page by url or from array buffer
- Host: GitHub
- URL: https://github.com/dy/add-font
- Owner: dy
- Created: 2016-08-25T04:19:24.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-04-14T16:41:48.000Z (about 9 years ago)
- Last Synced: 2025-09-20T17:48:23.936Z (9 months ago)
- Language: JavaScript
- Size: 11.7 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# add-font [](http://github.com/badges/stability-badges)
Register new font-face for the current web page by URL or from ArrayBuffer.
[](https://npmjs.org/package/add-font/)
```js
const addFont = require('add-font');
//CSS URL inserts the to head
addFont('//cdn.jsdelivr.net/font-hack/2.020/css/hack.min.css');
//Font URL w/o extension inserts eot, woff2, woff, ttf, svg and otf versions
addFont('//cdn.jsdelivr.net/font-hack/2.020/fonts/eot/latin/hack-regular-latin-webfont',
`font-family: Hack; font-weight: normal;`);
//Font URL with extension inserts only target font file
addFont('./wavefont.otf', 'wavefont');
//ArrayBuffer will insert raw data as a font
addFont(myFont.toArrayBuffer(), `font-weight: bold; font-family: my-font-${id};`);
```
## API
**`addFont(cssUrl)`**
**`addFont(fontUrl, cssString|fontName)`**
**`addFont(fontUrlList, cssString|fontName)`**
**`addFont(arrayBuffer, cssString|fontName)`**
Attach font to the page, apply additional parameters, which are whether font name or `@font-face` properties, eg `font-family: ; font-style: ; font-weight: `.
## Motivation
The package is created for [wavefont](https://github.com/dfcreative/wavefont) test.
It is here mostly to save arrayBuffer font code snippet.
It may be useful for font-related tests or in theory for font design tools.
For regular sites for css fonts just insert ``, for specific font use `insert-styles` with `@font-face`.
## Related
* [google-fonts](https://github.com/hughsk/google-fonts) — easy-peasy google fonts by name.
* [webfontloader](https://github.com/typekit/webfontloader) — solution for all possible font include cases.