pi-hashline-edit-pro 0.12.0 → 0.12.1
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/package.json +1 -1
- package/src/replace-normalize.ts +16 -0
package/package.json
CHANGED
package/src/replace-normalize.ts
CHANGED
|
@@ -29,6 +29,20 @@ function coerceContentLines(changes: unknown): unknown {
|
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
function coerceChangeItems(changes: unknown): unknown {
|
|
33
|
+
if (!Array.isArray(changes)) return changes;
|
|
34
|
+
return changes.map((item: unknown) => {
|
|
35
|
+
if (typeof item !== "string") return item;
|
|
36
|
+
try {
|
|
37
|
+
const parsed: unknown = JSON.parse(item);
|
|
38
|
+
if (isRec(parsed)) return parsed;
|
|
39
|
+
} catch {
|
|
40
|
+
// not valid JSON, leave as-is for downstream validation
|
|
41
|
+
}
|
|
42
|
+
return item;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
32
46
|
export function normReq(input: unknown): unknown {
|
|
33
47
|
if (!isRec(input)) {
|
|
34
48
|
return input;
|
|
@@ -46,10 +60,12 @@ export function normReq(input: unknown): unknown {
|
|
|
46
60
|
|
|
47
61
|
if (hasChangesField) {
|
|
48
62
|
record.changes = coerceChangesArray(record.changes);
|
|
63
|
+
record.changes = coerceChangeItems(record.changes);
|
|
49
64
|
record.changes = coerceContentLines(record.changes);
|
|
50
65
|
} else if (hasEditsField) {
|
|
51
66
|
// Accept "edits" as an alias for "changes" for backward compatibility
|
|
52
67
|
record.changes = coerceChangesArray(record.edits);
|
|
68
|
+
record.changes = coerceChangeItems(record.changes);
|
|
53
69
|
record.changes = coerceContentLines(record.changes);
|
|
54
70
|
delete record.edits;
|
|
55
71
|
}
|