Skip to main content

@barocss/text-analyzer

Version in this checkout: 0.1.1. npm · Source

Text-difference analysis for browser input and composition handling.

Purpose

Compare text before and after a DOM input update and obtain insert, delete, or replace changes.

Install

npm install @barocss/text-analyzer

The published package provides ES modules and TypeScript declarations. Use a bundler that supports package exports.

Public entry points

ImportRole
@barocss/text-analyzerPublic JavaScript and TypeScript API

Import only these public paths. Source paths such as @barocss/text-analyzer/src/... are not part of the published API.

Usage

import { analyzeTextChanges } from '@barocss/text-analyzer';

const changes = analyzeTextChanges({
oldText: 'Hello', newText: 'Hello world', selectionOffset: 5, selectionLength: 0,
});
for (const change of changes) {
console.log(change.type, change.start, change.end, change.text);
}

Integration notes

Provide the old selection offset with the text snapshots. The result describes edits; it does not apply a transaction or synchronize browser selection.

Documentation

License

MIT. The published archive includes the license in dist/LICENSE.