aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.eslintrc.js25
-rw-r--r--.npmignore3
-rw-r--r--README.md2
-rw-r--r--docs/_config.yml1
-rw-r--r--docs/global.html18
-rw-r--r--docs/index.html2
-rw-r--r--docs/index.js.html54
-rw-r--r--package.json6
-rw-r--r--src/index.js52
9 files changed, 85 insertions, 78 deletions
diff --git a/.eslintrc.js b/.eslintrc.js
new file mode 100644
index 0000000..ce27f79
--- /dev/null
+++ b/.eslintrc.js
@@ -0,0 +1,25 @@
+module.exports = {
+ "env": {
+ "es6": true,
+ "node": true
+ },
+ "extends": "eslint:recommended",
+ "rules": {
+ "indent": [
+ "error",
+ 4
+ ],
+ "linebreak-style": [
+ "error",
+ "unix"
+ ],
+ "quotes": [
+ "error",
+ "single"
+ ],
+ "semi": [
+ "error",
+ "always"
+ ]
+ }
+}; \ No newline at end of file
diff --git a/.npmignore b/.npmignore
index 5c4de01..4d2fdc4 100644
--- a/.npmignore
+++ b/.npmignore
@@ -59,3 +59,6 @@ typings/
# Source
src/
+
+# Documentation
+docs/
diff --git a/README.md b/README.md
index 98ccf22..e8ec03b 100644
--- a/README.md
+++ b/README.md
@@ -79,4 +79,6 @@ Description of the internal kitchen can be seen on the [documentation page](http
Found out a mistake or feel a lack of functionality? [issues](https://github.com/valentineus/iii-client/issues)
## License
+[![JavaScript Style Guide](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)
+
[MIT](LICENSE.md). Copyright (c) [Valentin Popov](https://valentineus.link/). \ No newline at end of file
diff --git a/docs/_config.yml b/docs/_config.yml
deleted file mode 100644
index 2f7efbe..0000000
--- a/docs/_config.yml
+++ /dev/null
@@ -1 +0,0 @@
-theme: jekyll-theme-minimal \ No newline at end of file
diff --git a/docs/global.html b/docs/global.html
index 3d2919f..bcec003 100644
--- a/docs/global.html
+++ b/docs/global.html
@@ -234,7 +234,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
- <a href="index.js.html">index.js</a>, <a href="index.js.html#line149">line 149</a>
+ <a href="index.js.html">index.js</a>, <a href="index.js.html#line140">line 140</a>
</li></ul></dd>
@@ -471,7 +471,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
- <a href="index.js.html">index.js</a>, <a href="index.js.html#line98">line 98</a>
+ <a href="index.js.html">index.js</a>, <a href="index.js.html#line92">line 92</a>
</li></ul></dd>
@@ -631,7 +631,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
- <a href="index.js.html">index.js</a>, <a href="index.js.html#line113">line 113</a>
+ <a href="index.js.html">index.js</a>, <a href="index.js.html#line106">line 106</a>
</li></ul></dd>
@@ -791,7 +791,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
- <a href="index.js.html">index.js</a>, <a href="index.js.html#line83">line 83</a>
+ <a href="index.js.html">index.js</a>, <a href="index.js.html#line78">line 78</a>
</li></ul></dd>
@@ -951,7 +951,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
- <a href="index.js.html">index.js</a>, <a href="index.js.html#line128">line 128</a>
+ <a href="index.js.html">index.js</a>, <a href="index.js.html#line120">line 120</a>
</li></ul></dd>
@@ -1111,7 +1111,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
- <a href="index.js.html">index.js</a>, <a href="index.js.html#line175">line 175</a>
+ <a href="index.js.html">index.js</a>, <a href="index.js.html#line165">line 165</a>
</li></ul></dd>
@@ -1267,7 +1267,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
- <a href="index.js.html">index.js</a>, <a href="index.js.html#line14">line 14</a>
+ <a href="index.js.html">index.js</a>, <a href="index.js.html#line15">line 15</a>
</li></ul></dd>
@@ -1428,7 +1428,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
- <a href="index.js.html">index.js</a>, <a href="index.js.html#line50">line 50</a>
+ <a href="index.js.html">index.js</a>, <a href="index.js.html#line48">line 48</a>
</li></ul></dd>
@@ -1635,7 +1635,7 @@
<br class="clear">
<footer>
- Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon May 29 2017 02:00:06 GMT+0300 (MSK) using the Minami theme.
+ Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon May 29 2017 07:00:49 GMT+0300 (MSK) using the Minami theme.
</footer>
<script>prettyPrint();</script>
diff --git a/docs/index.html b/docs/index.html
index 96792a6..f19634a 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -57,7 +57,7 @@
<br class="clear">
<footer>
- Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon May 29 2017 02:00:06 GMT+0300 (MSK) using the Minami theme.
+ Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon May 29 2017 07:00:49 GMT+0300 (MSK) using the Minami theme.
</footer>
<script>prettyPrint();</script>
diff --git a/docs/index.js.html b/docs/index.js.html
index 3749990..29aeb27 100644
--- a/docs/index.js.html
+++ b/docs/index.js.html
@@ -47,12 +47,13 @@
var http = require('http');
+exports.connect = connect;
/**
* Connects to the server and returns the connection data.
* @param {String} uuid - The bot UUID.
* @param {requestCallback} callback - The callback that handles the response.
*/
-var connect = function(uuid, callback) {
+function connect(uuid, callback) {
uuid = uuid || '';
if (!_verification(uuid)) {
@@ -64,7 +65,7 @@ var connect = function(uuid, callback) {
hostname: 'iii.ru',
path: '/api/2.0/json/Chat.init/' + uuid + '/',
method: 'GET',
- }
+ };
const request = http.request(query, function(response) {
var json = '';
@@ -72,15 +73,12 @@ var connect = function(uuid, callback) {
response.on('end', () => callback(json.result));
});
- request.on('error', function(error) {
- console.error('Error connecting to the server!\n', error.message);
- });
+ request.on('error', (error) => Error(error.message));
request.end();
}
-exports.connect = connect;
-
+exports.send = send;
/**
* Send a message to the server and return a response.
* @param {Object} raw - The data to send.
@@ -88,7 +86,7 @@ exports.connect = connect;
* @param {String} raw.text - Message text.
* @param {requestCallback} callback - The callback that handles the response.
*/
-var send = function(raw, callback) {
+function send(raw, callback) {
raw = raw || {};
const query = {
@@ -96,7 +94,7 @@ var send = function(raw, callback) {
hostname: 'iii.ru',
path: '/api/2.0/json/Chat.request',
method: 'POST',
- }
+ };
const data = _createPackage(raw);
@@ -106,22 +104,19 @@ var send = function(raw, callback) {
response.on('end', () => callback(json));
});
- request.on('error', function(error) {
- console.error('Error sending the package!\n', error.message);
- });
+ request.on('error', (error) => Error(error));
request.write(data);
request.end();
}
-exports.send = send;
-
+exports._encrypt = _encrypt;
/**
* Encrypts the incoming data.
* @param {String} raw - Decrypted data.
* @returns {String} - Encrypted string.
*/
-var _encrypt = function(raw) {
+function _encrypt(raw) {
raw = raw || '';
var base64 = Buffer.from(raw).toString('base64');
@@ -129,14 +124,13 @@ var _encrypt = function(raw) {
return _merger(string).toString('base64');
}
-exports._encrypt = _encrypt;
-
+exports._decrypt = _decrypt;
/**
* Decrypts the incoming data.
* @param {String} raw - Encrypted data.
* @returns {String} - Decrypted string.
*/
-var _decrypt = function(raw) {
+function _decrypt(raw) {
raw = raw || '';
var string = Buffer.from(raw, 'base64');
@@ -144,14 +138,13 @@ var _decrypt = function(raw) {
return Buffer.from(decrypted, 'base64');
}
-exports._decrypt = _decrypt;
-
+exports._decryptJSON = _decryptJSON;
/**
* Decrypts an encrypted JSON object.
* @param {String} raw - Encrypted data.
* @returns {Object} - Decrypted JSON.
*/
-var _decryptJSON = function(raw) {
+function _decryptJSON(raw) {
raw = raw || '';
var string = raw.toString('ascii');
@@ -159,14 +152,13 @@ var _decryptJSON = function(raw) {
return JSON.parse(data);
}
-exports._decryptJSON = _decryptJSON;
-
+exports._merger = _merger;
/**
* Merge and convert a string.
* @param {String} raw - The string to convert.
* @returns {String} - The converted string.
*/
-var _merger = function(data) {
+function _merger(data) {
data = data || '';
const salt = Buffer.from('some very-very long string without any non-latin characters due to different string representations inside of variable programming languages');
@@ -178,8 +170,7 @@ var _merger = function(data) {
return data;
}
-exports._merger = _merger;
-
+exports._createPackage = _createPackage;
/**
* Creates an encrypted package to send.
* @param {Object} raw - The data to send.
@@ -187,7 +178,7 @@ exports._merger = _merger;
* @param {String} raw.text - Message text.
* @returns {String} - Encrypted string.
*/
-var _createPackage = function(raw) {
+function _createPackage(raw) {
raw = raw || {};
if (!raw.text) {
@@ -206,20 +197,17 @@ var _createPackage = function(raw) {
return _encrypt(json);
}
-exports._createPackage = _createPackage;
-
+exports._verification = _verification;
/**
* Validation UUID format string.
* @param {String} data - The string to check.
* @returns {Boolean}
*/
-var _verification = function(data) {
+function _verification(data) {
data = data || '';
const regexp = new RegExp('^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$', 'i');
return regexp.test(data);
}
-
-exports._verification = _verification;
</code></pre>
</article>
</section>
@@ -232,7 +220,7 @@ exports._verification = _verification;
<br class="clear">
<footer>
- Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon May 29 2017 02:00:06 GMT+0300 (MSK) using the Minami theme.
+ Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon May 29 2017 07:00:49 GMT+0300 (MSK) using the Minami theme.
</footer>
<script>prettyPrint();</script>
diff --git a/package.json b/package.json
index a8e8e0a..0cc805d 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "iii-client",
- "version": "0.0.2",
+ "version": "0.0.3",
"description": "Simple API for communicating with the bot of the \"iii.ru\" service.",
"homepage": "https://github.com/valentineus/iii-client",
"license": "MIT",
@@ -27,12 +27,14 @@
"babel-cli": "^6.24.1",
"babel-core": "^6.24.1",
"babel-preset-es2015": "^6.24.1",
+ "eslint": "^3.19.0",
"jsdoc": "^3.4.3",
"minami": "^1.2.3"
},
"scripts": {
+ "check": "eslint ./src/*",
"jsdoc": "jsdoc --template ./node_modules/minami --destination ./docs ./src/index.js",
"compile": "babel --presets es2015 --minified --no-comments --source-maps --out-dir ./lib/ ./src/",
- "prepublish": "npm run compile && npm run jsdoc"
+ "prepublish": "npm run check && npm run jsdoc && npm run compile"
}
}
diff --git a/src/index.js b/src/index.js
index 2aaada0..31e238d 100644
--- a/src/index.js
+++ b/src/index.js
@@ -6,12 +6,13 @@
var http = require('http');
+exports.connect = connect;
/**
* Connects to the server and returns the connection data.
* @param {String} uuid - The bot UUID.
* @param {requestCallback} callback - The callback that handles the response.
*/
-var connect = function(uuid, callback) {
+function connect(uuid, callback) {
uuid = uuid || '';
if (!_verification(uuid)) {
@@ -23,7 +24,7 @@ var connect = function(uuid, callback) {
hostname: 'iii.ru',
path: '/api/2.0/json/Chat.init/' + uuid + '/',
method: 'GET',
- }
+ };
const request = http.request(query, function(response) {
var json = '';
@@ -31,15 +32,12 @@ var connect = function(uuid, callback) {
response.on('end', () => callback(json.result));
});
- request.on('error', function(error) {
- console.error('Error connecting to the server!\n', error.message);
- });
+ request.on('error', (error) => Error(error.message));
request.end();
}
-exports.connect = connect;
-
+exports.send = send;
/**
* Send a message to the server and return a response.
* @param {Object} raw - The data to send.
@@ -47,7 +45,7 @@ exports.connect = connect;
* @param {String} raw.text - Message text.
* @param {requestCallback} callback - The callback that handles the response.
*/
-var send = function(raw, callback) {
+function send(raw, callback) {
raw = raw || {};
const query = {
@@ -55,7 +53,7 @@ var send = function(raw, callback) {
hostname: 'iii.ru',
path: '/api/2.0/json/Chat.request',
method: 'POST',
- }
+ };
const data = _createPackage(raw);
@@ -65,22 +63,19 @@ var send = function(raw, callback) {
response.on('end', () => callback(json));
});
- request.on('error', function(error) {
- console.error('Error sending the package!\n', error.message);
- });
+ request.on('error', (error) => Error(error));
request.write(data);
request.end();
}
-exports.send = send;
-
+exports._encrypt = _encrypt;
/**
* Encrypts the incoming data.
* @param {String} raw - Decrypted data.
* @returns {String} - Encrypted string.
*/
-var _encrypt = function(raw) {
+function _encrypt(raw) {
raw = raw || '';
var base64 = Buffer.from(raw).toString('base64');
@@ -88,14 +83,13 @@ var _encrypt = function(raw) {
return _merger(string).toString('base64');
}
-exports._encrypt = _encrypt;
-
+exports._decrypt = _decrypt;
/**
* Decrypts the incoming data.
* @param {String} raw - Encrypted data.
* @returns {String} - Decrypted string.
*/
-var _decrypt = function(raw) {
+function _decrypt(raw) {
raw = raw || '';
var string = Buffer.from(raw, 'base64');
@@ -103,14 +97,13 @@ var _decrypt = function(raw) {
return Buffer.from(decrypted, 'base64');
}
-exports._decrypt = _decrypt;
-
+exports._decryptJSON = _decryptJSON;
/**
* Decrypts an encrypted JSON object.
* @param {String} raw - Encrypted data.
* @returns {Object} - Decrypted JSON.
*/
-var _decryptJSON = function(raw) {
+function _decryptJSON(raw) {
raw = raw || '';
var string = raw.toString('ascii');
@@ -118,14 +111,13 @@ var _decryptJSON = function(raw) {
return JSON.parse(data);
}
-exports._decryptJSON = _decryptJSON;
-
+exports._merger = _merger;
/**
* Merge and convert a string.
* @param {String} raw - The string to convert.
* @returns {String} - The converted string.
*/
-var _merger = function(data) {
+function _merger(data) {
data = data || '';
const salt = Buffer.from('some very-very long string without any non-latin characters due to different string representations inside of variable programming languages');
@@ -137,8 +129,7 @@ var _merger = function(data) {
return data;
}
-exports._merger = _merger;
-
+exports._createPackage = _createPackage;
/**
* Creates an encrypted package to send.
* @param {Object} raw - The data to send.
@@ -146,7 +137,7 @@ exports._merger = _merger;
* @param {String} raw.text - Message text.
* @returns {String} - Encrypted string.
*/
-var _createPackage = function(raw) {
+function _createPackage(raw) {
raw = raw || {};
if (!raw.text) {
@@ -165,17 +156,14 @@ var _createPackage = function(raw) {
return _encrypt(json);
}
-exports._createPackage = _createPackage;
-
+exports._verification = _verification;
/**
* Validation UUID format string.
* @param {String} data - The string to check.
* @returns {Boolean}
*/
-var _verification = function(data) {
+function _verification(data) {
data = data || '';
const regexp = new RegExp('^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$', 'i');
return regexp.test(data);
}
-
-exports._verification = _verification;