Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

tried to improve readability & reduce loc

  • Loading branch information...
commit 17b3be3936491523efee87879e6f9d9d16f54b53 1 parent 0ae7d26
@fb55 fb55 authored
Showing with 15 additions and 21 deletions.
  1. +15 −21 lib/nodepie.js
View
36 lib/nodepie.js
@@ -242,7 +242,9 @@ NodePie.prototype._checkType = function(){
* entities
**/
NodePie.prototype._formatStr = function(str){
- return this.options.keepHTMLEntities ? str : NodePie._decodeHTMLEntities(str);
+ if(this.options.keepHTMLEntities)
+ return str;
+ else return NodePie._decodeHTMLEntities(str);
};
/**
@@ -252,16 +254,13 @@ NodePie.prototype._formatStr = function(str){
* Fetches text contents from a string or feed text object
**/
NodePie.prototype._parseContents = function(str){
- if(!str){
- return false;
- }
-
- if(typeof str === "string"){
+ if(!str);
+ else if(typeof str === "string"){
str = str.trim();
return str && this._formatStr(str);
}
- if(typeof str === "object"){
+ else if(typeof str === "object"){
if(typeof str.$t === "string"){
str.$t = str.$t.trim();
return str.$t && this._formatStr(str.$t);
@@ -608,10 +607,10 @@ NodePie.Item.prototype._formatStr = function(str){
**/
NodePie.Item.prototype._parseAuthor = function(author){
// email (name)
- var name;
- if(name = author.trim().match(/^[\w.\-]+@[\w.\-]+ \(([^)]+)\)$/)){
+ var name = author.trim().match(/^[\w.\-]+@[\w.\-]+ \(([^)]+)\)$/);
+
+ if(name)
author = (name[1] || "").trim();
- }
return this._formatStr(author);
};
@@ -700,13 +699,10 @@ NodePie.Item.prototype.getAuthor = function(){
NodePie.Item.prototype.getAuthors = function(){
var author, authors = [], dcns = this.feed.namespaces[NodePie.NS.DC];
- if(this.element.author){
- author = this.element.author;
- }else if(this.element.creator){
- author = this.element.creator;
- }else if(dcns && this.element[dcns+":creator"]){
- author = this.element[dcns+":creator"];
- }
+ if(author = this.element.author);
+ else if(author = this.element.creator);
+ else if(dcns && (author = this.element[dcns+":creator"]) );
+ else return false;
if(typeof author === "string"){
return [this._parseAuthor(author)];
@@ -720,9 +716,8 @@ NodePie.Item.prototype.getAuthors = function(){
}
}
return authors || false;
- }else if(typeof author.name === "string"){
+ }else if(typeof author.name === "string")
return [this._parseAuthor(author.name)];
- }
}
return false;
@@ -739,8 +734,7 @@ NodePie.Item.prototype.getAuthors = function(){
* title = item.getTitle();
**/
NodePie.Item.prototype.getTitle = function(){
- var title = this.element.title;
- return this._parseContents(title);
+ return this._parseContents(this.element.title);
};
/**
Please sign in to comment.
Something went wrong with that request. Please try again.