text-fit
Apply text styles based on the shape of the text
Last updated 5 years ago by yoshuawuyts .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install text-fit 
SYNC missed versions from official npm registry.

text-fit stability

npm version build status test coverage downloads js-standard-style

Fitter, happier text. Apply text styles based on the shape of the text. Useful to apply styles based on a design system.

Usage

const textFit = require('text-fit')
const vdom = require('virtual-dom')
const hyperx = require('hyperx')

const hx = hyperx(vdom.h)

const text = 'The quick brown fox jumped over the lazy dog'

const styles = textFit(text, {
  scale: [
    { 'font-size': 24 },
    { 'font-size': 32, max: 30 },
    { 'font-size': 48, max: 15 }
  ]
})

const tree = hx`
  <h1 styles=${styles}>${text}</h1>
`

document.body.appendChild(vdom.create(tree))

API

textFit(text, opts)

Take a string, analyze the length, and determine the font size based on a scale. Takes the following options:

  • opts.scale: pass in a scale of values to be set. Determines based on .max if the values should be applied on the text.

Installation

$ npm install text-fit

License

MIT

Current Tags

  • 1.0.1                                ...           latest (5 years ago)

2 Versions

  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (1)
Dev Dependencies (6)
Dependents (2)

Copyright 2014 - 2016 © taobao.org |