Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@kizahasi/ot-string

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kizahasi/ot-string

Operational Transfomation library for string

  • 0.3.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
297
decreased by-13.16%
Maintainers
1
Weekly downloads
 
Created
Source

@kizahasi/ot-string

GitHub npm version minified size CI publish

Operational Transfomation library for string.

Installation

Run npm install @kizahasi/ot-string or yarn add @kizahasi/ot-string

Usage

import { TextTwoWayOperation, TextUpOperation, TextDownOperation } from '@kizahasi/ot-string';

// Gets diff of two string (diff-match-patch is used)
const twoWayOperation: TextTwoWayOperation.Operation = TextTwoWayOperation.diff({
    first: 'Roses are red',
    second: 'Violets are blue',
});

const upOperation: TextUpOperation.Operation = TextTwoWayOperation.toUpOperation(twoWayOperation);
const second = TextUpOperation.apply({
    prevState: 'Roses are red',
    action: upOperation,
});
/* second = 
{ isError: false, value: 'Violets are blue' }
*/

const downOperation: TextDownOperation.Operation =
    TextTwoWayOperation.toDownOperation(twoWayOperation);
const first = TextDownOperation.applyBack({
    nextState: 'Violets are blue',
    action: downOperation,
});
/* first =
{ isError: false, value: 'Roses are red' }
*/

// If you want to serialize a Text(Up|Down)Operation.Operation object, Text(Up|Down)Operation.toUpUnit helps you.
// (t = type, r = retain, i = insert, d = delete)
const upOperationAsUnitArray = TextUpOperation.toUnit(upOperation);
/* upOperationAsUnitArray =
[
    { t: 'd', d: 1 },
    { t: 'i', i: 'Vi' },
    { t: 'r', r: 1 },
    { t: 'd', d: 1 },
    { t: 'i', i: 'l' },
    { t: 'r', r: 1 },
    { t: 'i', i: 't' },
    { t: 'r', r: 6 },
    { t: 'd', d: 1 },
    { t: 'i', i: 'blu' },
    { t: 'r', r: 1 },
    { t: 'd', d: 1 }
]
*/
const downOperationAsUnitArray = TextDownOperation.toUnit(downOperation);
/* downOperationAsUnitArray =
[
    { t: 'd', d: 'R' },
    { t: 'i', i: 2 },
    { t: 'r', r: 1 },
    { t: 'd', d: 's' },
    { t: 'i', i: 1 },
    { t: 'r', r: 1 },
    { t: 'i', i: 1 },
    { t: 'r', r: 6 },
    { t: 'd', d: 'r' },
    { t: 'i', i: 3 },
    { t: 'r', r: 1 },
    { t: 'd', d: 'd' }
]
*/

// To convert back to Text(Up|Down)Operation.Operation, use ofUnit.
const upOperation2 = TextUpOperation.ofUnit(upOperationAsUnitArray);
// upOperation2 equals to upOperation
const downOperation2 = TextDownOperation.ofUnit(downOperationAsUnitArray);
// downOperation2 equals to downOperation

Issues

  • Because this library uses Typescipt namespace, tree-shaking may not work well to reduce the code size.
  • Some functions are not implemented (e.g. TextUpOperation.diff).

Keywords

FAQs

Package last updated on 11 Nov 2021

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc