1
0
Fork 0

basic editor interface

This commit is contained in:
Enoch Riese 2022-12-14 16:37:17 -06:00
parent 57dc0e929b
commit ed3f0abf23
3 changed files with 123 additions and 1 deletions

View file

@ -0,0 +1,53 @@
import defaultSettings from './default-settings'
class GistValidator {
givenGist
design
errors
valid = true
constructor(givenGist, design) {
this.givenGist = givenGist
this.design = design
this.errors = {}
}
validateSettings() {
for (var key in defaultSettings) {
if (typeof this.givenGist[key] !== typeof defaultSettings[key]) {
this.errors[key] = 'TypeError'
this.valid = false
}
}
}
validateMeasurements() {
this.errors.measurements = {}
for (const m of this.design.patternConfig.measurements || []) {
if (this.givenGist.measurements[m] === undefined) {
this.errors.measurements[m] = 'MissingMeasurement'
this.valid = false
} else if (isNaN(this.givenGist.measurements[m])) {
this.errors.measurements[m] = 'TypeError'
this.valid = false
}
}
}
validateOptions() {
console.log(this.design.patternConfig)
}
validate() {
this.validateSettings()
this.validateMeasurements()
this.validateOptions()
return { valid: this.valid, errors: this.errors }
}
}
export default function validateGist(givenGist, design) {
const validator = new GistValidator(givenGist, design)
return validator.validate()
}