You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.4 KiB
51 lines
1.4 KiB
export function getName(name, mode, ios, md) { |
|
mode = (mode || 'md').toLowerCase(); |
|
if (ios && mode === 'ios') { |
|
name = ios.toLowerCase(); |
|
} |
|
else if (md && mode === 'md') { |
|
name = md.toLowerCase(); |
|
} |
|
else if (name) { |
|
name = name.toLowerCase(); |
|
if (!/^md-|^ios-|^logo-/.test(name)) { |
|
name = `${mode}-${name}`; |
|
} |
|
} |
|
if (typeof name !== 'string' || name.trim() === '') { |
|
return null; |
|
} |
|
const invalidChars = name.replace(/[a-z]|-|\d/gi, ''); |
|
if (invalidChars !== '') { |
|
return null; |
|
} |
|
return name; |
|
} |
|
export function getSrc(src) { |
|
if (typeof src === 'string') { |
|
src = src.trim(); |
|
if (src.length > 0 && /(\/|\.)/.test(src)) { |
|
return src; |
|
} |
|
} |
|
return null; |
|
} |
|
export function isValid(elm) { |
|
if (elm.nodeType === 1) { |
|
if (elm.nodeName.toLowerCase() === 'script') { |
|
return false; |
|
} |
|
for (let i = 0; i < elm.attributes.length; i++) { |
|
const val = elm.attributes[i].value; |
|
if (typeof val === 'string' && val.toLowerCase().indexOf('on') === 0) { |
|
return false; |
|
} |
|
} |
|
for (let i = 0; i < elm.childNodes.length; i++) { |
|
if (!isValid(elm.childNodes[i])) { |
|
return false; |
|
} |
|
} |
|
} |
|
return true; |
|
}
|
|
|