Skip to content

Commit

Permalink
Committed by npm script.
Browse files Browse the repository at this point in the history
  • Loading branch information
nashwaan committed Dec 13, 2017
1 parent c7d38a1 commit 99cb8fd
Show file tree
Hide file tree
Showing 33 changed files with 1,854 additions and 10,527 deletions.
6 changes: 3 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{js}]
[*.{js,ts,json,yml}]
charset = utf-8
indent_style = space
indent_size = 2

[{package.json,.travis.yml}]
[*.{xml}]
indent_style = space
indent_size = 2
indent_size = 4
205 changes: 0 additions & 205 deletions .eslintrc

This file was deleted.

17 changes: 17 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "eslint:recommended",
"env": {
"node": true,
"browser": true
},
"rules": {
"excludedFiles": ["**/*.min.js"],
"indent": ["error", 2],
"linebreak-style": ["error", "unix"],
"quotes": ["error", "single"],
"semi": ["error", "always"],
"no-cond-assign": ["error", "always"],
"no-console": "off",
"no-else-return": "warn"
}
}
1 change: 0 additions & 1 deletion .eslintrcignore

This file was deleted.

4 changes: 0 additions & 4 deletions .jshintrc

This file was deleted.

1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ node_modules/
_playground/
artwork/
test/
doc/
package-lock.json
yarn.lock
*.log
Expand Down
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceRoot}\\test\\index.js",
"program": "${workspaceRoot}/test/index",
"outFiles": [
"${workspaceRoot}/out/**/*.js"
]
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ Convert XML text to Javascript object / JSON text (and vice versa).
![Convert XML ↔ JS/JSON as compact or non-compact](http://nashwaan.github.io/xml-js/images/synopsis.svg)
<!---![Convert XML ↔ JS/JSON as compact or non-compact](/synopsis.png?raw=true "Synopsis Diagram")-->

# Motivation

There are many XML to JavaScript object / JSON converters out there, but could not satisfy the following requirements:
# Features

* **Maintain Order of Elements**:
Instead of converting `<a/><b/><a/>` to `{a:[{},{}],b:{}}`, I wanted to preserve order of elements by doing this:
Most libraries will convert `<a/><b/><a/>` to `{a:[{},{}],b:{}}` which merges any node of same name into an array. This library can creates the following to preserve the order of elements:
`{"elements":[{"type":"element","name":"a"},{"type":"element","name":"b"},{"type":"element","name":"a"}]}`.

This is very important and it is the main reason why this library was created.

* **Fully XML Compliant**:
Can parse: elements, attributes, texts, comments, CData, DOCTYPE, XML declarations, and Processing Instructions.

Expand All @@ -41,7 +41,7 @@ Whether converting xml→json or json→xml, the result can be converted back to
This library depends only on one external npm module.

* **Change Property Key Name**:
Usually output of XML attributes are stored in `@attr`, `_atrr`, `$attr`, `$`, or `whatever` in order to avoid conflicting with name of sub-elements.
Usually output of XML attributes are stored in `@attr`, `_atrr`, `$attr` or `$` in order to avoid conflicting with name of sub-elements.
This library store them in `attributes`, but most importantly, you can change this to whatever you like.

* **Support Upwards Traversal**:
Expand Down
47 changes: 47 additions & 0 deletions bin/cli-helper.js
Original file line number Diff line number Diff line change
@@ -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;
}

};
Loading

0 comments on commit 99cb8fd

Please sign in to comment.