-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed the dependency on Babel compiler
- Loading branch information
Showing
13 changed files
with
514 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
'use strict'; | ||
|
||
const {URL} = require('url'); | ||
|
||
/** | ||
* Represents the author of a comment. | ||
*/ | ||
exports.Author = class Author { | ||
|
||
/** | ||
* Initializes a new instance of the class. | ||
* @param {string} [ipAddress] The author's IP address. | ||
* @param {string} [userAgent] The author's user agent. | ||
*/ | ||
constructor(ipAddress = '', userAgent = '') { | ||
|
||
/** | ||
* The author's mail address. | ||
* @type {string} | ||
*/ | ||
this.email = ''; | ||
|
||
/** | ||
* The author's IP address. | ||
* @type {string} | ||
*/ | ||
this.ipAddress = ipAddress; | ||
|
||
/** | ||
* The author's name. | ||
* @type {string} | ||
*/ | ||
this.name = ''; | ||
|
||
/** | ||
* The role of the author. | ||
* If you set it to `"administrator"`, Akismet will always return `false`. | ||
* @type {string} | ||
*/ | ||
this.role = ''; | ||
|
||
/** | ||
* The URL of the author's website. | ||
* @type {URL} | ||
*/ | ||
this.url = null; | ||
|
||
/** | ||
* The author's user agent, that is the string identifying the Web browser used to submit comments. | ||
* @type {string} | ||
*/ | ||
this.userAgent = userAgent; | ||
} | ||
|
||
/** | ||
* Creates a new author from the specified JSON map. | ||
* @param {object} map A JSON map representing an author. | ||
* @return {Author} The instance corresponding to the specified JSON map, or `null` if a parsing error occurred. | ||
*/ | ||
static fromJSON(map) { | ||
if (!map || typeof map != 'object') return null; | ||
|
||
let author = new Author(typeof map.user_ip == 'string' ? map.user_ip : ''); | ||
author.email = typeof map.comment_author_email == 'string' ? map.comment_author_email : ''; | ||
author.name = typeof map.comment_author == 'string' ? map.comment_author : ''; | ||
author.role = typeof map.user_role == 'string' ? map.user_role : ''; | ||
author.url = typeof map.comment_author_url == 'string' ? new URL(map.comment_author_url) : null; | ||
author.userAgent = typeof map.user_agent == 'string' ? map.user_agent : ''; | ||
return author; | ||
} | ||
|
||
/** | ||
* Converts this object to a map in JSON format. | ||
* @return {object} The map in JSON format corresponding to this object. | ||
*/ | ||
toJSON() { | ||
let map = {}; | ||
if (this.name.length) map.comment_author = this.name; | ||
if (this.email.length) map.comment_author_email = this.email; | ||
if (this.url) map.comment_author_url = this.url.href; | ||
if (this.userAgent.length) map.user_agent = this.userAgent; | ||
if (this.ipAddress.length) map.user_ip = this.ipAddress; | ||
if (this.role.length) map.user_role = this.role; | ||
return map; | ||
} | ||
|
||
/** | ||
* Returns a string representation of this object. | ||
* @return {string} The string representation of this object. | ||
*/ | ||
toString() { | ||
return `${this.constructor.name} ${JSON.stringify(this)}`; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
'use strict'; | ||
|
||
const {URL} = require('url'); | ||
|
||
/** | ||
* Represents the front page or home URL transmitted when making requests. | ||
*/ | ||
exports.Blog = class Blog { | ||
|
||
/** | ||
* Initializes a new instance of the class. | ||
* @param {string|URL} [url] The blog or site URL. | ||
* @param {string} [charset] he character encoding for the values included in comments. | ||
* @param {string[]} [languages] The languages in use on the blog or site, in ISO 639-1 format. | ||
*/ | ||
constructor(url = null, charset = '', languages = []) { | ||
|
||
/** | ||
* The character encoding for the values included in comments. | ||
* @type {string} | ||
*/ | ||
this.charset = charset; | ||
|
||
/** | ||
* The languages in use on the blog or site, in ISO 639-1 format. | ||
* @type {string[]} | ||
*/ | ||
this.languages = languages; | ||
|
||
/** | ||
* The blog or site URL. | ||
* @type {URL} | ||
*/ | ||
this.url = typeof url == 'string' ? new URL(url) : url; | ||
} | ||
|
||
/** | ||
* Creates a new blog from the specified JSON map. | ||
* @param {object} map A JSON map representing a blog. | ||
* @return {Blog} The instance corresponding to the specified JSON map, or `null` if a parsing error occurred. | ||
*/ | ||
static fromJSON(map) { | ||
if (!map || typeof map != 'object') return null; | ||
|
||
let blog = new Blog(typeof map.blog == 'string' ? map.blog : null); | ||
blog.charset = typeof map.blog_charset == 'string' ? map.blog_charset : ''; | ||
blog.languages = typeof map.blog_lang == 'string' ? map.blog_lang.split(',').map(lang => lang.trim()).filter(lang => lang.length) : []; | ||
return blog; | ||
} | ||
|
||
/** | ||
* Converts this object to a map in JSON format. | ||
* @return {object} The map in JSON format corresponding to this object. | ||
*/ | ||
toJSON() { | ||
let map = {}; | ||
if (this.url) map.blog = this.url.href; | ||
if (this.charset.length) map.blog_charset = this.charset; | ||
if (this.languages.length) map.blog_lang = this.languages.join(','); | ||
return map; | ||
} | ||
|
||
/** | ||
* Returns a string representation of this object. | ||
* @return {string} The string representation of this object. | ||
*/ | ||
toString() { | ||
return `${this.constructor.name} ${JSON.stringify(this)}`; | ||
} | ||
}; |
Oops, something went wrong.