Skip to content

Commit

Permalink
fix: imports
Browse files Browse the repository at this point in the history
  • Loading branch information
vltansky committed Apr 27, 2020
1 parent b986f3a commit 163cfba
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 215 deletions.
18 changes: 8 additions & 10 deletions lib/cjs/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ interface IElapsedLogger {
parse(hrtime: HrTime): string;
}
declare type HrTime = [number, number];
declare class SimpleTimeLogger {
private _timers;
start: (label?: string | null) => IElapsedLogger;
end: (label: string, overrideLabel?: string | null) => void;
get: (label: string) => string | boolean;
}
declare const elapsed: SimpleTimeLogger;
export declare const get: (label: string) => string | boolean;
export declare const end: (label: string, overrideLabel?: string | null) => void;
export declare const start: (label?: string | null) => IElapsedLogger;
export default elapsed;
export declare const end: (label: string, overrideLabel?: string | null) => void;
export declare const get: (label: string) => string | boolean;
declare const _default: {
get: (label: string) => string | boolean;
end: (label: string, overrideLabel?: string | null) => void;
start: (label?: string | null) => IElapsedLogger;
};
export default _default;
68 changes: 31 additions & 37 deletions lib/cjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,41 +40,35 @@ var ElapsedLogger = /** @class */ (function () {
};
return ElapsedLogger;
}());
var SimpleTimeLogger = /** @class */ (function () {
function SimpleTimeLogger() {
var _this = this;
this._timers = new Map();
this.start = function (label) {
if (label === void 0) { label = null; }
var elapsed = new ElapsedLogger();
if (!label) {
return elapsed;
}
_this._timers.set(label, elapsed);
return elapsed;
};
this.end = function (label, overrideLabel) {
if (overrideLabel === void 0) { overrideLabel = null; }
var elapsedTime = _this.get(label);
if (elapsedTime === false) {
return;
}
console.log((overrideLabel || label) + " " + elapsedTime);
_this._timers.delete(label);
};
this.get = function (label) {
var timer = _this._timers.get(label);
if (!timer) {
console.warn("No such label '" + label + "' for ElapsedLogger"); //process.emitWarning
return false;
}
return timer.get();
};
var _timers = new Map();
exports.start = function (label) {
if (label === void 0) { label = null; }
var elapsed = new ElapsedLogger();
if (!label) {
return elapsed;
}
return SimpleTimeLogger;
}());
var elapsed = new SimpleTimeLogger();
exports.get = elapsed.get;
exports.end = elapsed.end;
exports.start = elapsed.start;
exports.default = elapsed;
_timers.set(label, elapsed);
return elapsed;
};
exports.end = function (label, overrideLabel) {
if (overrideLabel === void 0) { overrideLabel = null; }
var elapsedTime = exports.get(label);
if (elapsedTime === false) {
return;
}
console.log((overrideLabel || label) + " " + elapsedTime);
_timers.delete(label);
};
exports.get = function (label) {
var timer = _timers.get(label);
if (!timer) {
console.warn("No such label '" + label + "' for ElapsedLogger"); //process.emitWarning
return false;
}
return timer.get();
};
exports.default = {
get: exports.get,
end: exports.end,
start: exports.start
};
18 changes: 0 additions & 18 deletions lib/es2015/index.d.ts

This file was deleted.

72 changes: 0 additions & 72 deletions lib/es2015/index.js

This file was deleted.

18 changes: 8 additions & 10 deletions lib/esm/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ interface IElapsedLogger {
parse(hrtime: HrTime): string;
}
declare type HrTime = [number, number];
declare class SimpleTimeLogger {
private _timers;
start: (label?: string | null) => IElapsedLogger;
end: (label: string, overrideLabel?: string | null) => void;
get: (label: string) => string | boolean;
}
declare const elapsed: SimpleTimeLogger;
export declare const get: (label: string) => string | boolean;
export declare const end: (label: string, overrideLabel?: string | null) => void;
export declare const start: (label?: string | null) => IElapsedLogger;
export default elapsed;
export declare const end: (label: string, overrideLabel?: string | null) => void;
export declare const get: (label: string) => string | boolean;
declare const _default: {
get: (label: string) => string | boolean;
end: (label: string, overrideLabel?: string | null) => void;
start: (label?: string | null) => IElapsedLogger;
};
export default _default;
68 changes: 31 additions & 37 deletions lib/esm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,41 +38,35 @@ var ElapsedLogger = /** @class */ (function () {
};
return ElapsedLogger;
}());
var SimpleTimeLogger = /** @class */ (function () {
function SimpleTimeLogger() {
var _this = this;
this._timers = new Map();
this.start = function (label) {
if (label === void 0) { label = null; }
var elapsed = new ElapsedLogger();
if (!label) {
return elapsed;
}
_this._timers.set(label, elapsed);
return elapsed;
};
this.end = function (label, overrideLabel) {
if (overrideLabel === void 0) { overrideLabel = null; }
var elapsedTime = _this.get(label);
if (elapsedTime === false) {
return;
}
console.log((overrideLabel || label) + " " + elapsedTime);
_this._timers.delete(label);
};
this.get = function (label) {
var timer = _this._timers.get(label);
if (!timer) {
console.warn("No such label '" + label + "' for ElapsedLogger"); //process.emitWarning
return false;
}
return timer.get();
};
var _timers = new Map();
export var start = function (label) {
if (label === void 0) { label = null; }
var elapsed = new ElapsedLogger();
if (!label) {
return elapsed;
}
return SimpleTimeLogger;
}());
var elapsed = new SimpleTimeLogger();
export var get = elapsed.get;
export var end = elapsed.end;
export var start = elapsed.start;
export default elapsed;
_timers.set(label, elapsed);
return elapsed;
};
export var end = function (label, overrideLabel) {
if (overrideLabel === void 0) { overrideLabel = null; }
var elapsedTime = get(label);
if (elapsedTime === false) {
return;
}
console.log((overrideLabel || label) + " " + elapsedTime);
_timers.delete(label);
};
export var get = function (label) {
var timer = _timers.get(label);
if (!timer) {
console.warn("No such label '" + label + "' for ElapsedLogger"); //process.emitWarning
return false;
}
return timer.get();
};
export default {
get: get,
end: end,
start: start
};
2 changes: 1 addition & 1 deletion lib/umd/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
],
"scripts": {
"test": "jest --collectCoverage=true",
"build": "npm run build:es2015 && npm run build:esm && npm run build:cjs && npm run build:umd && npm run build:umd:min",
"build:es2015": "tsc --module es2015 --target es2015 --outDir lib/es2015",
"build": "npm run build:esm && npm run build:cjs && npm run build:umd && npm run build:umd:min",
"build:esm": "tsc --module es2015 --target es5 --outDir lib/esm",
"build:cjs": "tsc --module commonjs --target es5 --outDir lib/cjs",
"build:umd": "rollup -c",
Expand Down
51 changes: 25 additions & 26 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,36 +50,35 @@ class ElapsedLogger implements IElapsedLogger {
return result;
}
}
class SimpleTimeLogger {
private _timers = new Map<string, IElapsedLogger>();

start = (label: string | null = null): IElapsedLogger => {
const elapsed = new ElapsedLogger();
if (!label) {
return elapsed;
}
this._timers.set(label, elapsed);
const _timers = new Map<string, IElapsedLogger>();

export const start = (label: string | null = null): IElapsedLogger => {
const elapsed = new ElapsedLogger();
if (!label) {
return elapsed;
}
_timers.set(label, elapsed);
return elapsed;
}

end = (label: string, overrideLabel: string | null = null): void => {
const elapsedTime = this.get(label);
if(elapsedTime === false){ return; }
console.log(`${overrideLabel || label} ${elapsedTime}`);
this._timers.delete(label);
}
export const end = (label: string, overrideLabel: string | null = null): void => {
const elapsedTime = get(label);
if(elapsedTime === false){ return; }
console.log(`${overrideLabel || label} ${elapsedTime}`);
_timers.delete(label);
}

get = (label: string): string | boolean => {
const timer = this._timers.get(label);
if (!timer) {
console.warn(`No such label '${label}' for ElapsedLogger`);//process.emitWarning
return false;
}
return timer.get();
export const get = (label: string): string | boolean => {
const timer = _timers.get(label);
if (!timer) {
console.warn(`No such label '${label}' for ElapsedLogger`);//process.emitWarning
return false;
}
return timer.get();
}
const elapsed = new SimpleTimeLogger();
export const get = elapsed.get;
export const end = elapsed.end;
export const start = elapsed.start;
export default elapsed;
export default {
get: get,
end: end,
start: start
}
4 changes: 2 additions & 2 deletions tests/browser/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ process = revert;
console.log = jest.fn();
describe("Log function", () => {
it('should output 1.2 seconds', () => {
const mockHrtime = jest.spyOn(elapsed, 'get').mockReturnValue('1.2 seconds ');
elapsed.start('test');
const elapsedTimer = elapsed.start('test');
const mockHrtime = jest.spyOn(elapsedTimer, 'get').mockReturnValue('1.2 seconds ');
elapsed.end('test');
mockHrtime.mockRestore();
expect(console.log).toHaveBeenCalledWith('test 1.2 seconds ');
Expand Down

0 comments on commit 163cfba

Please sign in to comment.