diff --git a/.prettierignore b/.prettierignore index 5b16f5b..a6e4ba0 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,4 +1,3 @@ -examples node_modules lib docs diff --git a/examples/javascript.js b/examples/javascript.js index 1545531..b80ba68 100644 --- a/examples/javascript.js +++ b/examples/javascript.js @@ -21,10 +21,10 @@ var js2xmlparser = require("../lib/main"); /** * This example demonstrates a very simple usage of js2xmlparser. */ -var example1 = function() { +var example1 = function () { var obj = { - "firstName": "John", - "lastName": "Smith" + firstName: "John", + lastName: "Smith", }; console.log(js2xmlparser.parse("person", obj)); console.log(); @@ -34,44 +34,44 @@ example1(); /** * This example demonstrates a more complex usage of j2xmlparser. */ -var example2 = function() { +var example2 = function () { var obj = { "@": { - "type": "natural" + type: "natural", }, - "firstName": "John", - "lastName": "Smith", - "dateOfBirth": new Date(1964, 7, 26), - "address": { + firstName: "John", + lastName: "Smith", + dateOfBirth: new Date(1964, 7, 26), + address: { "@": { - "type": "home" + type: "home", }, - "streetAddress": "3212 22nd St", - "city": "Chicago", - "state": "Illinois", - "zip": 10000 + streetAddress: "3212 22nd St", + city: "Chicago", + state: "Illinois", + zip: 10000, }, - "phone": [ + phone: [ { "@": { - "type": "home" + type: "home", }, - "#": "123-555-4567" + "#": "123-555-4567", }, { "@": { - "type": "cell" + type: "cell", }, - "#": "890-555-1234" + "#": "890-555-1234", }, { "@": { - "type": "work" + type: "work", }, - "#": "567-555-8901" - } + "#": "567-555-8901", + }, ], - "email": "john@smith.com" + email: "john@smith.com", }; console.log(js2xmlparser.parse("person", obj)); console.log(); @@ -81,107 +81,107 @@ example2(); /** * This example demonstrates some of js2xmlparser's options. */ -var example3 = function() { +var example3 = function () { var options = { aliasString: "exAlias", attributeString: "exAttr", - cdataKeys: [ - "exCdata", - "exCdata2" - ], + cdataKeys: ["exCdata", "exCdata2"], declaration: { include: true, encoding: "UTF-16", standalone: "yes", - version: "1.1" + version: "1.1", }, dtd: { include: true, name: "exName", sysId: "exSysId", - pubId: "exPubId" + pubId: "exPubId", }, format: { doubleQuotes: true, indent: "\t", newline: "\r\n", - pretty: true + pretty: true, }, typeHandlers: { - "[object Number]": function(value) { + "[object Number]": function (value) { return value + 17; - } + }, }, valueString: "exVal", wrapHandlers: { - "exArr": function() { + exArr: function () { return "exArrInner"; - } - } + }, + }, }; var obj = { - "ex1": "ex2", - "exVal_1": 123, - "ex3": ["ex4", "ex5"], - "ex6": { - "exAttr_1": { - "ex7": "ex8", - "ex9": "ex10" + ex1: "ex2", + exVal_1: 123, + ex3: ["ex4", "ex5"], + ex6: { + exAttr_1: { + ex7: "ex8", + ex9: "ex10", }, - "ex11": "ex12", - "ex13": { - "ex14": "ex15" + ex11: "ex12", + ex13: { + ex14: "ex15", }, - "ex16": [ + ex16: [ "ex17", { - "ex18": "ex19" - } + ex18: "ex19", + }, ], - "exArr": [ + exArr: [ "ex20", { - "ex21": "ex22" - } + ex21: "ex22", + }, ], - "exAttr_2": { - "ex23": "ex24", - "ex25": "ex26" - } + exAttr_2: { + ex23: "ex24", + ex25: "ex26", + }, }, - "exVal_2": "ex27", - "ex28": [ - "ex29", - "ex30" - ], - "ex31": true, - "ex32": undefined, - "ex33": null, - "ex34": 3.4, - "ex35": function() { + exVal_2: "ex27", + ex28: ["ex29", "ex30"], + ex31: true, + ex32: undefined, + ex33: null, + ex34: 3.4, + ex35: function () { return "ex36"; }, - "ex37": "i { const obj = { - "firstName": "John", - "lastName": "Smith" + firstName: "John", + lastName: "Smith", }; console.log(parse("person", obj)); console.log(); @@ -35,41 +35,41 @@ example1(); const example2 = () => { const obj = { "@": { - "type": "natural" + type: "natural", }, - "firstName": "John", - "lastName": "Smith", - "dateOfBirth": new Date(1964, 7, 26), - "address": { + firstName: "John", + lastName: "Smith", + dateOfBirth: new Date(1964, 7, 26), + address: { "@": { - "type": "home" + type: "home", }, - "streetAddress": "3212 22nd St", - "city": "Chicago", - "state": "Illinois", - "zip": 10000 + streetAddress: "3212 22nd St", + city: "Chicago", + state: "Illinois", + zip: 10000, }, - "phone": [ + phone: [ { "@": { - "type": "home" + type: "home", }, - "#": "123-555-4567" + "#": "123-555-4567", }, { "@": { - "type": "cell" + type: "cell", }, - "#": "890-555-1234" + "#": "890-555-1234", }, { "@": { - "type": "work" + type: "work", }, - "#": "567-555-8901" - } + "#": "567-555-8901", + }, ], - "email": "john@smith.com" + email: "john@smith.com", }; console.log(parse("person", obj)); console.log(); @@ -83,103 +83,103 @@ const example3 = () => { const options = { aliasString: "exAlias", attributeString: "exAttr", - cdataKeys: [ - "exCdata", - "exCdata2" - ], + cdataKeys: ["exCdata", "exCdata2"], declaration: { include: true, encoding: "UTF-16", standalone: "yes", - version: "1.1" + version: "1.1", }, dtd: { include: true, name: "exName", sysId: "exSysId", - pubId: "exPubId" + pubId: "exPubId", }, format: { doubleQuotes: true, indent: "\t", newline: "\r\n", - pretty: true + pretty: true, }, typeHandlers: { "[object Number]": (value: any) => { return value + 17; - } + }, }, valueString: "exVal", wrapHandlers: { - "exArr": () => { + exArr: () => { return "exArrInner"; - } - } + }, + }, }; const obj = { - "ex1": "ex2", - "exVal_1": 123, - "ex3": ["ex4", "ex5"], - "ex6": { - "exAttr_1": { - "ex7": "ex8", - "ex9": "ex10" + ex1: "ex2", + exVal_1: 123, + ex3: ["ex4", "ex5"], + ex6: { + exAttr_1: { + ex7: "ex8", + ex9: "ex10", }, - "ex11": "ex12", - "ex13": { - "ex14": "ex15" + ex11: "ex12", + ex13: { + ex14: "ex15", }, - "ex16": [ + ex16: [ "ex17", { - "ex18": "ex19" - } + ex18: "ex19", + }, ], - "exArr": [ + exArr: [ "ex20", { - "ex21": "ex22" - } + ex21: "ex22", + }, ], - "exAttr_2": { - "ex23": "ex24", - "ex25": "ex26" - } + exAttr_2: { + ex23: "ex24", + ex25: "ex26", + }, }, - "exVal_2": "ex27", - "ex28": [ - "ex29", - "ex30" - ], - "ex31": true, - "ex32": undefined, - "ex33": null, - "ex34": 3.4, - "ex35": () => { + exVal_2: "ex27", + ex28: ["ex29", "ex30"], + ex31: true, + ex32: undefined, + ex33: null, + ex34: 3.4, + ex35: () => { return "ex36"; }, - "ex37": "i