Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
The linebreak npm package is used for determining line break opportunities in text according to the Unicode Line Breaking Algorithm (UAX #14). It helps in handling text wrapping and formatting by identifying where lines can be broken in a way that maintains readability and adheres to typographic conventions.
Basic Line Breaking
This feature allows you to break a string into lines according to the Unicode Line Breaking Algorithm. The code sample demonstrates how to use the linebreak package to iterate through break points in a string and print each line.
const linebreak = require('linebreak');
const str = 'This is a sample text that needs line breaking.';
const breaker = linebreak(str);
let last = 0;
let bk;
while (!(bk = breaker.next()).done) {
console.log(str.slice(last, bk.value.position));
last = bk.value.position;
}
Custom Line Breaking
This feature allows you to customize the line breaking behavior by passing options. The code sample shows how to use a 'strict' line break mode to control the breaking points more precisely.
const linebreak = require('linebreak');
const str = 'Custom line breaking example.';
const breaker = linebreak(str, { lineBreak: 'strict' });
let last = 0;
let bk;
while (!(bk = breaker.next()).done) {
console.log(str.slice(last, bk.value.position));
last = bk.value.position;
}
The linewrap package provides a simple way to wrap text to a specified width. Unlike linebreak, which follows the Unicode Line Breaking Algorithm, linewrap focuses on wrapping text to fit within a given width, making it more suitable for simple text formatting tasks.
The wordwrap package is used to wrap text at a specified width, breaking lines at word boundaries. It is similar to linebreak in that it helps with text formatting, but it does not follow the Unicode Line Breaking Algorithm and is more straightforward in its approach.
An implementation of the Unicode Line Breaking Algorithm (UAX #14)
Line breaking, also known as word wrapping, is the process of breaking a section of text into lines such that it will fit in the available width of a page, window or other display area. The Unicode Line Breaking Algorithm performs part of this process. Given an input text, it produces a set of positions called "break opportunities" that are appropriate points to begin a new line. The selection of actual line break positions from the set of break opportunities is not covered by the Unicode Line Breaking Algorithm, but is in the domain of higher level software with knowledge of the available width and the display size of the text.
This is a JavaScript/CoffeeScript implementation of the Unicode Line Breaking Algorithm for Node.js (and browsers I guess). It is used by PDFKit for line wrapping text in PDF documents, but since the algorithm knows nothing about the actual visual appearance or layout of text, it could be used for other things as well.
You can install via npm
npm install linebreak
var LineBreaker = require('linebreak');
var lorem = 'lorem ipsum...';
var breaker = new LineBreaker(lorem);
var last = 0;
var bk;
while (bk = breaker.nextBreak()) {
// get the string between the last break and this one
var word = lorem.slice(last, bk.position);
console.log(word);
// you can also check bk.required to see if this was a required break...
if (bk.required) {
console.log('\n\n');
}
}
In order to use the library, you shouldn't need to know this, but if you're interested in contributing or fixing bugs, these things might be of interest.
The src/classes.coffee
file is automatically generated from LineBreak.txt
in the Unicode
database by src/generate_data.coffee
. It should be rare that you need to run this, but
you may if, for instance, you want to change the Unicode version.
You can run the tests using npm test
. They are written using mocha
, and generated from
LineBreakTest.txt
from the Unicode database, which is included in the repository for performance
reasons while running them. About 150 of the over 6000 tests are currently skipped due to
implementation differences. It appears that some of the tests may be wrong or use different
tailoring from the spec.
MIT
FAQs
An implementation of the Unicode Line Breaking Algorithm (UAX #14)
The npm package linebreak receives a total of 625,254 weekly downloads. As such, linebreak popularity was classified as popular.
We found that linebreak 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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.