@cedx/akismet
Version:
Prevent comment spam using the Akismet service.
51 lines (50 loc) • 1.61 kB
JavaScript
/**
* Represents the front page or home URL transmitted when making requests.
*/
export class Blog {
/**
* The character encoding for the values included in comments.
*/
charset;
/**
* The languages in use on the blog or site, in ISO 639-1 format.
*/
languages;
/**
* The blog or site URL.
*/
url;
/**
* Creates a new blog.
* @param options An object providing values to initialize this instance.
*/
constructor(options = {}) {
this.charset = options.charset ?? "";
this.languages = new Set(options.languages ?? []);
this.url = options.url ? new URL(options.url) : null;
}
/**
* Creates a new blog from the specified JSON object.
* @param json A JSON object representing a blog.
* @returns The instance corresponding to the specified JSON object.
*/
static fromJson(json) {
return new this({
charset: typeof json.blog_charset == "string" ? json.blog_charset : "",
languages: typeof json.blog_lang == "string" ? json.blog_lang.split(",").map(language => language.trim()) : [],
url: typeof json.blog == "string" ? json.blog : ""
});
}
/**
* Returns a JSON representation of this object.
* @returns The JSON representation of this object.
*/
toJSON() {
const map = { blog: this.url?.href ?? "" };
if (this.charset)
map.blog_charset = this.charset;
if (this.languages.size)
map.blog_lang = Array.from(this.languages).join(",");
return map;
}
}