Cleanup more Codeclimate issues (#267)
* Cleanup more Codeclimate issues * Cleanup unused imports
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { logger } from './index';
|
||||
import { format } from './logger';
|
||||
|
||||
describe('logger', () => {
|
||||
let dateMatch;
|
||||
@@ -39,6 +40,16 @@ describe('logger', () => {
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
describe('format', () => {
|
||||
it('returns null as-is', () => {
|
||||
expect(format(null)).toEqual(null);
|
||||
});
|
||||
|
||||
it('returns undefined as-is', () => {
|
||||
expect(format(undefined)).toEqual(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
it('logs to console.log with .log', () => {
|
||||
l.log('console.log test');
|
||||
|
||||
|
||||
+10
-14
@@ -11,9 +11,7 @@ import isBn from './is/bn';
|
||||
import isBuffer from './is/buffer';
|
||||
import isFunction from './is/function';
|
||||
import isObject from './is/object';
|
||||
import isNull from './is/null';
|
||||
import isU8a from './is/u8a';
|
||||
import isUndefined from './is/undefined';
|
||||
import u8aToHex from './u8a/toHex';
|
||||
|
||||
type ConsoleType = 'error' | 'log' | 'warn';
|
||||
@@ -33,13 +31,15 @@ const chalked = {
|
||||
warn: chalk.yellow
|
||||
};
|
||||
|
||||
export function format (value: any): any {
|
||||
if (isNull(value)) {
|
||||
return null;
|
||||
} else if (isUndefined(value)) {
|
||||
return undefined;
|
||||
}
|
||||
function formatObject (value: { [index: string]: any }): any {
|
||||
return Object.keys(value).reduce((result, key) => {
|
||||
result[key] = format(value[key]);
|
||||
|
||||
return result;
|
||||
}, {} as { [index: string]: any });
|
||||
}
|
||||
|
||||
export function format (value: any): any {
|
||||
if (Array.isArray(value)) {
|
||||
return value.map(format);
|
||||
}
|
||||
@@ -56,12 +56,8 @@ export function format (value: any): any {
|
||||
return u8aToHex(value);
|
||||
}
|
||||
|
||||
if (isObject(value) && value.constructor === Object) {
|
||||
return Object.keys(value).reduce((result, key) => {
|
||||
result[key] = format(value[key]);
|
||||
|
||||
return result;
|
||||
}, {} as { [index: string]: any });
|
||||
if (value && isObject(value) && value.constructor === Object) {
|
||||
return formatObject(value);
|
||||
}
|
||||
|
||||
return value;
|
||||
|
||||
@@ -35,11 +35,9 @@ export default function u8aToU8a (value?: Array<number> | Buffer | Uint8Array |
|
||||
}
|
||||
|
||||
if (isString(value)) {
|
||||
if (isHex(value)) {
|
||||
return hexToU8a(value);
|
||||
}
|
||||
|
||||
return stringToU8a(value);
|
||||
return isHex(value)
|
||||
? hexToU8a(value)
|
||||
: stringToU8a(value);
|
||||
}
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
|
||||
Reference in New Issue
Block a user