Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Leonidas-from-XIV/node-xml2js
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: bd0f7809a2a5d5e7ff7f8088154f25782857a46d
Choose a base ref
...
head repository: Leonidas-from-XIV/node-xml2js
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8e9a1209235406fe10cf96f4d458ce46c94bf412
Choose a head ref
  • 16 commits
  • 7 files changed
  • 2 contributors

Commits on Apr 9, 2023

  1. 4

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    b856cb8 View commit details

Commits on Apr 26, 2023

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    246252a View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    d486007 View commit details

Commits on Apr 27, 2023

  1. Copy the full SHA
    ad3a297 View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    4c8ec89 View commit details
  3. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    7292aa9 View commit details

Commits on May 25, 2023

  1. Copy the full SHA
    044cfe5 View commit details
  2. Copy the full SHA
    5f6620f View commit details
  3. Copy the full SHA
    167a385 View commit details
  4. Copy the full SHA
    3b97ae5 View commit details
  5. Merge pull request #680 from Leonidas-from-XIV/zap-dependency-fix

    Fix zap to be the original dependency
    Leonidas-from-XIV authored May 25, 2023
    Copy the full SHA
    1de4688 View commit details
  6. Copy the full SHA
    a25035c View commit details
  7. Release new version

    Leonidas-from-XIV committed May 25, 2023
    Copy the full SHA
    0e29f0e View commit details

Commits on Jul 25, 2023

  1. Update package lock

    Leonidas-from-XIV committed Jul 25, 2023
    Copy the full SHA
    ba46e54 View commit details
  2. Copy the full SHA
    30f9d61 View commit details
  3. Copy the full SHA
    8e9a120 View commit details
Showing with 63 additions and 135 deletions.
  1. +0 −12 .travis.yml
  2. +0 −79 bower.json
  3. +22 −12 lib/parser.js
  4. +7 −8 package-lock.json
  5. +3 −3 package.json
  6. +21 −11 src/parser.coffee
  7. +10 −10 test/parser.test.coffee
12 changes: 0 additions & 12 deletions .travis.yml

This file was deleted.

79 changes: 0 additions & 79 deletions bower.json

This file was deleted.

34 changes: 22 additions & 12 deletions lib/parser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 7 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
"json"
],
"homepage": "https://github.com/Leonidas-from-XIV/node-xml2js",
"version": "0.5.0",
"version": "0.6.1",
"author": "Marek Kubica <marek@xivilization.net> (https://xivilization.net)",
"contributors": [
"maqr <maqr.lollerskates@gmail.com> (https://github.com/maqr)",
@@ -79,12 +79,12 @@
"xmlbuilder": "~11.0.0"
},
"devDependencies": {
"coffee-script": ">=1.10.0",
"coffeescript": ">=1.10.0 <2",
"coveralls": "^3.0.1",
"diff": ">=1.0.8",
"docco": ">=0.6.2",
"nyc": ">=2.2.1",
"zap": ">=0.2.9"
"zap": ">=0.2.9 <1"
},
"engines": {
"node": ">=4.0.0"
32 changes: 21 additions & 11 deletions src/parser.coffee
Original file line number Diff line number Diff line change
@@ -15,6 +15,15 @@ processItem = (processors, item, key) ->
item = process(item, key) for process in processors
return item

defineProperty = (obj, key, value) ->
# make sure the descriptor hasn't been prototype polluted
descriptor = Object.create null
descriptor.value = value
descriptor.writeable = true
descriptor.enumerable = true
descriptor.configurable = true
Object.defineProperty obj, key, descriptor

class exports.Parser extends events
constructor: (opts) ->
# if this was called without 'new', create an instance with new and return
@@ -54,11 +63,12 @@ class exports.Parser extends events
assignOrPush: (obj, key, newValue) =>
if key not of obj
if not @options.explicitArray
obj[key] = newValue
defineProperty obj, key, newValue
else
obj[key] = [newValue]
defineProperty obj, key, [newValue]
else
obj[key] = [obj[key]] if not (obj[key] instanceof Array)
unless obj[key] instanceof Array
defineProperty obj, key, [obj[key]]
obj[key].push newValue

reset: =>
@@ -102,18 +112,18 @@ class exports.Parser extends events
charkey = @options.charkey

@saxParser.onopentag = (node) =>
obj = Object.create(null)
obj = {}
obj[charkey] = ""
unless @options.ignoreAttrs
for own key of node.attributes
if attrkey not of obj and not @options.mergeAttrs
obj[attrkey] = Object.create(null)
obj[attrkey] = {}
newValue = if @options.attrValueProcessors then processItem(@options.attrValueProcessors, node.attributes[key], key) else node.attributes[key]
processedKey = if @options.attrNameProcessors then processItem(@options.attrNameProcessors, key) else key
if @options.mergeAttrs
@assignOrPush obj, processedKey, newValue
else
obj[attrkey][processedKey] = newValue
defineProperty obj[attrkey], processedKey, newValue

# need a place to store the node name
obj["#name"] = if @options.tagNameProcessors then processItem(@options.tagNameProcessors, node.name) else node.name
@@ -163,7 +173,7 @@ class exports.Parser extends events
# put children into <childkey> property and unfold chars if necessary
if @options.explicitChildren and not @options.mergeAttrs and typeof obj is 'object'
if not @options.preserveChildrenOrder
node = Object.create(null)
node = {}
# separate attributes
if @options.attrkey of obj
node[@options.attrkey] = obj[@options.attrkey]
@@ -181,9 +191,9 @@ class exports.Parser extends events
# append current node onto parent's <childKey> array
s[@options.childkey] = s[@options.childkey] or []
# push a clone so that the node in the children array can receive the #name property while the original obj can do without it
objClone = Object.create(null)
objClone = {}
for own key of obj
objClone[key] = obj[key]
defineProperty objClone, key, obj[key]
s[@options.childkey].push objClone
delete obj["#name"]
# re-check whether we can collapse the node now to just the charkey value
@@ -198,8 +208,8 @@ class exports.Parser extends events
if @options.explicitRoot
# avoid circular references
old = obj
obj = Object.create(null)
obj[nodeName] = old
obj = {}
defineProperty obj, nodeName, old

@resultObject = obj
# parsing has ended, mark that so we won't throw exceptions from
20 changes: 10 additions & 10 deletions test/parser.test.coffee
Original file line number Diff line number Diff line change
@@ -547,13 +547,13 @@ module.exports =

'test single attrNameProcessors': skeleton(attrNameProcessors: [nameToUpperCase], (r)->
console.log 'Result object: ' + util.inspect r, false, 10
equ {}.hasOwnProperty.call(r.sample.attrNameProcessTest[0].$, 'CAMELCASEATTR'), true
equ {}.hasOwnProperty.call(r.sample.attrNameProcessTest[0].$, 'LOWERCASEATTR'), true)
equ r.sample.attrNameProcessTest[0].$.hasOwnProperty('CAMELCASEATTR'), true
equ r.sample.attrNameProcessTest[0].$.hasOwnProperty('LOWERCASEATTR'), true)

'test multiple attrNameProcessors': skeleton(attrNameProcessors: [nameToUpperCase, nameCutoff], (r)->
console.log 'Result object: ' + util.inspect r, false, 10
equ {}.hasOwnProperty.call(r.sample.attrNameProcessTest[0].$, 'CAME'), true
equ {}.hasOwnProperty.call(r.sample.attrNameProcessTest[0].$, 'LOWE'), true)
equ r.sample.attrNameProcessTest[0].$.hasOwnProperty('CAME'), true
equ r.sample.attrNameProcessTest[0].$.hasOwnProperty('LOWE'), true)

'test single attrValueProcessors': skeleton(attrValueProcessors: [nameToUpperCase], (r)->
console.log 'Result object: ' + util.inspect r, false, 10
@@ -575,21 +575,21 @@ module.exports =

'test single tagNameProcessors': skeleton(tagNameProcessors: [nameToUpperCase], (r)->
console.log 'Result object: ' + util.inspect r, false, 10
equ {}.hasOwnProperty.call(r, 'SAMPLE'), true
equ {}.hasOwnProperty.call(r.SAMPLE, 'TAGNAMEPROCESSTEST'), true)
equ r.hasOwnProperty('SAMPLE'), true
equ r.SAMPLE.hasOwnProperty('TAGNAMEPROCESSTEST'), true)

'test single tagNameProcessors in simple callback': (test) ->
fs.readFile fileName, (err, data) ->
xml2js.parseString data, tagNameProcessors: [nameToUpperCase], (err, r)->
console.log 'Result object: ' + util.inspect r, false, 10
equ {}.hasOwnProperty.call(r, 'SAMPLE'), true
equ {}.hasOwnProperty.call(r.SAMPLE, 'TAGNAMEPROCESSTEST'), true
equ r.hasOwnProperty('SAMPLE'), true
equ r.SAMPLE.hasOwnProperty('TAGNAMEPROCESSTEST'), true
test.finish()

'test multiple tagNameProcessors': skeleton(tagNameProcessors: [nameToUpperCase, nameCutoff], (r)->
console.log 'Result object: ' + util.inspect r, false, 10
equ {}.hasOwnProperty.call(r, 'SAMP'), true
equ {}.hasOwnProperty.call(r.SAMP, 'TAGN'), true)
equ r.hasOwnProperty('SAMP'), true
equ r.SAMP.hasOwnProperty('TAGN'), true)

'test attrValueProcessors key param': skeleton(attrValueProcessors: [replaceValueByName], (r)->
console.log 'Result object: ' + util.inspect r, false, 10