All files / src/elements Root.ts

87.5% Statements 7/8
87.5% Branches 7/8
66.66% Functions 2/3
87.5% Lines 7/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42                                                64x 64x 64x 64x     64x   64x           32x      
import Document from './Document'
import Template from './Template'
 
export type RootAttributes = {
    seed?: string
    locale?: string
    debug?: string
}
 
export interface RootConstructor {
    $: RootAttributes
    Document: Document
    Template?: Template | Template[]
}
 
export default class Root {
    public $: RootAttributes
    public seed?: number
    public locale?: string
    public debug?: boolean
    public Document: Document
    public Template?: Template | Template[] 
 
    constructor(opts: RootConstructor) {
        this.$ = opts.$
        this.seed = opts?.$?.seed !== undefined ? +(opts.$.seed) : undefined
        this.locale = opts?.$?.locale ?? undefined
        this.debug = opts?.$?.debug === 'true'
 
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
        this.Document = new Document(opts.Document as any)
 
        this.Template = Array.isArray(opts.Template)
            ? opts.Template.map(tmpl => new Template(tmpl))
            : opts.Template && new Template(opts.Template)
    }
 
    public toString(): string {
        return this.Document.toString()
    }
}