npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

text-operation

v2.0.1

Published

text operation classes for rich text operational transformation

Readme

text-operation Npm version Build Status Coverage Status

Classes for Rich Text Operations using Operational Transformation

Overview

This package is heavily based on firepad's OT operations, which were in turn based on ot.js. Yay OSS!

This package is a conversion of their masterful work into Typescript + ES6, and turned into an easy to use module.

Installation

npm i -S text-operation

Usage

The easiest way to get familiar with the TextOperation class is to check out text-operation.utils.spec.js

The OT operations we allow are retain insert delete. A single TextOperation will contain one or many of these operations, but must traverse exactly entire string for which they will be applied:

import { TextOperation } from 'text-operation';

const testString = 'I am a test string';

const o = new TextOperation();
o.retain(2);
o.delete(2);
o.insert('was');
o.retain(14);
o.insert('!');

// apply operations to a string
console.log(o.apply(testString)); // I was a test string!

// composition example
const o2 = new TextOperation();
o2.retain(2);
o2.delete(3);
o2.insert('still am');
o2.retain(15);
o2.insert('!!');

const composed = o.compose(o2);
console.log(composed);
// TextOperation {
//   ops:
//    [ TextOp { type: 'retain', chars: 2, text: null, attributes: {} },
//      TextOp { type: 'insert', chars: null, text: 'still am', attributes: {} },
//      TextOp { type: 'delete', chars: 2, text: null, attributes: null },
//      TextOp { type: 'retain', chars: 14, text: null, attributes: {} },
//      TextOp { type: 'insert', chars: null, text: '!!!!', attributes: {} } ],
//   baseLength: 18,
//   targetLength: 28 }

console.log(composed.apply(testString)); // I still am a test string!!!

// transformation example
const simpleString = 'abcdef';

const op1 = new TextOperation();
const op2 = new TextOperation();

op1.retain(6).insert('ghijk');
op2.retain(3).delete(3);
const transformed = op1.transform(op2);
console.log(transformed[0].toJSON(), transformed[1].toJSON()); // [ 3, 'ghijk' ] [ 3, -3, 5 ]

console.log(transformed[1].apply(op1.apply(simpleString))); // abcghijk

Contributing

This project welcomes code contributions, bug reports and feature requests. Please see the guidelines in CONTRIBUTING.md if you are interested in contributing.