aboutsummaryrefslogtreecommitdiff
path: root/src/tools/text-to-unicode/text-to-unicode.service.ts
diff options
context:
space:
mode:
authorGravatar hieudt-2054 <55786352+hieudt-2054@users.noreply.github.com> 2024-01-31 16:55:18 +0700
committerGravatar GitHub <noreply@github.com> 2024-01-31 09:55:18 +0000
commitc46207f1bb9fcd0691898be63bd20dfb5164de4b (patch)
tree5dcd90771eefeee5a9a1310e0a6f7b21095db920 /src/tools/text-to-unicode/text-to-unicode.service.ts
parent670f735501b5830ad31af52ef7cdaa17e9e51bab (diff)
downloadit-tools-c46207f1bb9fcd0691898be63bd20dfb5164de4b.tar.gz
it-tools-c46207f1bb9fcd0691898be63bd20dfb5164de4b.tar.zst
it-tools-c46207f1bb9fcd0691898be63bd20dfb5164de4b.zip
feat(new-tool): added unicode conversion utilities (#858)
* feat: add Text to Unicode tool * Update src/tools/text-to-unicode/index.ts --------- Co-authored-by: Corentin THOMASSET <corentin.thomasset74@gmail.com>
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 };