Add styleJSONseemsValid function

This commit is contained in:
Rob Garrison 2019-04-16 04:59:12 -05:00
parent e44426b879
commit 94a940f933
2 changed files with 14 additions and 8 deletions

View File

@ -96,3 +96,14 @@ function calcStyleDigest(style) {
return parts.join('');
}
}
function styleJSONseemsValid(json) {
return json
&& json.name
&& json.name.trim()
&& Array.isArray(json.sections)
&& json.sections
&& json.sections.length
&& typeof json.sections.every === 'function'
&& typeof json.sections[0].code === 'string';
}

View File

@ -1,5 +1,6 @@
/* global messageBox styleSectionsEqual getOwnTab API onDOMready
tryJSONparse scrollElementIntoView $ $$ API $create t animateElement */
tryJSONparse scrollElementIntoView $ $$ API $create t animateElement
styleJSONseemsValid */
'use strict';
const STYLISH_DUMP_FILE_EXT = '.txt';
@ -144,13 +145,7 @@ function importFromString(jsonString) {
.then(done);
function analyze(item, index) {
if (typeof item !== 'object' ||
!item ||
!item.name ||
!item.name.trim() ||
!item.sections ||
!Array.isArray(item.sections)
) {
if (typeof item !== 'object' || !styleJSONseemsValid(item)) {
stats.invalid.names.push(`#${index}: ${limitString(item && item.name || '')}`);
return;
}