Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@foliojs-fork/linebreak
Advanced tools
An implementation of the Unicode Line Breaking Algorithm (UAX #14)
@foliojs-fork/linebreak is a JavaScript library for determining line break opportunities in text according to the Unicode Line Breaking Algorithm. It is useful for text layout engines, word processors, and other applications that need to handle text wrapping and line breaking in a way that conforms to Unicode standards.
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 library to break a sample text into lines and print each line.
const linebreak = require('@foliojs-fork/linebreak');
const str = 'This is a sample text that needs line breaking.';
const breaker = new 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 Rules
This feature allows you to apply custom line breaking rules. The code sample demonstrates how to use the 'strict' line break rule to break a sample text into lines.
const linebreak = require('@foliojs-fork/linebreak');
const str = 'Custom rules for line breaking.';
const breaker = new 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 'linebreak' package is another implementation of the Unicode Line Breaking Algorithm. It provides similar functionality to @foliojs-fork/linebreak, allowing you to determine line break opportunities in text. However, it may have different performance characteristics and API design.
The 'wordwrapjs' package focuses on wrapping text to a specified width, which includes handling line breaks. While it does not strictly follow the Unicode Line Breaking Algorithm, it provides a simple and flexible way to wrap text, making it a good alternative for applications that need basic text wrapping functionality.
The 'hypher' package is a hyphenation engine for Node.js and browsers. It provides functionality for hyphenating words according to language-specific rules, which can be used in conjunction with line breaking to improve text layout. While it does not directly compete with @foliojs-fork/linebreak, it offers complementary functionality for text processing.
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 implementation of the Unicode Line Breaking Algorithm for Node.js (and browsers I guess). Currently supports Unicode version 13. 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.
Because on original repo is not possible release new version on npm see foliojs/linebreak#24. This fork is same as original repo and is maintained up-to-date. This forks contains these changes:
You can install via npm
npm install @foliojs-fork/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');
}
last = bk.position;
}
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.js
file is automatically generated from LineBreak.txt
in the Unicode
database by src/generate_data.js
. 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 50 of the over 7600 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)
We found that @foliojs-fork/linebreak 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.