
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
balanced-text
Advanced tools

A performance-optimized script for balancing text in browser. text-wrap: balance is in the CSS Text Module Level 4 draft. This JS script is a polyfill and is dependency-free.
Initial benchmarks are faster than both Adobe's and NY Time's polyfills.
npm i balanced-text
After installation, you can import the JS file into your project using this snippet:
import { balanceText } from 'balanced-text'
Then run:
balanceText()
<element class='has-text-balanced'>Lorem…</element>
/* For when the CSS spec is available */
.has-text-balanced {
text-wrap: balance;
}
The JS will only run if your browser does not support text-wrap: balance.
https://www.jsdelivr.com/package/npm/balanced-text
<script src='https://cdn.jsdelivr.net/npm/balanced-text@latest/balance-text.min.js'>
balanceText()
</script>
Options are passed as an optional object.
balanceText({
elements: '.has-text-balanced',
watch: false,
debounce: 200,
lazyBalance: false,
disableWait: false
})
Change which elements are balanced.
String'.has-text-balanced'balanceText({ elements: '.balance-text' })
Any string that works with document.querySelectorAll() is valid.
If the window is resized, rebalance the text.
BooleanfalsebalanceText({ watch: true })
When watch: true, balanceText is debounced by default. That reduces jank whenever the window is resized. Use debounce to change the timing.
Integer (milliseconds)200balanceText({ debounce: 200 })
Set debounce to 0 to eliminate it.
If you have many elements on your page that need balanced text, consider enabling lazy balancing.
When set to true, balanceText will only affect visible elements. Using IntersectionObserver, text will be automatically balanced when it enters the viewport. Because balanceText is fast, it should not introduce scroll jank.
BooleanfalsebalanceText({ lazyBalance: true })
By default, balanceText waits until the main thread is idle (see Timing). Enabling this option will make balanceText run as soon as possible. It may become render blocking. However, it can prevent the "flash" of unbalanced text.
BooleanFalsebalanceText({ disableWait: true })
br tag where the line breaks should goThis limits many performance drawbacks of other algorithms.
This script does assume a few things about the HTML contents:
b, strong, a tags). Will be fixed in future versions.' 'The script uses requestIdleCallback if available (~75% support). This reduces the likelihood that it interrupts important functions.
If not, it uses requestAnimationFrame to minimize the chances of dropping a frame.
requestAnimationFrame is always used during lazyBalancing to minimize scroll jank.
https://github.com/Nick-Mazuk/balanced-text/issues
©2020 Nick Mazuk. Code released under the MIT license.
FAQs
A performance-optimized script for balancing text in browser.
We found that balanced-text demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.