mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-04 21:37:11 -04:00
Fix type checking issues
This commit is contained in:
parent
d75473b2e8
commit
7e90365657
3 changed files with 9 additions and 9 deletions
|
@ -43,7 +43,7 @@ describe('text-to-unicode', () => {
|
||||||
interface TestConfig {
|
interface TestConfig {
|
||||||
text: string
|
text: string
|
||||||
results: Record<ConverterId, string>
|
results: Record<ConverterId, string>
|
||||||
skipPrintableAscii?: boolean
|
skipAscii?: boolean
|
||||||
};
|
};
|
||||||
const tests: TestConfig[] = [
|
const tests: TestConfig[] = [
|
||||||
{
|
{
|
||||||
|
@ -57,7 +57,7 @@ describe('text-to-unicode', () => {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: 'ABC',
|
text: 'ABC',
|
||||||
skipPrintableAscii: true,
|
skipAscii: true,
|
||||||
results: {
|
results: {
|
||||||
fullUnicode: 'ABC',
|
fullUnicode: 'ABC',
|
||||||
utf16: 'ABC',
|
utf16: 'ABC',
|
||||||
|
@ -67,7 +67,7 @@ describe('text-to-unicode', () => {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: ALL_PRINTABLE_ASCII,
|
text: ALL_PRINTABLE_ASCII,
|
||||||
skipPrintableAscii: true,
|
skipAscii: true,
|
||||||
results: {
|
results: {
|
||||||
// eslint-disable-next-line unicorn/escape-case
|
// eslint-disable-next-line unicorn/escape-case
|
||||||
fullUnicode: String.raw` !\u0022#$%&\u0027()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\u005c]^_${'`'}abcdefghijklmnopqrstuvwxyz{|}~`,
|
fullUnicode: String.raw` !\u0022#$%&\u0027()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\u005c]^_${'`'}abcdefghijklmnopqrstuvwxyz{|}~`,
|
||||||
|
@ -90,7 +90,7 @@ describe('text-to-unicode', () => {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: 'a 💩 b',
|
text: 'a 💩 b',
|
||||||
skipPrintableAscii: true,
|
skipAscii: true,
|
||||||
results: {
|
results: {
|
||||||
// eslint-disable-next-line unicorn/escape-case
|
// eslint-disable-next-line unicorn/escape-case
|
||||||
fullUnicode: String.raw`a \u{1f4a9} b`,
|
fullUnicode: String.raw`a \u{1f4a9} b`,
|
||||||
|
@ -102,13 +102,13 @@ describe('text-to-unicode', () => {
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
for (const { text, skipPrintableAscii: skipAscii, results } of tests) {
|
for (const { text, skipAscii, results } of tests) {
|
||||||
describe(`${text} (skipAscii=${skipAscii})`, () => {
|
describe(`${text} (skipAscii=${skipAscii})`, () => {
|
||||||
for (const [key, result] of Object.entries(results)) {
|
for (const [key, result] of Object.entries(results)) {
|
||||||
describe(key, () => {
|
describe(key, () => {
|
||||||
const converter = converters[key as ConverterId];
|
const converter = converters[key as ConverterId];
|
||||||
it('Escaping', () => {
|
it('Escaping', () => {
|
||||||
expect(converter.escape(text, skipAscii)).toBe(result);
|
expect(converter.escape(text, skipAscii ?? false)).toBe(result);
|
||||||
});
|
});
|
||||||
it('Unescaping', () => {
|
it('Unescaping', () => {
|
||||||
expect(converter.unescape(result)).toBe(text);
|
expect(converter.unescape(result)).toBe(text);
|
||||||
|
|
|
@ -4,11 +4,11 @@ export const SKIP_ASCII_JS = /([ -!#-&(-\[\]-~]+)/g;
|
||||||
export const SKIP_ASCII_HTML = /([ -!#-%(-;=?-~]+)/g;
|
export const SKIP_ASCII_HTML = /([ -!#-%(-;=?-~]+)/g;
|
||||||
|
|
||||||
function codeUnits(text: string): number[] {
|
function codeUnits(text: string): number[] {
|
||||||
return text.split('').map(char => char.codePointAt(0));
|
return text.split('').map(char => char.codePointAt(0)!);
|
||||||
}
|
}
|
||||||
|
|
||||||
function codePoints(text: string): number[] {
|
function codePoints(text: string): number[] {
|
||||||
return [...text].map(char => char.codePointAt(0));
|
return [...text].map(char => char.codePointAt(0)!);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ConverterConfig {
|
interface ConverterConfig {
|
||||||
|
|
|
@ -27,7 +27,7 @@ const { copy: copyText } = useCopy({ source: textFromUnicode });
|
||||||
v-model:value="converterId"
|
v-model:value="converterId"
|
||||||
searchable
|
searchable
|
||||||
label="Conversion type:"
|
label="Conversion type:"
|
||||||
:options="Object.entries(converters).map(([key, val]) => ({ label: val.name, value: key }))"
|
:options="Object.entries(converters).map(([key, val]) => ({ label: val.config.name, value: key }))"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<c-card class="card" title="Text to Unicode">
|
<c-card class="card" title="Text to Unicode">
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue