Skip to content

Commit

Permalink
Removed the dependency on Babel compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
cedx committed Jul 22, 2017
1 parent 19648d6 commit 543d14a
Show file tree
Hide file tree
Showing 13 changed files with 514 additions and 37 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog
This file contains highlights of what changes on each version of the [Akismet for JS](https://github.com/cedx/akismet.js) library.

## Version 9.1.0
- Removed the dependency on [Babel](https://babeljs.io) compiler.
- Updated the package dependencies.

## Version 9.0.0
- Breaking change: reverted the API of the `Client` class to an [Observable](http://reactivex.io/intro.html)-based one.
- Added new unit tests.
Expand Down
16 changes: 3 additions & 13 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,13 @@ const {david} = require('@cedx/gulp-david');
const {spawn} = require('child_process');
const del = require('del');
const gulp = require('gulp');
const babel = require('gulp-babel');
const eslint = require('gulp-eslint');
const {normalize} = require('path');

/**
* Runs the default tasks.
*/
gulp.task('default', ['build']);

/**
* Builds the sources.
*/
gulp.task('build', () => gulp.src('src/**/*.js')
.pipe(babel())
.pipe(gulp.dest('lib'))
);
gulp.task('default', ['lint']);

/**
* Deletes all generated files and reset any saved state.
Expand Down Expand Up @@ -49,15 +40,15 @@ gulp.task('doc', async () => {
/**
* Fixes the coding standards issues.
*/
gulp.task('fix', () => gulp.src(['*.js', 'src/**/*.js', 'test/**/*.js'], {base: '.'})
gulp.task('fix', () => gulp.src(['*.js', 'lib/**/*.js', 'test/**/*.js'], {base: '.'})
.pipe(eslint({fix: true}))
.pipe(gulp.dest('.'))
);

/**
* Performs static analysis of source code.
*/
gulp.task('lint', () => gulp.src(['*.js', 'src/**/*.js', 'test/**/*.js'])
gulp.task('lint', () => gulp.src(['*.js', 'lib/**/*.js', 'test/**/*.js'])
.pipe(eslint())
.pipe(eslint.format())
);
Expand All @@ -69,7 +60,6 @@ gulp.task('test', () => _exec('node_modules/.bin/nyc', [
'--report-dir=var',
'--reporter=lcovonly',
normalize('node_modules/.bin/mocha'),
'--compilers=js:babel-register',
'--recursive'
]));

Expand Down
94 changes: 94 additions & 0 deletions lib/author.js
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)}`;
}
};
70 changes: 70 additions & 0 deletions lib/blog.js
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)}`;
}
};
Loading

0 comments on commit 543d14a

Please sign in to comment.