@marcoappio/marco-config 2.0.168 → 2.0.169
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/utils/stringPatch/stringPatch.d.ts +12 -0
- package/dist/utils/stringPatch/stringPatch.d.ts.map +1 -0
- package/dist/utils/stringPatch/stringPatch.js +36 -0
- package/dist/utils/stringPatch/stringPatch.test.d.ts +2 -0
- package/dist/utils/stringPatch/stringPatch.test.d.ts.map +1 -0
- package/dist/utils/stringPatch/stringPatch.test.js +63 -0
- package/package.json +4 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type Instruction = {
|
|
2
|
+
index: number;
|
|
3
|
+
type: 'INSERTION' | 'DELETION';
|
|
4
|
+
value: string;
|
|
5
|
+
};
|
|
6
|
+
type Patch = Instruction[];
|
|
7
|
+
export declare const stringPatch: {
|
|
8
|
+
apply: (text: string, patch: Patch) => string;
|
|
9
|
+
create: (startText: string, endText: string) => Patch;
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=stringPatch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stringPatch.d.ts","sourceRoot":"","sources":["../../../src/utils/stringPatch/stringPatch.ts"],"names":[],"mappings":"AAEA,KAAK,WAAW,GAAG;IACjB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,WAAW,GAAG,UAAU,CAAA;IAC9B,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,KAAK,KAAK,GAAG,WAAW,EAAE,CAAA;AAE1B,eAAO,MAAM,WAAW;kBAEd,MAAM,SACL,KAAK,KACX,MAAM;wBAiBI,MAAM,WACR,MAAM,KACd,KAAK;CAmBT,CAAA"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { diffChars } from 'diff';
|
|
2
|
+
export const stringPatch = {
|
|
3
|
+
apply: (text, patch) => {
|
|
4
|
+
for (const instruction of patch) {
|
|
5
|
+
switch (instruction.type) {
|
|
6
|
+
case 'INSERTION': {
|
|
7
|
+
text = text.slice(0, instruction.index) + instruction.value + text.slice(instruction.index);
|
|
8
|
+
break;
|
|
9
|
+
}
|
|
10
|
+
case 'DELETION': {
|
|
11
|
+
text = text.slice(0, instruction.index) + text.slice(instruction.index + instruction.value.length);
|
|
12
|
+
break;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return text;
|
|
17
|
+
},
|
|
18
|
+
create: (startText, endText) => {
|
|
19
|
+
const charChanges = diffChars(startText, endText);
|
|
20
|
+
const patch = [];
|
|
21
|
+
let index = 0;
|
|
22
|
+
for (const change of charChanges) {
|
|
23
|
+
if (change.added) {
|
|
24
|
+
patch.push({ index, type: 'INSERTION', value: change.value });
|
|
25
|
+
index += change.value.length;
|
|
26
|
+
}
|
|
27
|
+
else if (change.removed) {
|
|
28
|
+
patch.push({ index, type: 'DELETION', value: change.value });
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
index += change.value.length;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return patch;
|
|
35
|
+
},
|
|
36
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stringPatch.test.d.ts","sourceRoot":"","sources":["../../../src/utils/stringPatch/stringPatch.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
import { stringPatch } from './stringPatch';
|
|
3
|
+
describe('stringPatch', () => {
|
|
4
|
+
const testCases = [
|
|
5
|
+
['hello world', 'hello beautiful world'],
|
|
6
|
+
['the quick brown fox', 'the slow brown fox'],
|
|
7
|
+
['', 'new content'],
|
|
8
|
+
['delete me', ''],
|
|
9
|
+
['no changes', 'no changes'],
|
|
10
|
+
['one two three', 'one three'],
|
|
11
|
+
['start middle end', 'start new middle end'],
|
|
12
|
+
['repeated repeated words', 'repeated words'],
|
|
13
|
+
['missing punctuation', 'missing, punctuation!'],
|
|
14
|
+
['old formatting', 'NEW FORMATTING'],
|
|
15
|
+
['extra spaces', 'extra spaces'],
|
|
16
|
+
['camelCase', 'snake_case'],
|
|
17
|
+
['this is a test', 'this is only a test'],
|
|
18
|
+
['remove last word test', 'remove last word'],
|
|
19
|
+
['beginning test', 'new beginning test'],
|
|
20
|
+
['[brackets]', '{curly brackets}'],
|
|
21
|
+
['line\nbreak', 'line break'],
|
|
22
|
+
['tab\tseparated', 'space separated'],
|
|
23
|
+
['numbers 123', 'numbers 456'],
|
|
24
|
+
['special chars !@#', 'different chars $%^'],
|
|
25
|
+
['uppercase TEXT', 'lowercase text'],
|
|
26
|
+
['trim this ', 'trim this'],
|
|
27
|
+
[' leading space', 'leading space'],
|
|
28
|
+
['mixed CASE text', 'all lower case text'],
|
|
29
|
+
['join these words', 'jointheseswords'],
|
|
30
|
+
['split,words,here', 'split words here'],
|
|
31
|
+
['version 1.0.0', 'version 2.0.0'],
|
|
32
|
+
['prefix-', 'prefix-added'],
|
|
33
|
+
['-suffix', 'added-suffix'],
|
|
34
|
+
['multi\nline\ntext', 'single line text'],
|
|
35
|
+
['short', 'much longer replacement'],
|
|
36
|
+
['very long original text', 'short'],
|
|
37
|
+
['kebab-case', 'camelCase'],
|
|
38
|
+
['PascalCase', 'camelCase'],
|
|
39
|
+
['duplicate duplicate', 'duplicate'],
|
|
40
|
+
[' multiple spaces ', 'single space'],
|
|
41
|
+
['<html>tags</html>', 'plain text'],
|
|
42
|
+
['quoted \'text\'', 'quoted "text"'],
|
|
43
|
+
['email@test.com', 'newemail@test.com'],
|
|
44
|
+
['http://old.url', 'http://new.url'],
|
|
45
|
+
['date: 2023-01-01', 'date: 2024-01-01'],
|
|
46
|
+
['rgb(255,0,0)', 'rgb(0,255,0)'],
|
|
47
|
+
['function(){\n}', 'function() {\n}'],
|
|
48
|
+
['snake_case_text', 'camelCaseText'],
|
|
49
|
+
['trailing comma,', 'no trailing comma'],
|
|
50
|
+
['...ellipsis', 'no ellipsis'],
|
|
51
|
+
['**markdown**', '_different markdown_'],
|
|
52
|
+
['(parentheses)', '[brackets]'],
|
|
53
|
+
['TRUE', 'false'],
|
|
54
|
+
['1234567890', '0987654321'],
|
|
55
|
+
];
|
|
56
|
+
for (const [start, end] of testCases) {
|
|
57
|
+
it(`should create a patch for ${start} to ${end}`, () => {
|
|
58
|
+
const patch = stringPatch.create(start, end);
|
|
59
|
+
const patched = stringPatch.apply(start, patch);
|
|
60
|
+
expect(patched).toBe(end);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marcoappio/marco-config",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.169",
|
|
4
4
|
"author": "team@marcoapp.io",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"repository": "git@github.com:marcoappio/marco-config.git",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@typescript-eslint/eslint-plugin": "5.62.0",
|
|
24
24
|
"@typescript-eslint/parser": "6.21.0",
|
|
25
|
+
"diff": "7.0.0",
|
|
25
26
|
"eslint": "8.41.0",
|
|
26
27
|
"eslint-plugin-import": "2.29.1",
|
|
27
28
|
"eslint-plugin-prefer-arrow": "1.2.3",
|
|
@@ -34,6 +35,8 @@
|
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
37
|
"@auto-it/npm": "11.2.0",
|
|
38
|
+
"@types/bun": "1.2.2",
|
|
39
|
+
"@types/diff": "7.0.1",
|
|
37
40
|
"auto": "11.2.0",
|
|
38
41
|
"tsc-alias": "1.8.10",
|
|
39
42
|
"typescript": "5.5.4"
|