aboutsummaryrefslogtreecommitdiff
path: root/src/tools/text-to-unicode/text-to-unicode.service.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/text-to-unicode/text-to-unicode.service.ts')
-rw-r--r--src/tools/text-to-unicode/text-to-unicode.service.ts9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/tools/text-to-unicode/text-to-unicode.service.ts b/src/tools/text-to-unicode/text-to-unicode.service.ts
new file mode 100644
index 0000000..e7772cf
--- /dev/null
+++ b/src/tools/text-to-unicode/text-to-unicode.service.ts
@@ -0,0 +1,9 @@
+function convertTextToUnicode(text: string): string {
+ return text.split('').map(value => `&#${value.charCodeAt(0)};`).join('');
+}
+
+function convertUnicodeToText(unicodeStr: string): string {
+ return unicodeStr.replace(/&#(\d+);/g, (match, dec) => String.fromCharCode(dec));
+}
+
+export { convertTextToUnicode, convertUnicodeToText };