Skip to content

Commit fd44be4

Browse files
committed
Merge branch 'feat/text-to-unicode-names' into chore/all-my-stuffs
# Conflicts: # components.d.ts # package.json # pnpm-lock.yaml # src/components/TextareaCopyable.vue # src/tools/index.ts # vite.config.ts
2 parents de6604f + e220d4a commit fd44be4

File tree

8 files changed

+80
-0
lines changed

8 files changed

+80
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"@types/markdown-it": "^13.0.7",
8989
"@types/memorystream": "^0.3.4",
9090
"@types/sshpk": "^1.17.4",
91+
"@unicode/unicode-15.1.0": "^1.5.2",
9192
"@vicons/material": "^0.12.0",
9293
"@vicons/tabler": "^0.12.0",
9394
"@vueuse/core": "^10.11.1",

pnpm-lock.yaml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tools/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ import { tool as nginxFormatter } from './nginx-formatter';
8484
import { tool as potrace } from './potrace';
8585
import { tool as rmbNumbers } from './rmb-numbers';
8686
import { tool as sensitiveDataMasker } from './sensitive-data-masker';
87+
import { tool as textToUnicodeNames } from './text-to-unicode-names';
8788
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
8889
import { tool as numeronymGenerator } from './numeronym-generator';
8990
import { tool as macAddressGenerator } from './mac-address-generator';
@@ -220,6 +221,7 @@ export const toolsByCategory: ToolCategory[] = [
220221
textToNatoAlphabet,
221222
textToBinary,
222223
textToUnicode,
224+
textToUnicodeNames,
223225
yamlToJson,
224226
yamlToToml,
225227
jsonToYaml,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Language } from '@vicons/tabler';
2+
import { defineTool } from '../tool';
3+
4+
export const tool = defineTool({
5+
name: 'Text to Unicode Names',
6+
path: '/text-to-unicode-names',
7+
description: 'Convert a text to its hexadecimal character codes and Unicode Names for each character',
8+
keywords: ['text', 'unicode', 'name', 'hexa', 'char', 'code'],
9+
component: () => import('./text-to-unicode-names.vue'),
10+
icon: Language,
11+
createdAt: new Date('2024-06-10'),
12+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { describe, expect, it } from 'vitest';
2+
import { convertTextToUnicodeNames } from './text-to-unicode-names.service';
3+
4+
describe('text-to-unicode-names', () => {
5+
describe('convertTextToUnicodeNames', () => {
6+
it('a text string is converted to its unicode names representation', () => {
7+
expect(convertTextToUnicodeNames('A')).toBe(
8+
'A (U+0041: LATIN CAPITAL LETTER A)');
9+
expect(convertTextToUnicodeNames('hello')).toBe(
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)');
11+
expect(convertTextToUnicodeNames('')).toBe(
12+
'');
13+
expect(convertTextToUnicodeNames('être 1 $ ¤ …')).toBe(
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)');
15+
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)');
17+
});
18+
it('the separator between octets can be changed', () => {
19+
expect(convertTextToUnicodeNames('hello', { separator: ' ; ' })).toBe(
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)');
21+
});
22+
});
23+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import unicode from '@unicode/unicode-15.1.0/Names/index.js';
2+
3+
export function convertTextToUnicodeNames(text: string, { separator = ' ' }: { separator?: string } = {}): string {
4+
return [...text]
5+
.map(char => `${char} (U+${char.codePointAt(0)?.toString(16).toUpperCase().padStart(4, '0')}: ${(unicode.get(char.codePointAt(0)) || 'UNKNOWN CHARACTER')})`)
6+
.join(separator);
7+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<script setup lang="ts">
2+
import { convertTextToUnicodeNames } from './text-to-unicode-names.service';
3+
4+
const inputText = ref('');
5+
const unicodeNamesFromText = computed(() => convertTextToUnicodeNames(inputText.value, { separator: '\n' }));
6+
</script>
7+
8+
<template>
9+
<c-card title="Text to Unicode Names">
10+
<c-input-text
11+
v-model:value="inputText"
12+
multiline placeholder="e.g. 'Hello world'"
13+
label="Enter text to convert to Unicode Names"
14+
autosize autofocus raw-text
15+
/>
16+
<textarea-copyable
17+
v-model:value="unicodeNamesFromText"
18+
word-wrap
19+
label="Unicode Names from your text" multiline raw-text readonly mt-2
20+
placeholder="The Unicode Names representation of your text will be here"
21+
/>
22+
</c-card>
23+
</template>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module '@unicode/unicode-15.1.0/Names/index.js'{
2+
const unicode: HashSet<number, string>;
3+
export default unicode;
4+
}

0 commit comments

Comments
 (0)