First commit

This commit is contained in:
Thomas Fuhrmann 2023-10-02 15:04:02 +02:00
commit 87d22a4516
235 changed files with 51802 additions and 0 deletions

47
node_modules/xml-js/bin/cli-helper.js generated vendored Normal file
View file

@ -0,0 +1,47 @@
module.exports = {
getCommandLineHelp: function (command, requiredArgs, optionalArgs) {
var reqArgs = requiredArgs.reduce(function (res, arg) {return res + ' <' + arg.arg + '>';}, '');
var output = 'Usage: ' + command + reqArgs + ' [options]\n';
requiredArgs.forEach(function (argument) {
output += ' <' + argument.arg + '>' + Array(20 - argument.arg.length).join(' ') + argument.desc + '\n';
});
output += '\nOptions:\n';
optionalArgs.forEach(function (argument) {
output += ' --' + argument.arg + Array(20 - argument.arg.length).join(' ') + argument.desc + '\n';
});
return output;
},
mapCommandLineArgs: function (requiredArgs, optionalArgs) {
var options = {}, r, o, a = 2;
for (r = 0; r < requiredArgs.length; r += 1) {
if (a < process.argv.length && process.argv[a].substr(0, 1) !== '-' && process.argv[a] !== 'JASMINE_CONFIG_PATH=./jasmine.json') {
options[requiredArgs[r].option] = process.argv[a++];
} else {
break;
}
}
for (; a < process.argv.length; a += 1) {
for (o = 0; o < optionalArgs.length; o += 1) {
if (optionalArgs[o].alias === process.argv[a].slice(1) || optionalArgs[o].arg === process.argv[a].slice(2)) {
break;
}
}
if (o < optionalArgs.length) {
switch (optionalArgs[o].type) {
case 'file': case 'string': case 'number':
if (a + 1 < process.argv.length) {
a += 1;
options[optionalArgs[o].option] = (optionalArgs[o].type === 'number' ? Number(process.argv[a]) : process.argv[a]);
}
break;
case 'flag':
options[optionalArgs[o].option] = true; break;
}
}
}
return options;
}
};

83
node_modules/xml-js/bin/cli.js generated vendored Normal file
View file

@ -0,0 +1,83 @@
#!/usr/bin/env node
var fs = require('fs');
var helper = require('./cli-helper');
var project = require('../package.json');
var xml2json = require('../lib/xml2json');
var json2xml = require('../lib/json2xml');
var output = '';
var stream = '';
var options = {};
var requiredArgs = [
{ arg: 'src', type: 'file', option: 'src', desc: 'Input file that need to be converted.'}
];
var optionalArgs = [
{ arg: 'help', alias: 'h', type: 'flag', option: 'help', desc: 'Display this help content.' },
{ arg: 'version', alias: 'v', type: 'flag', option: 'version', desc: 'Display version number of this module.' },
{ arg: 'out', type: 'file', option: 'out', desc: 'Output file where the converted result should be written.' },
{ arg: 'to-json', type: 'flag', option:'toJason', desc: 'Convert.' },
{ arg: 'compact', type: 'flag', option:'compact', desc: 'Compact JSON form (see explanation in www.npmjs.com/package/xml-js).' },
{ arg: 'spaces', type: 'number', option:'spaces', desc: 'Specifies amount of space indentation in the output.' },
{ arg: 'trim', type: 'flag', option:'trim', desc: 'Any whitespaces surrounding texts will be trimmed.' },
// { arg: 'sanitize', type: 'flag', option:'sanitize', desc: 'Special xml characters will be replaced with entity codes.' },
{ arg: 'native-type', type: 'flag', option:'nativeType', desc: 'Numbers and boolean will be converted (coerced) to native type instead of text.' },
{ arg: 'always-array', type: 'flag', option:'alwaysArray', desc: 'Every element will always be an array type (applicable if --compact is set). If the passed value is an array, only elements with names in the passed array are always made arrays.' },
{ arg: 'always-children', type: 'flag', option:'alwaysChildren', desc: 'Every element will always contain sub-elements (applicable if --compact is not set).' },
{ arg: 'instruction-attr', type: 'flag', option:'instructionHasAttributes', desc: 'Whether to parse contents of processing instruction as attributes.' },
{ arg: 'full-tag', type: 'flag', option:'fullTagEmptyElement', desc: 'XML elements will always be in <a></a> form.' },
{ arg: 'no-decl', type: 'flag', option:'ignoreDeclaration', desc: 'Declaration instruction <?xml?> will be ignored.' },
{ arg: 'no-decl', type: 'flag', option:'ignoreInstruction', desc: 'Processing instruction <?...?> will be ignored.' },
{ arg: 'no-attr', type: 'flag', option:'ignoreAttributes', desc: 'Attributes of elements will be ignored.' },
{ arg: 'no-text', type: 'flag', option:'ignoreText', desc: 'Texts of elements will be ignored.' },
{ arg: 'no-cdata', type: 'flag', option:'ignoreCdata', desc: 'CData of elements will be ignored.' },
{ arg: 'no-doctype', type: 'flag', option:'ignoreDoctype', desc: 'DOCTYPE of elements will be ignored.' },
{ arg: 'no-comment', type: 'flag', option:'ignoreComment', desc: 'Comments of elements will be ignored.' },
{ arg: 'text-key', type: 'string', option:'textKey', desc: 'To change the default \'text\' key.' },
{ arg: 'cdata-key', type: 'string', option:'cdataKey', desc: 'To change the default \'cdata\' key.' },
{ arg: 'doctype-key', type: 'string', option:'doctypeKey', desc: 'To change the default \'doctype\' key.' },
{ arg: 'comment-key', type: 'string', option:'commentKey', desc: 'To change the default \'comment\' key.' },
{ arg: 'attributes-key', type: 'string', option:'attributesKey', desc: 'To change the default \'attributes\' key.' },
{ arg: 'declaration-key', type: 'string', option:'declarationKey', desc: 'To change the default \'declaration\' key <?xml?>.' },
{ arg: 'instruction-key', type: 'string', option:'instructionKey', desc: 'To change the default \'processing instruction\' key <?...?>.' },
{ arg: 'type-key', type: 'string', option:'typeKey', desc: 'To change the default \'type\' key (applicable if --compact is not set).' },
{ arg: 'name-key', type: 'string', option:'nameKey', desc: 'To change the default \'name\' key (applicable if --compact is not set).' },
{ arg: 'elements-key', type: 'string', option:'elementsKey', desc: 'To change the default \'elements\' key (applicable if --compact is not set).' }
];
process.stdin.setEncoding('utf8');
process.stdin.on('readable', function () {
var chunk = process.stdin.read();
if (chunk !== null) {
stream += chunk;
}
});
process.stdin.on('end', function () {
process.stdout.write(xml2json(stream, {}) + '\n');
});
options = helper.mapCommandLineArgs(requiredArgs, optionalArgs);
if (options.version) {
console.log(project.version);
process.exit(0);
} else if (options.help || process.argv.length <= 2 + requiredArgs.length - 1) {
console.log(helper.getCommandLineHelp('xml-js', requiredArgs, optionalArgs));
process.exit(process.argv.length <= 2 ? 1 : 0);
} else if ('src' in options) {
if (fs.statSync(options.src).isFile()) {
if (options.src.split('.').pop() === 'xml') {
output = xml2json(fs.readFileSync(options.src, 'utf8'), options);
} else if (options.src.split('.').pop() === 'json') {
output = json2xml(fs.readFileSync(options.src, 'utf8'), options);
}
if (options.out) {
fs.writeFileSync(options.out, output, 'utf8');
} else {
console.log(output);
}
process.exit(0);
}
} else {
process.exit(1);
}

23
node_modules/xml-js/bin/test.json generated vendored Normal file
View file

@ -0,0 +1,23 @@
{
"elements": [
{
"type": "element",
"name": "a",
"attributes": {
"x": "1"
},
"elements": [
{
"type": "element",
"name": "b",
"elements": [
{
"type": "text",
"text": "bye!"
}
]
}
]
}
]
}

3
node_modules/xml-js/bin/test.xml generated vendored Normal file
View file

@ -0,0 +1,3 @@
<a x="1">
<b>bye!</b>
</a>