Comparing version 0.9.1 to 0.9.2
@@ -59,9 +59,9 @@ #!/usr/bin/env node | ||
} else if (options.help || process.argv.length <= 2) { | ||
console.log(common.printCommandLineHelp('xml-js', requiredArgs, optionalArgs)); | ||
console.log(common.getCommandLineHelp('xml-js', requiredArgs, optionalArgs)); | ||
process.exit(process.argv.length <= 2 ? 1 : 0); | ||
} else if ('src' in options && 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); | ||
} else if ('raw' in options && fs.statSync(options.raw[0]).isFile()) { | ||
if (options.raw[0].split('.').pop() === 'xml') { | ||
output = xml2json(fs.readFileSync(options.raw[0], 'utf8'), options); | ||
} else if (options.raw[0].split('.').pop() === 'json') { | ||
output = json2xml(fs.readFileSync(options.raw[0], 'utf8'), options); | ||
} | ||
@@ -68,0 +68,0 @@ if (options.out) { |
@@ -44,3 +44,3 @@ /*jslint node:true */ | ||
mapCommandLineArgs: function (optionalArgs) { | ||
var i, j, options = {}; | ||
var r, i, j, raw = [], options = {}; | ||
function findIndex (argument, index) { | ||
@@ -51,3 +51,13 @@ if (argument.alias === process.argv[i].slice(1) || argument.arg === process.argv[i].slice(2)) { | ||
} | ||
for (i = 2; i < process.argv.length; i += 1) { | ||
for (r = 2; r < process.argv.length; r += 1) { | ||
if (process.argv[r].substr(0, 1) !== '-' && process.argv[r] !== 'JASMINE_CONFIG_PATH=./jasmine.json') { | ||
if (!('raw' in options)) { | ||
options.raw = []; | ||
} | ||
options.raw.push(process.argv[r]); | ||
} else { | ||
break; | ||
} | ||
} | ||
for (i = r; i < process.argv.length; i += 1) { | ||
j = -1; | ||
@@ -54,0 +64,0 @@ optionalArgs.forEach(findIndex); |
/*jslint node:true */ | ||
var sax = require('sax'); | ||
var expat = {}; // = require('node-expat'); | ||
var expat = {on: function () {}, parse: function () {}}; // = require('node-expat'); | ||
var common = require('./common'); | ||
@@ -195,6 +195,6 @@ | ||
function onError (error) { | ||
console.error('error', error); | ||
error.note = error; //console.error(error); | ||
} | ||
module.exports = function(xml, userOptions) { | ||
module.exports = function (xml, userOptions) { | ||
@@ -201,0 +201,0 @@ var parser = pureJsParser ? sax.parser(true, {}) : parser = new expat.Parser('UTF-8'); |
{ | ||
"name": "xml-js", | ||
"version": "0.9.1", | ||
"version": "0.9.2", | ||
"description": "A convertor between XML text and Javascript object / JSON text.", | ||
@@ -45,3 +45,3 @@ "main": "index.js", | ||
"biased-opener": "^0.2.8", | ||
"browser-sync": "^2.12.8", | ||
"browser-sync": "^2.12.12", | ||
"cash-cat": "^0.2.0", | ||
@@ -48,0 +48,0 @@ "codacy-coverage": "^1.1.3", |
@@ -72,2 +72,8 @@ ![XML ⇔ JS/JSON](http://nashwaan.github.io/xml-js/images/logo.svg) | ||
You can also installed it globally to use it as command line convertor. | ||
```bash | ||
npm install -g xml-js | ||
``` | ||
## Quick start | ||
@@ -74,0 +80,0 @@ |
/*jslint node:true*/ | ||
/*global describe,it,expect,beforeEach,afterEach*/ | ||
var convert = require('../lib'); | ||
var testItems = require('./test-items'); | ||
if (!jasmine.standalone) { | ||
var exec = require('child_process').exec; | ||
var packageInfo = require('../package.json'); | ||
/*exec('node ./bin/cli.js --version', function (error, stdout, stderr) { | ||
console.log(stdout, stderr); | ||
});*/ | ||
//console.log(exec('node ./bin/cli.js --version'), {encoding: 'utf8'}); | ||
describe('Testing cli.js:', function () { | ||
'use strict'; | ||
xdescribe('No options supplied (fallback to defaults):', function () { | ||
describe('Getting version and help on usage:', function () { | ||
var options = {onlyItem: 6}; | ||
testItems(options).forEach(function (test) { | ||
it(test.desc, function () { | ||
expect(convert.xml2js(test.xml, options)).toEqual(test.js); | ||
it('Get version --version', function (done) { | ||
exec('node ./bin/cli --version', function (error, stdout, stderr) { | ||
expect(stdout).toEqual(packageInfo.version + '\n'); | ||
done(); | ||
}); | ||
}); | ||
it('Get version -v', function (done) { | ||
exec('node ./bin/cli -v', function (error, stdout, stderr) { | ||
expect(stdout).toEqual(packageInfo.version + '\n'); | ||
done(); | ||
}); | ||
}); | ||
it('Get help --help', function (done) { | ||
exec('node ./bin/cli --help', function (error, stdout, stderr) { | ||
expect(stdout.substr(0, 13)).toEqual('Usage: xml-js'); | ||
done(); | ||
}); | ||
}); | ||
it('Get help -h', function (done) { | ||
exec('node ./bin/cli -h', function (error, stdout, stderr) { | ||
expect(stdout.substr(0, 13)).toEqual('Usage: xml-js'); | ||
done(); | ||
}); | ||
}); | ||
it('Get help when no arguments supplied', function (done) { | ||
exec('node ./bin/cli', function (error, stdout, stderr) { | ||
expect(stdout.substr(0, 13)).toEqual('Usage: xml-js'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('Convert XML:', function () { | ||
xit('should convert xml file', function (done) { | ||
exec('node ./bin/cli note.xml', function (error, stdout, stderr) { | ||
expect(stdout).toEqual(packageInfo.version + '\n'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} |
@@ -84,43 +84,47 @@ /*jslint node:true*/ | ||
it('Flag argument, alias', function () { | ||
var possibleArgs = [{arg: 'version', alias: 'v', type: 'flag', option: 'version', desc: 'Display version.'}]; | ||
process.argv.push('-v'); | ||
expect(convert.mapCommandLineArgs(possibleArgs)).toEqual({version: true}); | ||
process.argv.pop(); | ||
}); | ||
if (!jasmine.standalone) { | ||
it('Flag argument, alias', function () { | ||
var possibleArgs = [{arg: 'version', alias: 'v', type: 'flag', option: 'version', desc: 'Display version.'}]; | ||
process.argv.push('-v'); | ||
expect(convert.mapCommandLineArgs(possibleArgs)).toEqual({version: true}); | ||
process.argv.pop(); | ||
}); | ||
it('Number argument, long form', function () { | ||
var possibleArgs = [{arg: 'spaces', type: 'number', option: 'spaces', desc: 'Specify spaces.'}]; | ||
process.argv.push('--spaces'); process.argv.push('5'); | ||
expect(convert.mapCommandLineArgs(possibleArgs)).toEqual({spaces: 5}); | ||
process.argv.pop(); process.argv.pop(); | ||
}); | ||
it('Number argument, long form', function () { | ||
var possibleArgs = [{arg: 'spaces', type: 'number', option: 'spaces', desc: 'Specify spaces.'}]; | ||
process.argv.push('--spaces'); process.argv.push('5'); | ||
expect(convert.mapCommandLineArgs(possibleArgs)).toEqual({spaces: 5}); | ||
process.argv.pop(); process.argv.pop(); | ||
}); | ||
it('String argument, long form', function () { | ||
var possibleArgs = [{arg: 'name', type: 'string', option: 'name', desc: 'Specify name.'}]; | ||
process.argv.push('--name'); process.argv.push('Foo'); | ||
expect(convert.mapCommandLineArgs(possibleArgs)).toEqual({name: 'Foo'}); | ||
process.argv.pop(); process.argv.pop(); | ||
}); | ||
it('String argument, long form', function () { | ||
var possibleArgs = [{arg: 'name', type: 'string', option: 'name', desc: 'Specify name.'}]; | ||
process.argv.push('--name'); process.argv.push('Foo'); | ||
expect(convert.mapCommandLineArgs(possibleArgs)).toEqual({name: 'Foo'}); | ||
process.argv.pop(); process.argv.pop(); | ||
}); | ||
it('File argument, long form', function () { | ||
var possibleArgs = [{arg: 'input', type: 'file', option: 'input', desc: 'Specify file.'}]; | ||
process.argv.push('--input'); process.argv.push('test.txt'); | ||
expect(convert.mapCommandLineArgs(possibleArgs)).toEqual({input: 'test.txt'}); | ||
process.argv.pop(); process.argv.pop(); | ||
}); | ||
it('File argument, long form', function () { | ||
var possibleArgs = [{arg: 'input', type: 'file', option: 'input', desc: 'Specify file.'}]; | ||
process.argv.push('--input'); process.argv.push('test.txt'); | ||
expect(convert.mapCommandLineArgs(possibleArgs)).toEqual({input: 'test.txt'}); | ||
process.argv.pop(); process.argv.pop(); | ||
}); | ||
it('Argument not proceeded with dash', function () { | ||
var possibleArgs = [{arg: 'version', alias: 'v', type: 'flag', option: 'version', desc: 'Display version.'}]; | ||
process.argv.push('v'); | ||
expect(convert.mapCommandLineArgs(possibleArgs)).toEqual({}); | ||
process.argv.pop(); | ||
}); | ||
it('Argument not proceeded with dash', function () { | ||
var possibleArgs = [{arg: 'version', alias: 'v', type: 'flag', option: 'version', desc: 'Display version.'}]; | ||
process.argv.push('v'); | ||
expect(convert.mapCommandLineArgs(possibleArgs)).toEqual({}); | ||
process.argv.pop(); | ||
}); | ||
it('Incomplete compound argument, long form', function () { | ||
var possibleArgs = [{arg: 'input', type: 'file', option: 'input', desc: 'Specify file.'}]; | ||
process.argv.push('--input'); | ||
expect(convert.mapCommandLineArgs(possibleArgs)).toEqual({}); | ||
process.argv.pop(); | ||
}); | ||
it('Incomplete compound argument, long form', function () { | ||
var possibleArgs = [{arg: 'input', type: 'file', option: 'input', desc: 'Specify file.'}]; | ||
process.argv.push('--input'); | ||
expect(convert.mapCommandLineArgs(possibleArgs)).toEqual({}); | ||
process.argv.pop(); | ||
}); | ||
} | ||
@@ -127,0 +131,0 @@ }); |
@@ -260,3 +260,3 @@ /*jslint node:true */ | ||
} catch (e) { | ||
console.log('Error: ', e); | ||
e.note = 'ignore me'; | ||
} | ||
@@ -263,0 +263,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1380456
53
23020
297
2