[Pkg-javascript-commits] [ltx] 291/469: Formatting updates

Jonas Smedegaard dr at jones.dk
Wed Aug 31 13:03:18 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 4e1f636371bae91dc84d4628969f2e58e82be35c
Author: Lloyd Watkin <lloyd.watkin at surevine.com>
Date:   Thu Jan 9 09:01:31 2014 +0000

    Formatting updates
---
 lib/element.js | 75 +++++++++++++++++++++++++++++-----------------------------
 1 file changed, 38 insertions(+), 37 deletions(-)

diff --git a/lib/element.js b/lib/element.js
index 9fa7179..5425515 100644
--- a/lib/element.js
+++ b/lib/element.js
@@ -84,12 +84,12 @@ Element.prototype.getXmlns = function() {
  * xmlns can be null, returns the matching attribute.
  **/
 Element.prototype.getAttr = function(name, xmlns) {
-    if(!xmlns)
+    if (!xmlns)
         return this.attrs[name]
 
     var namespaces = this.getXmlns()
 
-    if(!namespaces[xmlns])
+    if (!namespaces[xmlns])
         return null
 
     return this.attrs[[namespaces[xmlns], name].join(':')]
@@ -107,7 +107,7 @@ Element.prototype.getChild = function(name, xmlns) {
  **/
 Element.prototype.getChildren = function(name, xmlns) {
     var result = []
-    for(var i = 0; i < this.children.length; i++) {
+    for (var i = 0; i < this.children.length; i++) {
 	      var child = this.children[i]
         if (child.getName &&
             child.getName() == name &&
@@ -129,7 +129,7 @@ Element.prototype.getChildByAttr = function(attr, val, xmlns, recursive) {
  **/
 Element.prototype.getChildrenByAttr = function(attr, val, xmlns, recursive) {
     var result = []
-    for(var i = 0; i < this.children.length; i++) {
+    for (var i = 0; i < this.children.length; i++) {
 	      var child = this.children[i]
         if (child.attrs &&
             child.attrs[attr] == val &&
@@ -144,7 +144,7 @@ Element.prototype.getChildrenByAttr = function(attr, val, xmlns, recursive) {
 
 Element.prototype.getChildrenByFilter = function(filter, recursive) {
     var result = []
-    for(var i = 0; i < this.children.length; i++) {
+    for (var i = 0; i < this.children.length; i++) {
         var child = this.children[i]
         if (filter(child))
             result.push(child)
@@ -160,9 +160,9 @@ Element.prototype.getChildrenByFilter = function(filter, recursive) {
 
 Element.prototype.getText = function() {
     var text = ''
-    for(var i = 0; i < this.children.length; i++) {
+    for (var i = 0; i < this.children.length; i++) {
 	var child = this.children[i]
-        if (typeof child == 'string' || typeof child == 'number')
+        if ((typeof child === 'string') || (typeof child === 'number'))
             text += child
     }
     return text
@@ -243,19 +243,19 @@ Element.prototype.remove = function(el, xmlns) {
  */
 Element.prototype.clone = function() {
     var clone = new Element(this.name, {})
-    for(var k in this.attrs) {
-	if (this.attrs.hasOwnProperty(k))
-	    clone.attrs[k] = this.attrs[k]
+    for (var k in this.attrs) {
+        if (this.attrs.hasOwnProperty(k))
+            clone.attrs[k] = this.attrs[k]
     }
-    for(var i = 0; i < this.children.length; i++) {
-	var child = this.children[i]
-	clone.cnode(child.clone ? child.clone() : child)
+    for (var i = 0; i < this.children.length; i++) {
+	    var child = this.children[i]
+	    clone.cnode(child.clone ? child.clone() : child)
     }
     return clone
 }
 
 Element.prototype.text = function(val) {
-    if(val && this.children.length == 1){
+    if (val && this.children.length == 1){
         this.children[0] = val
         return this
     }
@@ -263,8 +263,8 @@ Element.prototype.text = function(val) {
 }
 
 Element.prototype.attr = function(attr, val) {
-    if (!(typeof val === 'undefined' || val === null)) {
-        if(!this.attrs){
+    if ((!(typeof val === 'undefined') || (val === null))) {
+        if (!this.attrs){
           this.attrs = {}
         }
         this.attrs[attr] = val
@@ -286,33 +286,34 @@ Element.prototype.toString = function() {
 Element.prototype.write = function(writer) {
     writer('<')
     writer(this.name)
-    for(var k in this.attrs) {
+    for (var k in this.attrs) {
         var v = this.attrs[k]
-	if (v || v === '' || v === 0) {
+	if (v || (v === '') || (v === 0)) {
 	    writer(' ')
             writer(k)
-            writer('=\'')
-            if (typeof v != 'string')
+            writer('="')
+            if (typeof v !== 'string')
 		v = v.toString(10)
             writer(escapeXml(v))
-            writer('\'')
+            writer('"')
 	}
     }
-    if (this.children.length == 0) {
+    if (this.children.length === 0) {
         writer('/>')
     } else {
         writer('>')
-	for(var i = 0; i < this.children.length; i++) {
-	    var child = this.children[i]
-	    /* Skip null/undefined */
-	    if (child || child === 0) {
-		if (child.write)
-		    child.write(writer)
-		else if (typeof child === 'string')
-			writer(escapeXmlText(child))
-		else if (child.toString)
-			writer(escapeXmlText(child.toString(10)))
-	    }
+        for (var i = 0; i < this.children.length; i++) {
+            var child = this.children[i]
+            /* Skip null/undefined */
+            if (child || (child === 0)) {
+                if (child.write) {
+                    child.write(writer)
+                } else if (typeof child === 'string') {
+                    writer(escapeXmlText(child))
+                } else if (child.toString) {
+                    writer(escapeXmlText(child.toString(10)))
+                }
+            }
         }
         writer('</')
         writer(this.name)
@@ -325,16 +326,16 @@ function escapeXml(s) {
         replace(/\&/g, '&').
         replace(/</g, '<').
         replace(/>/g, '>').
-        replace(/'/g, '"').
-        replace(/'/g, ''');
+        replace(/"/g, '"').
+        replace(/"/g, ''')
 }
 
 function escapeXmlText(s) {
     return s.
         replace(/\&/g, '&').
         replace(/</g, '<').
-        replace(/>/g, '>');
+        replace(/>/g, '>')
 }
 
 exports.Element = Element
-exports.escapeXml = escapeXml
+exports.escapeXml = escapeXml
\ No newline at end of file

-- 
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