You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

break-styled-lines

Package Overview
Dependencies
0
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

break-styled-lines

Add newlines to a string of text given a font style and width


Version published
Maintainers
1
Created

Readme

Source

break-styled-lines

This package is useful for when you want to know where linebreaks will occur in text given a font style (e.g. 16pt italic Georgia) and the width of its container. Uses the Canvas API to measure text, so it's quite fast. Uses an OffscreenCanvas if the browser supports it.

Example

import breakLines from 'break-styled-lines';

const textWithLineBreaks = breakLines(
  "Good day to you my friends! What ails you on this day?",
  100,
  "bold 12pt arial"
);

The result of the above usage would be:

/*
Good day to
you my
friends!
What ails
you on this
day?
*/

Installation

yarn add break-styled-lines

Usage

breakLines(
  // The string you'd like to break into lines. Can also be an array of strings, which will be treated as a single run of text, and then split back apart again.
  text: string | string[]
  // The width constraining the text
  width: number
  // The style of the text (a value of the CSS font property e.g. 10px bold serif)
  style: string
): string | string[]

Keywords

FAQs

Package last updated on 27 Nov 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc