https://github.com/davidfig/calc-fontsize
calculate font-size for a given bounding box and optionally a font
https://github.com/davidfig/calc-fontsize
Last synced: 2 months ago
JSON representation
calculate font-size for a given bounding box and optionally a font
- Host: GitHub
- URL: https://github.com/davidfig/calc-fontsize
- Owner: davidfig
- License: mit
- Created: 2017-08-04T10:42:58.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-08-18T01:26:08.000Z (over 7 years ago)
- Last Synced: 2025-02-18T01:17:28.996Z (3 months ago)
- Language: JavaScript
- Size: 236 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## debug.js
calculate font-size for a given bounding box and optionally a font## Code Example
const FontSize = require('calc-fontsize')
const div = document.createElement('div')
document.body.appendChild(div)
const text = 'find the right size for me'
div.style.fontSize = FontSize(text, {width: 100, height: 100, fontFamily: 'arial'})div.style.fontFamily = 'arial'
div.style.fontSize = fontSize + 'px'
div.innerText = text## Live Example
https://davidfig.github.io/calc-fontsize/## Installation
npm i calc-fontsize
# API Reference
/**
* @param {string} text
* @param {object} options
* @param {number} [width] maximum width for bounding box
* @param {number} [height] maximum height for bounding box
* @param {string} [fontFamily]
* @param {number} [min=10] minimum font size
* @param {number} [max=1000] maximium font size
* @param {boolean} [remove=false] remove dummy element instead of hiding it for use on next call
* @returns {number} fontSize
*/
function FontSize(text, options)Copyright (c) 2017 YOPEY YOPEY LLC - MIT License