"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/xmlbuilder/lib/XMLBuilder.js" (8 Mar 2017, 3963 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 // Generated by CoffeeScript 1.3.3
    2 (function() {
    3   var XMLBuilder, XMLFragment,
    4     __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
    5 
    6   XMLFragment = require('./XMLFragment');
    7 
    8   XMLBuilder = (function() {
    9 
   10     function XMLBuilder(name, xmldec, doctype, options) {
   11       this.assertLegalChar = __bind(this.assertLegalChar, this);
   12 
   13       var att, child, _ref;
   14       this.children = [];
   15       this.rootObject = null;
   16       if (this.is(name, 'Object')) {
   17         _ref = [name, xmldec], xmldec = _ref[0], doctype = _ref[1];
   18         name = null;
   19       }
   20       if (name != null) {
   21         name = '' + name || '';
   22         if (xmldec == null) {
   23           xmldec = {
   24             'version': '1.0'
   25           };
   26         }
   27       }
   28       this.allowSurrogateChars = options != null ? options.allowSurrogateChars : void 0;
   29       if ((xmldec != null) && !(xmldec.version != null)) {
   30         throw new Error("Version number is required");
   31       }
   32       if (xmldec != null) {
   33         xmldec.version = '' + xmldec.version || '';
   34         if (!xmldec.version.match(/1\.[0-9]+/)) {
   35           throw new Error("Invalid version number: " + xmldec.version);
   36         }
   37         att = {
   38           version: xmldec.version
   39         };
   40         if (xmldec.encoding != null) {
   41           xmldec.encoding = '' + xmldec.encoding || '';
   42           if (!xmldec.encoding.match(/[A-Za-z](?:[A-Za-z0-9._-]|-)*/)) {
   43             throw new Error("Invalid encoding: " + xmldec.encoding);
   44           }
   45           att.encoding = xmldec.encoding;
   46         }
   47         if (xmldec.standalone != null) {
   48           att.standalone = xmldec.standalone ? "yes" : "no";
   49         }
   50         child = new XMLFragment(this, '?xml', att);
   51         this.children.push(child);
   52       }
   53       if (doctype != null) {
   54         att = {};
   55         if (name != null) {
   56           att.name = name;
   57         }
   58         if (doctype.ext != null) {
   59           doctype.ext = '' + doctype.ext || '';
   60           att.ext = doctype.ext;
   61         }
   62         child = new XMLFragment(this, '!DOCTYPE', att);
   63         this.children.push(child);
   64       }
   65       if (name != null) {
   66         this.begin(name);
   67       }
   68     }
   69 
   70     XMLBuilder.prototype.begin = function(name, xmldec, doctype) {
   71       var doc, root;
   72       if (!(name != null)) {
   73         throw new Error("Root element needs a name");
   74       }
   75       if (this.rootObject) {
   76         this.children = [];
   77         this.rootObject = null;
   78       }
   79       if (xmldec != null) {
   80         doc = new XMLBuilder(name, xmldec, doctype);
   81         return doc.root();
   82       }
   83       name = '' + name || '';
   84       root = new XMLFragment(this, name, {});
   85       root.isRoot = true;
   86       root.documentObject = this;
   87       this.children.push(root);
   88       this.rootObject = root;
   89       return root;
   90     };
   91 
   92     XMLBuilder.prototype.root = function() {
   93       return this.rootObject;
   94     };
   95 
   96     XMLBuilder.prototype.end = function(options) {
   97       return toString(options);
   98     };
   99 
  100     XMLBuilder.prototype.toString = function(options) {
  101       var child, r, _i, _len, _ref;
  102       r = '';
  103       _ref = this.children;
  104       for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  105         child = _ref[_i];
  106         r += child.toString(options);
  107       }
  108       return r;
  109     };
  110 
  111     XMLBuilder.prototype.is = function(obj, type) {
  112       var clas;
  113       clas = Object.prototype.toString.call(obj).slice(8, -1);
  114       return (obj != null) && clas === type;
  115     };
  116 
  117     XMLBuilder.prototype.assertLegalChar = function(str) {
  118       var chars, chr;
  119       if (this.allowSurrogateChars) {
  120         chars = /[\u0000-\u0008\u000B-\u000C\u000E-\u001F\uFFFE-\uFFFF]/;
  121       } else {
  122         chars = /[\u0000-\u0008\u000B-\u000C\u000E-\u001F\uD800-\uDFFF\uFFFE-\uFFFF]/;
  123       }
  124       chr = str.match(chars);
  125       if (chr) {
  126         throw new Error("Invalid character (" + chr + ") in string: " + str + " at index " + chr.index);
  127       }
  128     };
  129 
  130     return XMLBuilder;
  131 
  132   })();
  133 
  134   module.exports = XMLBuilder;
  135 
  136 }).call(this);