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

libzap

Package Overview
Dependencies
Maintainers
7
Versions
103
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

libzap - npm Package Compare versions

Comparing version 0.0.77 to 0.0.78

lib/util/unicode_test.d.ts

13

lib/ot/subtract_test.js

@@ -6,2 +6,3 @@ "use strict";

const subtract_1 = require("./subtract");
const unicode_1 = require("../util/unicode");
describe("subtract", () => {

@@ -25,2 +26,12 @@ ([

{
a: { edit: { "#f": ["😆"] } },
r: { edit: { "#f": ["@"] } },
a1: { edit: { "#f": [1, "😆"] } },
want: { edit: { "#f": ["@", 1, -1] } },
preText: "",
raceText: "@",
race2Text: "😆@",
wantText: "@😆",
},
{
a: { edit: { "#f": ["B", -1] } },

@@ -109,3 +120,3 @@ r: { edit: { "#f": ["y", 1] } },

if (t.preText !== undefined && t.raceText !== undefined && t.wantText !== undefined && t.race2Text !== undefined) {
const aRaceText = textDoc_1.applyEdits(edits(t.a).concat(t.raceText.length - t.preText.length), t.raceText);
const aRaceText = textDoc_1.applyEdits(edits(t.a).concat(unicode_1.charLength(t.raceText) - unicode_1.charLength(t.preText)), t.raceText);
assert.equal(aRaceText, t.race2Text, "a applied to raceText != race2Text");

@@ -112,0 +123,0 @@ if (t.r) {

5

lib/ot/subtract.js

@@ -5,2 +5,3 @@ "use strict";

const diff_match_patch_1 = require("diff-match-patch");
const unicode_1 = require("../util/unicode");
let differ;

@@ -81,3 +82,3 @@ function subtract(a, a1, r) {

case diff_match_patch_1.DIFF_EQUAL:
ops.push(c[1].length);
ops.push(unicode_1.charLength(c[1]));
break;

@@ -88,3 +89,3 @@ case diff_match_patch_1.DIFF_INSERT:

case diff_match_patch_1.DIFF_DELETE:
ops[i] = -1 * c[1].length;
ops[i] = -1 * unicode_1.charLength(c[1]);
break;

@@ -91,0 +92,0 @@ }

@@ -7,3 +7,3 @@ "use strict";

[
{ ops: [1, "xyz", -2], want: "axyz" },
{ ops: [1, "xyz😎", -2], want: "axyz😎" },
{ ops: [3, "xyz"], want: "abcxyz" },

@@ -19,3 +19,3 @@ ].forEach(({ ops, want }) => {

{ ops: [-1], want: { ret: 0, del: 1, ins: 0 } },
{ ops: [1, "a", -1], want: { ret: 1, del: 1, ins: 1 } },
{ ops: [1, "a😎", -1], want: { ret: 1, del: 1, ins: 2 } },
].forEach(({ ops, want }) => {

@@ -36,3 +36,3 @@ it(`${JSON.stringify(ops)}`, () => assert.deepEqual(textDoc_1.countEdits(ops), want));

[
{ ops: [5, 2, 0, "a", "b", -3, 1, -2, -1], want: [7, "ab", -3, 1, -3] },
{ ops: [5, 2, 0, "a", "b", "😎", -3, 1, -2, -1], want: [7, "ab😎", -3, 1, -3] },
].forEach(({ ops, want }) => {

@@ -46,4 +46,4 @@ it(`${JSON.stringify(ops)}`, () => assert.deepEqual(textDoc_1.mergeEdits(ops), want));

a: [3],
b: ["abc", 3],
want: ["abc", 3],
b: ["abc😎", 3],
want: ["abc😎", 3],
},

@@ -61,4 +61,4 @@ {

{
a: [1, "abc"],
b: [2, -1, 1],
a: [1, "ab😎c"],
b: [2, -2, 1],
want: [1, "ac"],

@@ -95,6 +95,6 @@ },

{
a: [1, "abc", 2],
a: [1, "abc😎", 2],
b: [2, -1],
a1: [1, "abc", 1],
b1: [5, -1],
a1: [1, "abc😎", 1],
b1: [6, -1],
},

@@ -101,0 +101,0 @@ {

"use strict";
const unicode_1 = require("../util/unicode");
function noop(ops) {

@@ -12,4 +13,4 @@ return !ops || ops.length === 0 || ops.every(x => typeof x === "number" && x >= 0);

const { ret, del, ins } = countEdits(ops);
if (ret + del !== text.length) {
throw new Error(`base length must equal document length (${ret + del} != ${text.length})`);
if (ret + del !== unicode_1.charLength(text)) {
throw new Error(`base length must equal document length (${ret + del} != ${unicode_1.charLength(text)})`);
}

@@ -21,7 +22,7 @@ for (const op of ops) {

else if (typeof op === "number" && op < 0) {
text = text.slice(0, i) + text.slice(i + -op);
text = unicode_1.charSlice(text, 0, i) + unicode_1.charSlice(text, i + -op);
}
else if (typeof op === "string") {
text = text.slice(0, i) + op + text.slice(i);
i += op.length;
text = unicode_1.charSlice(text, 0, i) + op + unicode_1.charSlice(text, i);
i += unicode_1.charLength(op);
}

@@ -47,3 +48,3 @@ }

else if (typeof op === "string") {
ins += op.length;
ins += unicode_1.charLength(op);
}

@@ -188,5 +189,5 @@ }

else if (typeof oa === "string" && typeof ob === "number" && ob < 0) {
switch (Math.sign(oa.length + ob)) {
switch (Math.sign(unicode_1.charLength(oa) + ob)) {
case 1:
oa = oa.slice(-ob);
oa = unicode_1.charSlice(oa, -ob);
v = geteditop(ib, b);

@@ -197,3 +198,3 @@ ib = v.i;

case -1:
ob = ob + oa.length;
ob = ob + unicode_1.charLength(oa);
v = geteditop(ia, a);

@@ -214,6 +215,6 @@ ia = v.i;

else if (typeof oa === "string" && typeof ob === "number" && ob > 0) {
switch (Math.sign(oa.length - ob)) {
switch (Math.sign(unicode_1.charLength(oa) - ob)) {
case 1:
ab.push(oa.slice(0, ob));
oa = oa.slice(ob);
ab.push(unicode_1.charSlice(oa, 0, ob));
oa = unicode_1.charSlice(oa, ob);
v = geteditop(ib, b);

@@ -224,3 +225,3 @@ ib = v.i;

case -1:
ob = ob - oa.length;
ob = ob - unicode_1.charLength(oa);
ab.push(oa);

@@ -291,3 +292,3 @@ v = geteditop(ia, a);

if (typeof oa === "string" && oa) {
om = oa.length;
om = unicode_1.charLength(oa);
a1.push(oa);

@@ -301,3 +302,3 @@ b1.push(om);

if (typeof ob === "string" && ob) {
om = ob.length;
om = unicode_1.charLength(ob);
a1.push(om);

@@ -304,0 +305,0 @@ b1.push(ob);

@@ -173,3 +173,3 @@ "use strict";

const [exists, known] = opExists(op, d);
if (known && exists && !isBufferPath(d)) {
if (known && exists) {
throw new Error(`copy to: file ${d} file already exists`);

@@ -328,3 +328,3 @@ }

[exists, known] = opExists(op, d);
if (known && exists && !isBufferPath(d)) {
if (known && exists) {
throw new Error(`copy to: file ${d} file already exists`);

@@ -715,3 +715,3 @@ }

}
else if (destExists && destKnown && !isBufferPath(d)) {
else if (destExists && destKnown) {
throw new Error(`copy: file ${d} already exists - x: ${toString(x)} y: ${toString(y)}`);

@@ -718,0 +718,0 @@ }

@@ -7,3 +7,5 @@ "use strict";

{ a: "a", b: "a", want: [1] },
{ a: "\uD83D\uDE07", b: "\uD83D\uDE07", want: [1] },
{ a: "a", b: "b", want: [-1, "b"] },
{ a: "a", b: "\uD83D\uDE07", want: [-1, "\uD83D\uDE07"] },
{ a: "", b: "a", want: ["a"] },

@@ -10,0 +12,0 @@ { a: "a", b: "", want: [-1] },

"use strict";
const unicode_1 = require("./unicode");
const diff_match_patch_1 = require("diff-match-patch");

@@ -14,3 +15,3 @@ let differ;

case diff_match_patch_1.DIFF_EQUAL:
ops[i] = c[1].length;
ops[i] = unicode_1.charLength(c[1]);
break;

@@ -21,3 +22,3 @@ case diff_match_patch_1.DIFF_INSERT:

case diff_match_patch_1.DIFF_DELETE:
ops[i] = -1 * c[1].length;
ops[i] = -1 * unicode_1.charLength(c[1]);
break;

@@ -24,0 +25,0 @@ }

{
"name": "libzap",
"version": "0.0.77",
"version": "0.0.78",
"description": "JavaScript library for Zap",

@@ -5,0 +5,0 @@ "license": "none",

@@ -6,2 +6,3 @@ import * as assert from "assert";

import { subtract } from "./subtract";
import { charLength } from "../util/unicode";

@@ -28,2 +29,16 @@ describe("subtract", () => {

{
// 😆@ -> @😆 (same as above, but with an emoji)
a: { edit: { "#f": ["😆"] } }, // applied to "" -> "😆", applied to raceText -> "😆@"
r: { edit: { "#f": ["@"] } }, // applied to "" -> "@" (raceText)
a1: { edit: { "#f": [1, "😆"] } }, // applied to raceText "@" -> "@😆" (wantText)
// This want op differs from the equivalent test above
// (with "B" not "😆"), but the outcome is the same.
want: { edit: { "#f": ["@", 1, -1] } }, // applied to race2Text "😆@" -> "@😆" (wantText)
preText: "",
raceText: "@",
race2Text: "😆@",
wantText: "@😆",
},
{
a: { edit: { "#f": ["B", -1] } },

@@ -132,3 +147,3 @@ r: { edit: { "#f": ["y", 1] } },

if (t.preText !== undefined && t.raceText !== undefined && t.wantText !== undefined && t.race2Text !== undefined) {
const aRaceText = applyEdits(edits(t.a).concat(t.raceText.length - t.preText.length), t.raceText);
const aRaceText = applyEdits(edits(t.a).concat(charLength(t.raceText) - charLength(t.preText)), t.raceText);
assert.equal(aRaceText, t.race2Text, "a applied to raceText != race2Text");

@@ -135,0 +150,0 @@

import { EditOps, countEdits, applyEdits, noop } from "./textDoc";
import { normalize, WorkspaceOp, compose as composeWorkspaceOps, toString as opToString } from "./workspace";
import { diff_match_patch as DiffMatchPatch, DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT } from "diff-match-patch";
import { charLength } from "../util/unicode";

@@ -122,3 +123,3 @@ let differ: DiffMatchPatch;

case DIFF_EQUAL:
ops.push(c[1].length);
ops.push(charLength(c[1]));
break;

@@ -131,3 +132,3 @@

case DIFF_DELETE:
ops[i] = -1 * c[1].length;
ops[i] = -1 * charLength(c[1]);
break;

@@ -134,0 +135,0 @@ }

@@ -8,3 +8,3 @@ import * as assert from "assert";

[
{ ops: [1, "xyz", -2], want: "axyz" },
{ ops: [1, "xyz😎", -2], want: "axyz😎" },
{ ops: [3, "xyz"], want: "abcxyz" },

@@ -21,3 +21,3 @@ ].forEach(({ops, want}) => {

{ ops: [-1], want: { ret: 0, del: 1, ins: 0 } },
{ ops: [1, "a", -1], want: { ret: 1, del: 1, ins: 1 } },
{ ops: [1, "a😎", -1], want: { ret: 1, del: 1, ins: 2 } },
].forEach(({ops, want}) => {

@@ -40,3 +40,3 @@ it(`${JSON.stringify(ops)}`, () => assert.deepEqual(countEdits(ops), want));

[
{ ops: [5, 2, 0, "a", "b", -3, 1, -2, -1], want: [7, "ab", -3, 1, -3] },
{ ops: [5, 2, 0, "a", "b", "😎", -3, 1, -2, -1], want: [7, "ab😎", -3, 1, -3] },
].forEach(({ops, want}) => {

@@ -51,4 +51,4 @@ it(`${JSON.stringify(ops)}`, () => assert.deepEqual(mergeEdits(ops), want));

a: [3],
b: ["abc", 3],
want: ["abc", 3],
b: ["abc😎", 3],
want: ["abc😎", 3],
},

@@ -66,4 +66,4 @@ {

{
a: [1, "abc"],
b: [2, -1, 1],
a: [1, "ab😎c"],
b: [2, -2, 1],
want: [1, "ac"],

@@ -101,6 +101,6 @@ },

{
a: [1, "abc", 2],
a: [1, "abc😎", 2],
b: [2, -1],
a1: [1, "abc", 1],
b1: [5, -1],
a1: [1, "abc😎", 1],
b1: [6, -1],
},

@@ -107,0 +107,0 @@ {

@@ -0,1 +1,3 @@

import { charLength, charSlice } from "../util/unicode";
export type EditOp = number | string; // number is retain/delete, string is insert

@@ -14,4 +16,4 @@ export type EditOps = EditOp[];

const {ret, del, ins} = countEdits(ops);
if (ret + del !== text.length) {
throw new Error(`base length must equal document length (${ret + del} != ${text.length})`);
if (ret + del !== charLength(text)) {
throw new Error(`base length must equal document length (${ret + del} != ${charLength(text)})`);
}

@@ -22,6 +24,6 @@ for (const op of ops) {

} else if (typeof op === "number" && op < 0) {
text = text.slice(0, i) + text.slice(i + -op);
text = charSlice(text, 0, i) + charSlice(text, i + -op);
} else if (typeof op === "string") {
text = text.slice(0, i) + op + text.slice(i);
i += op.length;
text = charSlice(text, 0, i) + op + charSlice(text, i);
i += charLength(op);
}

@@ -45,3 +47,3 @@ }

} else if (typeof op === "string") {
ins += op.length;
ins += charLength(op);
}

@@ -166,9 +168,9 @@ }

} else if (typeof oa === "string" && typeof ob === "number" && ob < 0) { // insert delete
switch (Math.sign(oa.length + ob)) {
switch (Math.sign(charLength(oa) + ob)) {
case 1:
oa = oa.slice(-ob);
oa = charSlice(oa, -ob);
v = geteditop(ib, b); ib = v.i; ob = v.o;
break;
case -1:
ob = ob + oa.length;
ob = ob + charLength(oa);
v = geteditop(ia, a); ia = v.i; oa = v.o;

@@ -182,10 +184,10 @@ break;

} else if (typeof oa === "string" && typeof ob === "number" && ob > 0) { // insert retain
switch (Math.sign(oa.length - ob)) {
switch (Math.sign(charLength(oa) - ob)) {
case 1:
ab.push(oa.slice(0, ob));
oa = oa.slice(ob);
ab.push(charSlice(oa, 0, ob));
oa = charSlice(oa, ob);
v = geteditop(ib, b); ib = v.i; ob = v.o;
break;
case -1:
ob = ob - oa.length;
ob = ob - charLength(oa);
ab.push(oa);

@@ -242,3 +244,3 @@ v = geteditop(ia, a); ia = v.i; oa = v.o;

if (typeof oa === "string" && oa) { // insert a
om = oa.length;
om = charLength(oa);
a1.push(oa);

@@ -250,3 +252,3 @@ b1.push(om);

if (typeof ob === "string" && ob) { // insert b
om = ob.length;
om = charLength(ob);
a1.push(om);

@@ -253,0 +255,0 @@ b1.push(ob);

@@ -9,3 +9,5 @@ import * as assert from "assert";

{ a: "a", b: "a", want: [1] },
{ a: "\uD83D\uDE07", b: "\uD83D\uDE07", want: [1] },
{ a: "a", b: "b", want: [-1, "b"] },
{ a: "a", b: "\uD83D\uDE07", want: [-1, "\uD83D\uDE07"] },
{ a: "", b: "a", want: ["a"] },

@@ -12,0 +14,0 @@ { a: "a", b: "", want: [-1] },

import { EditOps } from "../ot/textDoc";
import { charLength } from "./unicode";

@@ -23,3 +24,3 @@ import { diff_match_patch as DiffMatchPatch, DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT } from "diff-match-patch";

case DIFF_EQUAL:
ops[i] = c[1].length;
ops[i] = charLength(c[1]);
break;

@@ -32,3 +33,3 @@

case DIFF_DELETE:
ops[i] = -1 * c[1].length;
ops[i] = -1 * charLength(c[1]);
break;

@@ -35,0 +36,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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