Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@kizahasi/ot-string
Advanced tools
Operational Transfomation library for string.
Run npm install @kizahasi/ot-string
or yarn add @kizahasi/ot-string
.
To use it in a browser directly, you can use Skypack.
import { diff } from '@kizahasi/ot-string';
const prevState = 'January';
const nextState = 'February';
const twoWayOperation = diff({ prevState, nextState });
import { diff, toUpoperation, apply, toDownOperation, applyBack } from '@kizahasi/ot-string';
const prevState = 'January';
const nextState = 'February';
const twoWayOperation = diff({ prevState, nextState });
// `toUpOperation` drops some data from twoWayOperation, but its object size is reduced.
const upOperation = toUpOperation(twoWayOperation);
const nextState2 = apply({ prevState, upOperation });
console.log(nextState2.isError, nextState2.value);
// => false February
// `toDownOperation` drops some data from twoWayOperation, but its object size is reduced.
const downOperation = toDownOperation(twoWayOperation);
const prevState2 = applyBack({ prevState, upOperation });
console.log(nextState2.isError, nextState2.value);
// => false January
import { toUpOperation, diff, transformUpOperation, apply } from '@kizahasi/ot-string';
const state1 = 'June 1';
const state2_june2 = 'June 2';
const state2_july1 = 'July 1';
const first = toUpOperation(diff({ prevState: state1, nextState: state2_june2 }));
const second = toUpOperation(diff({ prevState: state1, nextState: state2_july1 }));
const transformed = transformUpOperation({ first, second });
console.log(transformed.isError);
// => false
// state1 + first + secondPrime
const state3a = apply({ prevState: state2_june2, upOperation: transformed.value.secondPrime });
// state1 + second + firstPrime
const state3b = apply({ prevState: state2_july1, upOperation: transformed.value.firstPrime });
console.log(state3a.isError);
// => false
console.log(state3b.isError);
// => false
console.log(state3a.value === 'July 2');
// => true
// state1 + first + secondPrime = state1 + second + firstPrime
console.log(state3a.value === state3b.value);
// => true
import {
diff,
toDownOperation,
toUpOperation,
serializeUpOperation,
serializeDownOperation,
deserializeUpOperation,
deserializeDownOperation,
deserializeTwoWayOperation,
} from '@kizahasi/ot-string';
const twoWayOperation = diff({ prevState: 'hour', nextState: 'ours' });
const upOperation = toUpOperation(twoWayOperation);
const downOperation = toDownOperation(twoWayOperation);
// Serialize UpOperation.
const serializedUpOperation = serializeUpOperation(upOperation);
console.log(serializedUpOperation);
// => [ { t: 'd', d: 1 }, { t: 'r', r: 3 }, { t: 'i', i: 's' } ]
// (t = type, r = retain, i = insert, d = delete. Above object indicates "Delete 1 character, then retain 3 characters, finally insert 's'.")
// Serialize DownOperation.
const serializedDownOperation = serializeDownOperation(downOperation);
console.log(serializedDownOperation);
// => [ { t: 'd', d: 'h' }, { t: 'r', r: 3 }, { t: 'i', i: 1 } ]
// Serialize TwoWayOperation.
const serializedTwoWayOperation = serializeTwoWayOperation(downOperation);
console.log(serializedDownOperation);
// => [ { t: 'd', d: 'h' }, { t: 'r', r: 3 }, { t: 'i', i: 's' } ]
// Deserialize.
const deserializedUpOperation = deserializeUpOperation(serializedUpOperation);
const deserializedDownOperation = deserializeDownOperation(serializedDownOperation);
const deserializedTwoWayOperation = deserializeTwoWayOperation(serializedTwoWayOperation);
FAQs
Operational Transfomation library for string
The npm package @kizahasi/ot-string receives a total of 432 weekly downloads. As such, @kizahasi/ot-string popularity was classified as not popular.
We found that @kizahasi/ot-string demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.