[Pkg-javascript-commits] [ltx] 451/469: Revert "Merge pull request #91 from node-xmpp/no-json-2" (#97)
Jonas Smedegaard
dr at jones.dk
Wed Aug 31 13:03:38 UTC 2016
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository ltx.
commit 132150e230e09c2a37f9a7e0157433a94a41a02d
Author: Xiaoxin Lu <javascript at yahoo.com>
Date: Tue Jun 7 12:06:58 2016 -0400
Revert "Merge pull request #91 from node-xmpp/no-json-2" (#97)
This reverts commit a1fc70c4275783a5e33eb0c00c232d8fb607a66e, reversing
changes made to 6ccfc527ededc0bf88179a792d8539470a509524.
---
lib/Element.js | 10 ++++++++++
test/element-test.js | 10 ++++++++++
2 files changed, 20 insertions(+)
diff --git a/lib/Element.js b/lib/Element.js
index 7dce18b..73f6b19 100644
--- a/lib/Element.js
+++ b/lib/Element.js
@@ -318,6 +318,16 @@ Element.prototype.toString = function () {
return s
}
+Element.prototype.toJSON = function () {
+ return {
+ name: this.name,
+ attrs: this.attrs,
+ children: this.children.map(function (child) {
+ return child && child.toJSON ? child.toJSON() : child
+ })
+ }
+}
+
Element.prototype._addChildren = function (writer) {
writer('>')
for (var i = 0; i < this.children.length; i++) {
diff --git a/test/element-test.js b/test/element-test.js
index 9ce87bc..b33db92 100644
--- a/test/element-test.js
+++ b/test/element-test.js
@@ -82,6 +82,16 @@ vows.describe('Element').addBatch({
'serialize with integer text': function () {
var e = new Element('e').t(1000)
assert.equal(e.getText(), 1000)
+ },
+ 'serialize to json': function () {
+ var e = new Element('e', { foo: 23, bar: 0, nil: null }).c('f').t(1000).up()
+ assert.deepEqual(e.toJSON(), {
+ name: 'e',
+ attrs: { foo: 23, bar: 0, nil: null },
+ children: [
+ { name: 'f', attrs: {}, children: [1000] }
+ ]
+ })
}
},
'remove': {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/ltx.git
More information about the Pkg-javascript-commits
mailing list