Skip to content

Commit

Permalink
MM-18913: Migrate latinise.tsx and tests to Typescript (mattermost#3821)
Browse files Browse the repository at this point in the history
* Migrate latinise.tsx and tests to Typescript

* Remove inner describe
  • Loading branch information
cedrickring authored and cpanato committed Oct 2, 2019
1 parent c9c7a78 commit 0d988eb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 27 deletions.
23 changes: 0 additions & 23 deletions utils/latinise.test.jsx

This file was deleted.

21 changes: 21 additions & 0 deletions utils/latinise.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import {latinise} from 'utils/latinise';

describe('Latinise', () => {
test('should return ascii version of Dév Spé', () => {
expect(latinise('Dév Spé')).
toEqual('Dev Spe');
});

test('should not replace any characters', () => {
expect(latinise('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890')).
toEqual('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890');
});

test('should replace characters with diacritics with ascii equivalents', () => {
expect(latinise('àáâãäåæçèéêëìíîïñòóôõöœùúûüýÿ')).
toEqual('aaaaaaaeceeeeiiiinooooooeuuuuyy');
});
});
6 changes: 3 additions & 3 deletions utils/latinise.jsx → utils/latinise.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

var latinMap = {
const latinMap: { [key: string]: string } = {
Á: 'A', // LATIN CAPITAL LETTER A WITH ACUTE
Ă: 'A', // LATIN CAPITAL LETTER A WITH BREVE
: 'A', // LATIN CAPITAL LETTER A WITH BREVE AND ACUTE
Expand Down Expand Up @@ -993,10 +993,10 @@ var latinMap = {
: 'x', // LATIN SUBSCRIPT SMALL LETTER X
};

export function map(x) {
export function map(x: string) {
return latinMap[x] || x;
}

export function latinise(input) {
export function latinise(input: string) {
return input.replace(/[^A-Za-z0-9]/g, map);
}
2 changes: 1 addition & 1 deletion utils/url.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import {latinise} from 'utils/latinise.jsx';
import {latinise} from 'utils/latinise';

export function cleanUpUrlable(input) {
var cleaned = latinise(input);
Expand Down

0 comments on commit 0d988eb

Please sign in to comment.