add: lint && fix: util var error

This commit is contained in:
lancegin
2017-09-12 14:39:25 +08:00
parent 5a9f7f2730
commit fb84dbfe93
2 changed files with 22 additions and 18 deletions
+2 -1
View File
@@ -9,7 +9,8 @@
}, },
"scripts": { "scripts": {
"test": "mocha --compilers js:babel-core/register", "test": "mocha --compilers js:babel-core/register",
"build": "babel src -d lib" "build": "babel src -d lib",
"lint": "eslint src/**.js ; exit 0"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
+20 -17
View File
@@ -20,14 +20,15 @@ export class Util {
* @return {String} * @return {String}
*/ */
static rjust(num, n) { static rjust(num, n) {
let len = num.toString().length; let numTmp = num;
let len = numTmp.toString().length;
while (len < n) { while (len < n) {
num = `0${num}`; numTmp = `0${numTmp}`;
len++; len += 1;
} }
return num; return numTmp;
} }
/* /*
@@ -44,15 +45,16 @@ export class Util {
* @return {BYTES} * @return {BYTES}
*/ */
static arr_rjust(arr, n) { static arr_rjust(arr, n) {
if (n <= arr.length) { let arrTmp = arr;
arr = arr.splice(arr.length - 1 - n); if (n <= arrTmp.length) {
return arr; arrTmp = arrTmp.splice(arrTmp.length - 1 - n);
return arrTmp;
} }
const diff = n - arr.length; const diff = n - arrTmp.length;
for (let i = 0; i < diff; i++) { for (let i = 0; i < diff; i += 1) {
arr.unshift(String.fromCharCode(0)); arrTmp.unshift(String.fromCharCode(0));
} }
return arr; return arrTmp;
} }
/* /*
@@ -78,11 +80,12 @@ export class Util {
* @return {BYTES} * @return {BYTES}
*/ */
static int_to_bytestring(input, padding = 8) { static int_to_bytestring(input, padding = 8) {
let inputTmp = input;
let result = []; let result = [];
while (input != 0) { while (inputTmp !== 0) {
result.push(String.fromCharCode(input & 0xFF)); result.push(String.fromCharCode(inputTmp & 0xFF));
input >>= 8; inputTmp >>= 8;
} }
result = result.reverse(); result = result.reverse();
@@ -106,11 +109,11 @@ export class Util {
* @return {Int} * @return {Int}
*/ */
static timecode(time, interval) { static timecode(time, interval) {
const time_str = Date.parse(time).toString(); const timeStr = Date.parse(time).toString();
// fotmat the time, the ms is not needed. // fotmat the time, the ms is not needed.
const format_time = time_str.substring(0, time_str.length - 3); const formatTime = timeStr.substring(0, timeStr.length - 3);
return parseInt(parseInt(format_time) / interval); return parseInt(parseInt(formatTime) / interval);
} }
} }