
Security News
Risky Biz Podcast: Making Reachability Analysis Work in Real-World Codebases
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
A 10x faster and more accurate text wrapping util in < 2KB (min) (MIT Licensed)
uWrap exists to efficiently predict varying row heights for list and grid virtualization, a technique for UI performance optimization when rendering large, scrollable datasets.
Doing this both quickly and accurately turns out to be a non-trivial task since Canvas2D provides no API for text wrapping, and measureText()
is quite expensive;
measuring via DOM is also a non-starter due to poor performance.
Additionally, font size, variable-width kerning, letter-spacing
, explicit line breaks, and different white-space
choices affect the wrapping locations.
Notes:
\r\n
explicit line breakspre-line
wrapping strategy is implemented so faruWrap outperforms canvas-hypertxt by a wide margin in both CPU and memory usage while being significantly more accurate.
The benchmark below wraps 100,000 random sentences into boxes of random widths between 50px and 250px. You can see this live in DevTools console of the demo page.
Chrome 135 | Firefox 137 | Safari 18.1 | |
---|---|---|---|
uWrap | 82ms | 90ms | 185ms |
canvas-hypertxt | 770ms | 1660ms | 1430ms |
npm i uwrap
or
<script src="./dist/uWrap.iife.min.js"></script>
See uWrap.d.ts TypeScript def.
// import fn for wrapping variable-width fonts using pre-line strategy
import { varPreLine } from 'uwrap';
// create a Canvas2D context with desired font settings
let ctx = document.createElement('canvas').getContext('2d');
ctx.font = "14px Inter, sans-serif";
ctx.letterSpacing = '0.15px';
// init util fns
const { count, test, split } = varPreLine(ctx);
// example text
let text = 'The quick brown fox jumps over the lazy dog.';
// count lines
let numLines = count(text, width);
// test if text will wrap
let willWrap = test(text, width);
// split lines (with optional limit)
let lines = split(text, width, 3);
FAQs
A very fast and accurate text and line wrapping util
The npm package uwrap receives a total of 42,967 weekly downloads. As such, uwrap popularity was classified as popular.
We found that uwrap demonstrated a healthy version release cadence and project activity because the last version was released less than 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
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.