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.

33 lines
654 B

2 years ago
  1. 'use strict'
  2. let Container = require('./container')
  3. let LazyResult, Processor
  4. class Document extends Container {
  5. constructor(defaults) {
  6. // type needs to be passed to super, otherwise child roots won't be normalized correctly
  7. super({ type: 'document', ...defaults })
  8. if (!this.nodes) {
  9. this.nodes = []
  10. }
  11. }
  12. toResult(opts = {}) {
  13. let lazy = new LazyResult(new Processor(), this, opts)
  14. return lazy.stringify()
  15. }
  16. }
  17. Document.registerLazyResult = dependant => {
  18. LazyResult = dependant
  19. }
  20. Document.registerProcessor = dependant => {
  21. Processor = dependant
  22. }
  23. module.exports = Document
  24. Document.default = Document