mrkr 0.0.0 → 0.1.0
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/index.cjs +23 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +23 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -28,6 +28,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
28
28
|
markRef: ()=>markRef,
|
|
29
29
|
markable: ()=>markable
|
|
30
30
|
});
|
|
31
|
+
var _computedKey;
|
|
31
32
|
const mark = Symbol('mark');
|
|
32
33
|
class MarkRef {
|
|
33
34
|
references = new Set();
|
|
@@ -44,6 +45,7 @@ class MarkRef {
|
|
|
44
45
|
function markRef() {
|
|
45
46
|
return new MarkRef();
|
|
46
47
|
}
|
|
48
|
+
_computedKey = Symbol.toPrimitive;
|
|
47
49
|
class Markable extends String {
|
|
48
50
|
start = -1;
|
|
49
51
|
end = -1;
|
|
@@ -76,6 +78,27 @@ class Markable extends String {
|
|
|
76
78
|
for (const mark of this.marks)if (mark.ref === ref && (void 0 === from || mark.offset <= from)) lastOffset = mark.offset;
|
|
77
79
|
return lastOffset;
|
|
78
80
|
}
|
|
81
|
+
append(value) {
|
|
82
|
+
const newValue = this.toString() + value.toString();
|
|
83
|
+
const builder = new MarkableBuilder().withStart(this.start).withEnd(this.end + (value instanceof Markable ? value.length : 0)).withMarks([
|
|
84
|
+
...this.marks
|
|
85
|
+
]);
|
|
86
|
+
if (value instanceof Markable) for (const mark of value.marks)builder.withMarks([
|
|
87
|
+
...builder.marks,
|
|
88
|
+
{
|
|
89
|
+
offset: mark.offset + this.length,
|
|
90
|
+
ref: mark.ref
|
|
91
|
+
}
|
|
92
|
+
]);
|
|
93
|
+
return builder.build(newValue);
|
|
94
|
+
}
|
|
95
|
+
[_computedKey](hint) {
|
|
96
|
+
if ('string' === hint || 'default' === hint) {
|
|
97
|
+
console.warn("Warning: Implicit conversion of Markable to string. This may lead to loss of mark information. If it was intentional, consider using explicit methods like .toString() or .cut() instead. Use append() to concatenate Markable instances without losing marks.");
|
|
98
|
+
return this.toString();
|
|
99
|
+
}
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
79
102
|
}
|
|
80
103
|
class MarkableBuilder {
|
|
81
104
|
start = -1;
|
package/dist/index.d.ts
CHANGED
|
@@ -19,6 +19,8 @@ declare class Markable extends String {
|
|
|
19
19
|
cut(): string[];
|
|
20
20
|
offsetOf(ref: MarkRef, from?: number): number;
|
|
21
21
|
lastOffsetOf(ref: MarkRef, from?: number): number;
|
|
22
|
+
append(value: string | Markable): Markable;
|
|
23
|
+
[Symbol.toPrimitive](hint: string): string | null;
|
|
22
24
|
}
|
|
23
25
|
export declare const markable: (strings: TemplateStringsArray, ...values: any[]) => Markable;
|
|
24
26
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
var _computedKey;
|
|
1
2
|
const src_mark = Symbol('mark');
|
|
2
3
|
class MarkRef {
|
|
3
4
|
references = new Set();
|
|
@@ -14,6 +15,7 @@ class MarkRef {
|
|
|
14
15
|
function markRef() {
|
|
15
16
|
return new MarkRef();
|
|
16
17
|
}
|
|
18
|
+
_computedKey = Symbol.toPrimitive;
|
|
17
19
|
class Markable extends String {
|
|
18
20
|
start = -1;
|
|
19
21
|
end = -1;
|
|
@@ -46,6 +48,27 @@ class Markable extends String {
|
|
|
46
48
|
for (const mark of this.marks)if (mark.ref === ref && (void 0 === from || mark.offset <= from)) lastOffset = mark.offset;
|
|
47
49
|
return lastOffset;
|
|
48
50
|
}
|
|
51
|
+
append(value) {
|
|
52
|
+
const newValue = this.toString() + value.toString();
|
|
53
|
+
const builder = new MarkableBuilder().withStart(this.start).withEnd(this.end + (value instanceof Markable ? value.length : 0)).withMarks([
|
|
54
|
+
...this.marks
|
|
55
|
+
]);
|
|
56
|
+
if (value instanceof Markable) for (const mark of value.marks)builder.withMarks([
|
|
57
|
+
...builder.marks,
|
|
58
|
+
{
|
|
59
|
+
offset: mark.offset + this.length,
|
|
60
|
+
ref: mark.ref
|
|
61
|
+
}
|
|
62
|
+
]);
|
|
63
|
+
return builder.build(newValue);
|
|
64
|
+
}
|
|
65
|
+
[_computedKey](hint) {
|
|
66
|
+
if ('string' === hint || 'default' === hint) {
|
|
67
|
+
console.warn("Warning: Implicit conversion of Markable to string. This may lead to loss of mark information. If it was intentional, consider using explicit methods like .toString() or .cut() instead. Use append() to concatenate Markable instances without losing marks.");
|
|
68
|
+
return this.toString();
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
49
72
|
}
|
|
50
73
|
class MarkableBuilder {
|
|
51
74
|
start = -1;
|