Skip to content

Commit 44175e6

Browse files
authored
Merge pull request #11 from apicore-engineering/develop
add ZeroWithEncoder::cleanString
2 parents c7225d2 + 9904019 commit 44175e6

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

dist/index.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ type LiveTranslatorPluginOptions = {
1313
refreshRate?: number;
1414
checkVisibility?: boolean;
1515
};
16+
export declare abstract class ZeroWidthEncoder {
17+
static START: string;
18+
static ZERO: string;
19+
static ONE: string;
20+
static SPACE: string;
21+
static END: string;
22+
static PATTERN: RegExp;
23+
static encode(text: string): string;
24+
static decode(zeroWidth: string): string;
25+
static cleanString(str: string): string;
26+
}
1627
export declare const LiveTranslatorPlugin: {
1728
install(app: any, options: LiveTranslatorPluginOptions): void;
1829
};

dist/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function deepForIn(object, fn) {
8585
};
8686
forIn(object, iteratee);
8787
}
88-
class ZeroWidthEncoder {
88+
export class ZeroWidthEncoder {
8989
static START = '\u200B';
9090
static ZERO = '\u200C';
9191
static ONE = '\u200D';
@@ -132,6 +132,9 @@ class ZeroWidthEncoder {
132132
.join('');
133133
return text;
134134
}
135+
static cleanString(str) {
136+
return str.replaceAll(ZeroWidthEncoder.PATTERN, '');
137+
}
135138
}
136139
class Cache {
137140
_cache = {};
@@ -239,7 +242,7 @@ class LiveTranslatorManager {
239242
parts[i] = meta + parts[i];
240243
break;
241244
case 'restore':
242-
parts[i] = parts[i].replaceAll(ZeroWidthEncoder.PATTERN, '');
245+
parts[i] = ZeroWidthEncoder.cleanString(parts[i]);
243246
break;
244247
}
245248
}

src/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function deepForIn(object: Object, fn: (value: string, key: string) => void) {
104104
forIn(object, iteratee)
105105
}
106106

107-
abstract class ZeroWidthEncoder {
107+
export abstract class ZeroWidthEncoder {
108108
static START = '\u200B'
109109
static ZERO = '\u200C'
110110
static ONE = '\u200D'
@@ -153,6 +153,10 @@ abstract class ZeroWidthEncoder {
153153
.join('')
154154
return text
155155
}
156+
157+
static cleanString (str: string): string {
158+
return str.replaceAll(ZeroWidthEncoder.PATTERN, '')
159+
}
156160
}
157161

158162
type CacheElem = { value: Element, locked: boolean }
@@ -287,7 +291,7 @@ class LiveTranslatorManager {
287291
parts[i] = meta + parts[i]
288292
break
289293
case 'restore':
290-
parts[i] = parts[i].replaceAll(ZeroWidthEncoder.PATTERN, '')
294+
parts[i] = ZeroWidthEncoder.cleanString(parts[i])
291295
break
292296
}
293297
}

0 commit comments

Comments
 (0)