Skip to content

Commit e220d4a

Browse files
committed
fix: better display format (char, U+XXXX and name)
1 parent 0b84e26 commit e220d4a

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import { describe, expect, it } from 'vitest';
22
import { convertTextToUnicodeNames } from './text-to-unicode-names.service';
33

4-
describe('text-to-binary', () => {
4+
describe('text-to-unicode-names', () => {
55
describe('convertTextToUnicodeNames', () => {
66
it('a text string is converted to its unicode names representation', () => {
77
expect(convertTextToUnicodeNames('A')).toBe(
8-
'U+0041 (LATIN CAPITAL LETTER A)');
8+
'A (U+0041: LATIN CAPITAL LETTER A)');
99
expect(convertTextToUnicodeNames('hello')).toBe(
10-
'U+0068 (LATIN SMALL LETTER H) U+0065 (LATIN SMALL LETTER E) U+006C (LATIN SMALL LETTER L) U+006C (LATIN SMALL LETTER L) U+006F (LATIN SMALL LETTER O)');
10+
'h (U+0068: LATIN SMALL LETTER H) e (U+0065: LATIN SMALL LETTER E) l (U+006C: LATIN SMALL LETTER L) l (U+006C: LATIN SMALL LETTER L) o (U+006F: LATIN SMALL LETTER O)');
1111
expect(convertTextToUnicodeNames('')).toBe(
1212
'');
1313
expect(convertTextToUnicodeNames('être 1 $ ¤ …')).toBe(
14-
'U+00EA (LATIN SMALL LETTER E WITH CIRCUMFLEX) U+0074 (LATIN SMALL LETTER T) U+0072 (LATIN SMALL LETTER R) U+0065 (LATIN SMALL LETTER E) U+0020 (SPACE) U+0031 (DIGIT ONE) U+0020 (SPACE) U+0024 (DOLLAR SIGN) U+0020 (SPACE) U+00A4 (CURRENCY SIGN) U+0020 (SPACE) U+2026 (HORIZONTAL ELLIPSIS)');
14+
'ê (U+00EA: LATIN SMALL LETTER E WITH CIRCUMFLEX) t (U+0074: LATIN SMALL LETTER T) r (U+0072: LATIN SMALL LETTER R) e (U+0065: LATIN SMALL LETTER E) (U+0020: SPACE) 1 (U+0031: DIGIT ONE) (U+0020: SPACE) $ (U+0024: DOLLAR SIGN) (U+0020: SPACE) ¤ (U+00A4: CURRENCY SIGN) (U+0020: SPACE) … (U+2026: HORIZONTAL ELLIPSIS)');
1515
expect(convertTextToUnicodeNames('⁇ 𥆧 💩')).toBe(
16-
'U+2047 (DOUBLE QUESTION MARK) U+0020 (SPACE) U+251A7 (CJK Ideograph Extension B) U+0020 (SPACE) U+1F4A9 (PILE OF POO)');
16+
'⁇ (U+2047: DOUBLE QUESTION MARK) (U+0020: SPACE) 𥆧 (U+251A7: CJK Ideograph Extension B) (U+0020: SPACE) 💩 (U+1F4A9: PILE OF POO)');
1717
});
1818
it('the separator between octets can be changed', () => {
1919
expect(convertTextToUnicodeNames('hello', { separator: ' ; ' })).toBe(
20-
'U+0068 (LATIN SMALL LETTER H) ; U+0065 (LATIN SMALL LETTER E) ; U+006C (LATIN SMALL LETTER L) ; U+006C (LATIN SMALL LETTER L) ; U+006F (LATIN SMALL LETTER O)');
20+
'h (U+0068: LATIN SMALL LETTER H) ; e (U+0065: LATIN SMALL LETTER E) ; l (U+006C: LATIN SMALL LETTER L) ; l (U+006C: LATIN SMALL LETTER L) ; o (U+006F: LATIN SMALL LETTER O)');
2121
});
2222
});
2323
});

src/tools/text-to-unicode-names/text-to-unicode-names.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import unicode from '@unicode/unicode-15.1.0/Names/index.js';
22

33
export function convertTextToUnicodeNames(text: string, { separator = ' ' }: { separator?: string } = {}): string {
44
return [...text]
5-
.map(char => `U+${char.codePointAt(0)?.toString(16).toUpperCase().padStart(4, '0')} (${(unicode.get(char.codePointAt(0)) || 'UNKNOWN CHARACTER')})`)
5+
.map(char => `${char} (U+${char.codePointAt(0)?.toString(16).toUpperCase().padStart(4, '0')}: ${(unicode.get(char.codePointAt(0)) || 'UNKNOWN CHARACTER')})`)
66
.join(separator);
77
}

src/tools/text-to-unicode-names/text-to-unicode-names.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { convertTextToUnicodeNames } from './text-to-unicode-names.service';
33
44
const inputText = ref('');
5-
const unicodeNamesFromText = computed(() => convertTextToUnicodeNames(inputText.value));
5+
const unicodeNamesFromText = computed(() => convertTextToUnicodeNames(inputText.value, { separator: '\n' }));
66
</script>
77

88
<template>

0 commit comments

Comments
 (0)