UNPKG

@doodad-js/xml

Version:
80 lines (67 loc) 1.89 kB
// Copyright 2015-2018 Claude Petit, licensed under Apache License version 2.0 "use strict"; exports.add = function add(modules) { modules = (modules || {}); modules['Doodad.Tools.Xml.Parsers.Sax.Loader'] = { version: '5.2.0b', dependencies: [ 'Doodad.Tools.Xml', ], create: function create(root, /*optional*/_options) { //=================================== // Get namespaces //=================================== const doodad = root.Doodad, //types = doodad.Types, tools = doodad.Tools, modules = doodad.Modules, xml = tools.Xml, xmlParsers = xml.Parsers, sax = xmlParsers.Sax, saxLoader = sax.Loader; //=================================== // Internal //=================================== // <FUTURE> Thread context const __Internal__ = { saxlib: null, }; //=================================== // SAX Parser //=================================== // NOTE: SAX is optional saxLoader.ADD('get', root.DD_DOC( { author: "Claude Petit", revision: 1, params: null, returns: 'object', description: "Returns parser from the SAX-JS library when available. Otherwise, returns 'null'.", } , function get() { return __Internal__.saxlib; })); //=================================== // Init //=================================== return function init(/*optional*/options) { //return modules.import('sax') // .catch(function(err) { // // Do nothing. // }); return modules.import('sax') .catch(function(err) { // <PRB> NPM doesn't flatten packages return modules.import('@doodad-js/xml/node_modules/sax'); }) .then(function(exports) { __Internal__.saxlib = exports.default; }) .catch(function(err) { // Do nothing. }); }; }, }; return modules; };