-
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.
- Loading branch information
Showing
8 changed files
with
232 additions
and
164 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,45 +5,39 @@ export class Author { | |
|
||
/** | ||
* The author's mail address. If you set it to `"[email protected]"`, Akismet will always return `true`. | ||
* @type {string} | ||
*/ | ||
email; | ||
email: string; | ||
|
||
/** | ||
* The author's IP address. | ||
* @type {string} | ||
*/ | ||
ipAddress; | ||
ipAddress: string; | ||
|
||
/** | ||
* The author's name. If you set it to `"viagra-test-123"`, Akismet will always return `true`. | ||
* @type {string} | ||
*/ | ||
name; | ||
name: string; | ||
|
||
/** | ||
* The author's role. If you set it to `"administrator"`, Akismet will always return `false`. | ||
* @type {AuthorRole|string} | ||
*/ | ||
role; | ||
role: AuthorRole|string; | ||
|
||
/** | ||
* The URL of the author's website. | ||
* @type {URL|null} | ||
*/ | ||
url; | ||
url: URL|null; | ||
|
||
/** | ||
* The author's user agent, that is the string identifying the Web browser used to submit comments. | ||
* @type {string} | ||
*/ | ||
userAgent; | ||
userAgent: string; | ||
|
||
/** | ||
* Creates a new author. | ||
* @param {Partial<AuthorOptions>} options An object providing values to initialize this instance. | ||
* @param options An object providing values to initialize this instance. | ||
*/ | ||
constructor(options = {}) { | ||
constructor(options: Partial<AuthorOptions> = {}) { | ||
this.email = options.email ?? ""; | ||
this.ipAddress = options.ipAddress ?? ""; | ||
this.name = options.name ?? ""; | ||
|
@@ -54,10 +48,10 @@ export class Author { | |
|
||
/** | ||
* Creates a new author from the specified JSON object. | ||
* @param {Record<string, any>} json A JSON object representing an author. | ||
* @returns {Author} The instance corresponding to the specified JSON object. | ||
* @param json A JSON object representing an author. | ||
* @returns The instance corresponding to the specified JSON object. | ||
*/ | ||
static fromJson(json) { | ||
static fromJson(json: Record<string, any>): Author { | ||
return new this({ | ||
email: typeof json.comment_author_email == "string" ? json.comment_author_email : "", | ||
ipAddress: typeof json.user_ip == "string" ? json.user_ip : "", | ||
|
@@ -70,10 +64,10 @@ export class Author { | |
|
||
/** | ||
* Returns a JSON representation of this object. | ||
* @returns {Record<string, any>} The JSON representation of this object. | ||
* @returns The JSON representation of this object. | ||
*/ | ||
toJSON() { | ||
/** @type {Record<string, any>} */ const map = {user_ip: this.ipAddress}; | ||
toJSON(): Record<string, any> { | ||
const map: Record<string, any> = {user_ip: this.ipAddress}; | ||
if (this.email) map.comment_author_email = this.email; | ||
if (this.name) map.comment_author = this.name; | ||
if (this.role) map.user_role = this.role; | ||
|
@@ -85,23 +79,47 @@ export class Author { | |
|
||
/** | ||
* Defines the options of an {@link Author} instance. | ||
* @typedef {object} AuthorOptions | ||
* @property {string} email The author's mail address. If you set it to `"[email protected]"`, Akismet will always return `true`. | ||
* @property {string} ipAddress The author's IP address. | ||
* @property {string} name The author's name. | ||
* @property {AuthorRole|string} role The author's role. | ||
* @property {URL|string} url The URL of the author's website. | ||
* @property {string} userAgent The author's user agent, that is the string identifying the Web browser used to submit comments. | ||
*/ | ||
export interface AuthorOptions { | ||
|
||
/** | ||
* The author's mail address. If you set it to `"[email protected]"`, Akismet will always return `true`. | ||
*/ | ||
email: string; | ||
|
||
/** | ||
* The author's IP address. | ||
*/ | ||
ipAddress: string; | ||
|
||
/** | ||
* The author's name. If you set it to `"viagra-test-123"`, Akismet will always return `true`. | ||
*/ | ||
name: string; | ||
|
||
/** | ||
* The author's role. If you set it to `"administrator"`, Akismet will always return `false`. | ||
*/ | ||
role: AuthorRole|string; | ||
|
||
/** | ||
* The URL of the author's website. | ||
*/ | ||
url: URL|string; | ||
|
||
/** | ||
* The author's user agent, that is the string identifying the Web browser used to submit comments. | ||
*/ | ||
userAgent: string; | ||
} | ||
|
||
/** | ||
* Specifies the role of an author. | ||
* @enum {string} | ||
*/ | ||
export const AuthorRole = Object.freeze({ | ||
export enum AuthorRole { | ||
|
||
/** | ||
* The author is an administrator. | ||
*/ | ||
administrator: "administrator" | ||
}); | ||
administrator = "administrator" | ||
} |
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 |
---|---|---|
@@ -1,21 +1,20 @@ | ||
/** | ||
* Specifies the result of a comment check. | ||
* @enum {number} | ||
*/ | ||
export const CheckResult = Object.freeze({ | ||
export enum CheckResult { | ||
|
||
/** | ||
* The comment is not a spam (i.e. a ham). | ||
*/ | ||
ham: 0, | ||
ham, | ||
|
||
/** | ||
* The comment is a spam. | ||
*/ | ||
spam: 1, | ||
spam, | ||
|
||
/** | ||
* The comment is a pervasive spam (i.e. it can be safely discarded). | ||
*/ | ||
pervasiveSpam: 2 | ||
}); | ||
pervasiveSpam | ||
} |
Oops, something went wrong.