[PLT-1444] Created latinise function and updated cleanUpUrlable function to utilize (#6273)

This commit is contained in:
chrismatteson
2017-05-15 07:09:39 -07:00
committed by Joram Wilander
parent 375cdbdb13
commit 4da45c0e76
3 changed files with 1030 additions and 1 deletions

View File

@@ -0,0 +1,23 @@
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import {latinise} from 'utils/latinise.jsx';
describe('Latinise', () => {
describe('handleNames', () => {
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');
});
});
});

1003
webapp/utils/latinise.jsx Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,8 +1,11 @@
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import {latinise} from 'utils/latinise.jsx';
export function cleanUpUrlable(input) {
var cleaned = input.trim().replace(/-/g, ' ').replace(/[^\w\s]/gi, '').toLowerCase().replace(/\s/g, '-');
var cleaned = latinise(input);
cleaned = cleaned.trim().replace(/-/g, ' ').replace(/[^\w\s]/gi, '').toLowerCase().replace(/\s/g, '-');
cleaned = cleaned.replace(/-{2,}/, '-');
cleaned = cleaned.replace(/^-+/, '');
cleaned = cleaned.replace(/-+$/, '');