@neo-one/utils
Advanced tools
Comparing version 0.0.2 to 0.1.0
160
dist/es.js
@@ -1,2 +0,2 @@ | ||
import { Observable as Observable$1 } from 'rxjs/Observable'; | ||
import { Observable } from 'rxjs/Observable'; | ||
import uuidV4 from 'uuid/v4'; | ||
@@ -40,2 +40,24 @@ | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
} | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
} | ||
function _extends() { | ||
@@ -93,5 +115,99 @@ _extends = Object.assign || function (target) { | ||
var loadTime = Date.now(); | ||
var now = function now() { | ||
if (typeof performance !== 'undefined' && performance && performance.now) { | ||
return performance.now(); | ||
} else if (process) { | ||
// So webpack doesn't try to bundle it. | ||
var perfHooks = 'perf_hooks'; // $FlowFixMe | ||
return require(perfHooks).performance.now(); // eslint-disable-line | ||
} | ||
return Date.now() - loadTime; | ||
}; // eslint-disable-next-line | ||
var createProfile = function createProfile(log) { | ||
return function (point, data) { | ||
var start = now(); | ||
return { | ||
stop: function stop() { | ||
var durationMS = now() - start; | ||
if (durationMS > 1) { | ||
log(_extends({ | ||
event: 'PROFILE' | ||
}, data || {}, { | ||
point: point, | ||
durationMS: durationMS | ||
})); | ||
} | ||
} | ||
}; | ||
}; | ||
}; | ||
var Performance = | ||
/*#__PURE__*/ | ||
function () { | ||
function Performance() { | ||
_classCallCheck(this, Performance); | ||
this._durations = {}; | ||
this._counts = {}; | ||
} | ||
_createClass(Performance, [{ | ||
key: "start", | ||
value: function start(name) { | ||
var _this = this; | ||
var start = now(); | ||
return function () { | ||
var duration = now() - start; | ||
if (_this._durations[name] == null) { | ||
_this._durations[name] = 0; | ||
_this._counts[name] = 0; | ||
} | ||
_this._durations[name] += duration; | ||
_this._counts[name] += 1; | ||
}; | ||
} | ||
}, { | ||
key: "getCount", | ||
value: function getCount(name) { | ||
return this._counts[name] || 0; | ||
} | ||
}, { | ||
key: "reset", | ||
value: function reset() { | ||
this._durations = {}; | ||
this._counts = {}; | ||
} | ||
}, { | ||
key: "toStats", | ||
value: function toStats() { | ||
var normalizedDurations = {}; | ||
var _arr = Object.keys(this._durations); | ||
for (var _i = 0; _i < _arr.length; _i++) { | ||
var _key = _arr[_i]; | ||
normalizedDurations[_key] = this._durations[_key] / this._counts[_key]; | ||
} | ||
return { | ||
durations: _extends({}, this._durations), | ||
counts: _extends({}, this._counts), | ||
normalizedDurations: normalizedDurations | ||
}; | ||
} | ||
}]); | ||
return Performance; | ||
}(); | ||
function finalize(func) { | ||
return function (source) { | ||
return Observable$1.create(function (observer) { | ||
return Observable.create(function (observer) { | ||
var lastValue; | ||
@@ -170,36 +286,2 @@ var subscription = source.subscribe({ | ||
var loadTime = Date.now(); | ||
var now = function now() { | ||
if (typeof performance !== 'undefined' && performance && performance.now) { | ||
return performance.now(); | ||
} else if (process) { | ||
// So webpack doesn't try to bundle it. | ||
var perfHooks = 'perf_hooks'; // $FlowFixMe | ||
return require(perfHooks).performance.now(); // eslint-disable-line | ||
} | ||
return Date.now() - loadTime; | ||
}; // eslint-disable-next-line | ||
var createProfile = function createProfile(log) { | ||
return function (point, data) { | ||
var start = now(); | ||
return { | ||
stop: function stop() { | ||
var durationMS = now() - start; | ||
if (durationMS > 1) { | ||
log(_extends({ | ||
event: 'PROFILE' | ||
}, data || {}, { | ||
point: point, | ||
durationMS: durationMS | ||
})); | ||
} | ||
} | ||
}; | ||
}; | ||
}; | ||
function logInvoke(_x, _x2, _x3, _x4, _x5) { | ||
@@ -276,3 +358,3 @@ return _logInvoke.apply(this, arguments); | ||
return function (source) { | ||
return Observable$1.create(function (observer) { | ||
return Observable.create(function (observer) { | ||
return source.subscribe({ | ||
@@ -293,3 +375,3 @@ next: function next(value) { | ||
return function (source) { | ||
return Observable$1.create(function (observer) { | ||
return Observable.create(function (observer) { | ||
return source.subscribe({ | ||
@@ -440,3 +522,3 @@ next: function next(value) { | ||
export { CustomError, finalize, createProfile, now as performanceNow, logInvoke, neverComplete, onComplete, setupCLI, utils }; | ||
export { CustomError, Performance, finalize, createProfile, now as performanceNow, logInvoke, neverComplete, onComplete, setupCLI, utils }; | ||
//# sourceMappingURL=es.js.map |
@@ -46,2 +46,24 @@ 'use strict'; | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
} | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
} | ||
function _extends() { | ||
@@ -99,2 +121,96 @@ _extends = Object.assign || function (target) { | ||
var loadTime = Date.now(); | ||
var now = function now() { | ||
if (typeof performance !== 'undefined' && performance && performance.now) { | ||
return performance.now(); | ||
} else if (process) { | ||
// So webpack doesn't try to bundle it. | ||
var perfHooks = 'perf_hooks'; // $FlowFixMe | ||
return require(perfHooks).performance.now(); // eslint-disable-line | ||
} | ||
return Date.now() - loadTime; | ||
}; // eslint-disable-next-line | ||
var createProfile = function createProfile(log) { | ||
return function (point, data) { | ||
var start = now(); | ||
return { | ||
stop: function stop() { | ||
var durationMS = now() - start; | ||
if (durationMS > 1) { | ||
log(_extends({ | ||
event: 'PROFILE' | ||
}, data || {}, { | ||
point: point, | ||
durationMS: durationMS | ||
})); | ||
} | ||
} | ||
}; | ||
}; | ||
}; | ||
var Performance = | ||
/*#__PURE__*/ | ||
function () { | ||
function Performance() { | ||
_classCallCheck(this, Performance); | ||
this._durations = {}; | ||
this._counts = {}; | ||
} | ||
_createClass(Performance, [{ | ||
key: "start", | ||
value: function start(name) { | ||
var _this = this; | ||
var start = now(); | ||
return function () { | ||
var duration = now() - start; | ||
if (_this._durations[name] == null) { | ||
_this._durations[name] = 0; | ||
_this._counts[name] = 0; | ||
} | ||
_this._durations[name] += duration; | ||
_this._counts[name] += 1; | ||
}; | ||
} | ||
}, { | ||
key: "getCount", | ||
value: function getCount(name) { | ||
return this._counts[name] || 0; | ||
} | ||
}, { | ||
key: "reset", | ||
value: function reset() { | ||
this._durations = {}; | ||
this._counts = {}; | ||
} | ||
}, { | ||
key: "toStats", | ||
value: function toStats() { | ||
var normalizedDurations = {}; | ||
var _arr = Object.keys(this._durations); | ||
for (var _i = 0; _i < _arr.length; _i++) { | ||
var _key = _arr[_i]; | ||
normalizedDurations[_key] = this._durations[_key] / this._counts[_key]; | ||
} | ||
return { | ||
durations: _extends({}, this._durations), | ||
counts: _extends({}, this._counts), | ||
normalizedDurations: normalizedDurations | ||
}; | ||
} | ||
}]); | ||
return Performance; | ||
}(); | ||
function finalize(func) { | ||
@@ -176,36 +292,2 @@ return function (source) { | ||
var loadTime = Date.now(); | ||
var now = function now() { | ||
if (typeof performance !== 'undefined' && performance && performance.now) { | ||
return performance.now(); | ||
} else if (process) { | ||
// So webpack doesn't try to bundle it. | ||
var perfHooks = 'perf_hooks'; // $FlowFixMe | ||
return require(perfHooks).performance.now(); // eslint-disable-line | ||
} | ||
return Date.now() - loadTime; | ||
}; // eslint-disable-next-line | ||
var createProfile = function createProfile(log) { | ||
return function (point, data) { | ||
var start = now(); | ||
return { | ||
stop: function stop() { | ||
var durationMS = now() - start; | ||
if (durationMS > 1) { | ||
log(_extends({ | ||
event: 'PROFILE' | ||
}, data || {}, { | ||
point: point, | ||
durationMS: durationMS | ||
})); | ||
} | ||
} | ||
}; | ||
}; | ||
}; | ||
function logInvoke(_x, _x2, _x3, _x4, _x5) { | ||
@@ -445,2 +527,3 @@ return _logInvoke.apply(this, arguments); | ||
exports.CustomError = CustomError; | ||
exports.Performance = Performance; | ||
exports.finalize = finalize; | ||
@@ -447,0 +530,0 @@ exports.createProfile = createProfile; |
{ | ||
"name": "@neo-one/utils", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"keywords": [ | ||
@@ -38,4 +38,4 @@ "neo", | ||
"rxjs": "^5.5.6", | ||
"uuid": "^3.1.0" | ||
"uuid": "^3.2.1" | ||
} | ||
} |
/* @flow */ | ||
export { default as CustomError } from './CustomError'; | ||
export { default as Performance } from './Performance'; | ||
export { default as finalize } from './finalize'; | ||
@@ -4,0 +5,0 @@ export { createProfile, now as performanceNow } from './log'; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
109440
17
1257
Updateduuid@^3.2.1