/
dimamir
/
node-xml-toolkit
Обзор
Документация
Войти
/
dimamir
/
node-xml-toolkit
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
lib/XMLIterator.js
57 строк
1 KB
Dmitry Ovsyanko
XMLIterator test coverage
05 ноя 2024, 20:23
05 ноя 2024, 20:23
945e5c6
Код
Авторство
О чём код?
const XMLNode = require ('./XMLNode.js') const SAXEvent = require ('./SAXEvent.js') const EntityResolver = require ('./EntityResolver.js') const XMLIterator = class { constructor (src, options = {}) { this.src = src this.options = options this.pos = 0 this.selfEnclosed = null this.entityResolver = options.entityResolver ?? new EntityResolver () } [Symbol.iterator] () { return this; } autoClose () { let value = this.selfEnclosed value.type = SAXEvent.TYPES.END_ELEMENT this.selfEnclosed = null return {value} } next () { if (this.selfEnclosed !== null) return this.autoClose () const {src, pos, entityResolver} = this if (src.length - pos < 1) return {done: true} const value = new XMLNode (src.slice (pos), entityResolver) value.trim () const {length} = value.src; if (length === 0) return {done: true} this.pos += length if (value.isStartElement && value.isSelfEnclosed) this.selfEnclosed = value return {value} } } module.exports = XMLIterator