always lowercase mode and name props

This commit is contained in:
Adam Bradley
2018-05-16 11:32:55 -05:00
parent d705685298
commit 08b5f4bb35
2 changed files with 7 additions and 3 deletions
+4
View File
@@ -146,6 +146,10 @@ describe('getName', () => {
expect(icon.getName('md-some-name', '', '', '')).toBe('md-some-name');
});
it('always lowercase name and mode', () => {
expect(icon.getName('SOME-NAME', 'IOS', '', '')).toBe('ios-some-name');
});
it('default md name w/out mode, ios or md', () => {
expect(icon.getName('some-name', '', '', '')).toBe('md-some-name');
});
+3 -3
View File
@@ -206,7 +206,7 @@ function getSvgContent(url: string) {
export function getName(name: string, mode: string, ios: string, md: string) {
// default to "md" if somehow the mode wasn't set
mode = mode || 'md';
mode = (mode || 'md').toLowerCase();
// if an icon was passed in using the ios or md attributes
// set the iconName to whatever was passed in
@@ -219,7 +219,7 @@ export function getName(name: string, mode: string, ios: string, md: string) {
} else if (name && !(/^md-|^ios-|^logo-/.test(name))) {
// this does not have one of the defaults
// so lets auto add in the mode prefix for them
name = mode + '-' + name;
name = mode + '-' + name.toLowerCase();
}
if (typeof name !== 'string' || name.trim() === '') {
@@ -227,7 +227,7 @@ export function getName(name: string, mode: string, ios: string, md: string) {
}
// only allow alpha characters and dash
const invalidChars = name.replace(/[a-z]|-|\d/g, '');
const invalidChars = name.replace(/[a-z]|-|\d/gi, '');
if (invalidChars !== '') {
return null;
}