Socket
Socket
Sign inDemoInstall

@probe.gl/stats

Package Overview
Dependencies
Maintainers
3
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@probe.gl/stats - npm Package Compare versions

Comparing version 3.5.0-alpha.1 to 3.5.0-alpha.2

dist/index.d.ts

6

dist/es5/index.js

@@ -10,3 +10,3 @@ "use strict";

enumerable: true,
get: function get() {
get: function () {
return _stats.default;

@@ -17,3 +17,3 @@ }

enumerable: true,
get: function get() {
get: function () {
return _stat.default;

@@ -24,3 +24,3 @@ }

enumerable: true,
get: function get() {
get: function () {
return _hiResTimestamp.default;

@@ -27,0 +27,0 @@ }

@@ -10,6 +10,2 @@ "use strict";

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

@@ -19,5 +15,4 @@

var Stat = function () {
function Stat(name, type) {
(0, _classCallCheck2.default)(this, Stat);
class Stat {
constructor(name, type) {
(0, _defineProperty2.default)(this, "name", void 0);

@@ -42,137 +37,119 @@ (0, _defineProperty2.default)(this, "type", void 0);

(0, _createClass2.default)(Stat, [{
key: "setSampleSize",
value: function setSampleSize(samples) {
this.sampleSize = samples;
return this;
}
}, {
key: "incrementCount",
value: function incrementCount() {
this.addCount(1);
return this;
}
}, {
key: "decrementCount",
value: function decrementCount() {
this.subtractCount(1);
return this;
}
}, {
key: "addCount",
value: function addCount(value) {
this._count += value;
this._samples++;
setSampleSize(samples) {
this.sampleSize = samples;
return this;
}
this._checkSampling();
incrementCount() {
this.addCount(1);
return this;
}
return this;
}
}, {
key: "subtractCount",
value: function subtractCount(value) {
this._count -= value;
this._samples++;
decrementCount() {
this.subtractCount(1);
return this;
}
this._checkSampling();
addCount(value) {
this._count += value;
this._samples++;
return this;
}
}, {
key: "addTime",
value: function addTime(time) {
this._time += time;
this.lastTiming = time;
this._samples++;
this._checkSampling();
this._checkSampling();
return this;
}
subtractCount(value) {
this._count -= value;
this._samples++;
this._checkSampling();
return this;
}
addTime(time) {
this._time += time;
this.lastTiming = time;
this._samples++;
this._checkSampling();
return this;
}
timeStart() {
this._startTime = (0, _hiResTimestamp.default)();
this._timerPending = true;
return this;
}
timeEnd() {
if (!this._timerPending) {
return this;
}
}, {
key: "timeStart",
value: function timeStart() {
this._startTime = (0, _hiResTimestamp.default)();
this._timerPending = true;
return this;
}
}, {
key: "timeEnd",
value: function timeEnd() {
if (!this._timerPending) {
return this;
}
this.addTime((0, _hiResTimestamp.default)() - this._startTime);
this._timerPending = false;
this.addTime((0, _hiResTimestamp.default)() - this._startTime);
this._timerPending = false;
this._checkSampling();
this._checkSampling();
return this;
}
}, {
key: "getSampleAverageCount",
value: function getSampleAverageCount() {
return this.sampleSize > 0 ? this.lastSampleCount / this.sampleSize : 0;
}
}, {
key: "getSampleAverageTime",
value: function getSampleAverageTime() {
return this.sampleSize > 0 ? this.lastSampleTime / this.sampleSize : 0;
}
}, {
key: "getSampleHz",
value: function getSampleHz() {
return this.lastSampleTime > 0 ? this.sampleSize / (this.lastSampleTime / 1000) : 0;
}
}, {
key: "getAverageCount",
value: function getAverageCount() {
return this.samples > 0 ? this.count / this.samples : 0;
}
}, {
key: "getAverageTime",
value: function getAverageTime() {
return this.samples > 0 ? this.time / this.samples : 0;
}
}, {
key: "getHz",
value: function getHz() {
return this.time > 0 ? this.samples / (this.time / 1000) : 0;
}
}, {
key: "reset",
value: function reset() {
this.time = 0;
this.count = 0;
this.samples = 0;
this.lastTiming = 0;
this.lastSampleTime = 0;
this.lastSampleCount = 0;
return this;
}
getSampleAverageCount() {
return this.sampleSize > 0 ? this.lastSampleCount / this.sampleSize : 0;
}
getSampleAverageTime() {
return this.sampleSize > 0 ? this.lastSampleTime / this.sampleSize : 0;
}
getSampleHz() {
return this.lastSampleTime > 0 ? this.sampleSize / (this.lastSampleTime / 1000) : 0;
}
getAverageCount() {
return this.samples > 0 ? this.count / this.samples : 0;
}
getAverageTime() {
return this.samples > 0 ? this.time / this.samples : 0;
}
getHz() {
return this.time > 0 ? this.samples / (this.time / 1000) : 0;
}
reset() {
this.time = 0;
this.count = 0;
this.samples = 0;
this.lastTiming = 0;
this.lastSampleTime = 0;
this.lastSampleCount = 0;
this._count = 0;
this._time = 0;
this._samples = 0;
this._startTime = 0;
this._timerPending = false;
return this;
}
_checkSampling() {
if (this._samples === this.sampleSize) {
this.lastSampleTime = this._time;
this.lastSampleCount = this._count;
this.count += this._count;
this.time += this._time;
this.samples += this._samples;
this._time = 0;
this._count = 0;
this._time = 0;
this._samples = 0;
this._startTime = 0;
this._timerPending = false;
return this;
}
}, {
key: "_checkSampling",
value: function _checkSampling() {
if (this._samples === this.sampleSize) {
this.lastSampleTime = this._time;
this.lastSampleCount = this._count;
this.count += this._count;
this.time += this._time;
this.samples += this._samples;
this._time = 0;
this._count = 0;
this._samples = 0;
}
}
}]);
return Stat;
}();
}
}
exports.default = Stat;
//# sourceMappingURL=stat.js.map

@@ -10,6 +10,2 @@ "use strict";

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

@@ -19,5 +15,4 @@

var Stats = function () {
function Stats(options) {
(0, _classCallCheck2.default)(this, Stats);
class Stats {
constructor(options) {
(0, _defineProperty2.default)(this, "id", void 0);

@@ -33,81 +28,68 @@ (0, _defineProperty2.default)(this, "stats", {});

(0, _createClass2.default)(Stats, [{
key: "get",
value: function get(name) {
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'count';
return this._getOrCreate({
name: name,
type: type
});
get(name, type = 'count') {
return this._getOrCreate({
name,
type
});
}
get size() {
return Object.keys(this.stats).length;
}
reset() {
for (const key in this.stats) {
this.stats[key].reset();
}
}, {
key: "size",
get: function get() {
return Object.keys(this.stats).length;
}
}, {
key: "reset",
value: function reset() {
for (var key in this.stats) {
this.stats[key].reset();
}
return this;
return this;
}
forEach(fn) {
for (const key in this.stats) {
fn(this.stats[key]);
}
}, {
key: "forEach",
value: function forEach(fn) {
for (var key in this.stats) {
fn(this.stats[key]);
}
}
}, {
key: "getTable",
value: function getTable() {
var table = {};
this.forEach(function (stat) {
table[stat.name] = {
time: stat.time || 0,
count: stat.count || 0,
average: stat.getAverageTime() || 0,
hz: stat.getHz() || 0
};
});
return table;
}
}, {
key: "_initializeStats",
value: function _initializeStats() {
var _this = this;
}
var stats = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
stats.forEach(function (stat) {
return _this._getOrCreate(stat);
});
getTable() {
const table = {};
this.forEach(stat => {
table[stat.name] = {
time: stat.time || 0,
count: stat.count || 0,
average: stat.getAverageTime() || 0,
hz: stat.getHz() || 0
};
});
return table;
}
_initializeStats(stats = []) {
stats.forEach(stat => this._getOrCreate(stat));
}
_getOrCreate(stat) {
if (!stat || !stat.name) {
return null;
}
}, {
key: "_getOrCreate",
value: function _getOrCreate(stat) {
if (!stat || !stat.name) {
return null;
}
var name = stat.name,
type = stat.type;
const {
name,
type
} = stat;
if (!this.stats[name]) {
if (stat instanceof _stat.default) {
this.stats[name] = stat;
} else {
this.stats[name] = new _stat.default(name, type);
}
if (!this.stats[name]) {
if (stat instanceof _stat.default) {
this.stats[name] = stat;
} else {
this.stats[name] = new _stat.default(name, type);
}
return this.stats[name];
}
}]);
return Stats;
}();
return this.stats[name];
}
}
exports.default = Stats;
//# sourceMappingURL=stats.js.map

@@ -9,3 +9,3 @@ "use strict";

function getHiResTimestamp() {
var timestamp;
let timestamp;

@@ -15,3 +15,3 @@ if (typeof window !== 'undefined' && window.performance) {

} else if (typeof process !== 'undefined' && process.hrtime) {
var timeParts = process.hrtime();
const timeParts = process.hrtime();
timestamp = timeParts[0] * 1000 + timeParts[1] / 1e6;

@@ -18,0 +18,0 @@ } else {

@@ -5,3 +5,3 @@ {

"license": "MIT",
"version": "3.5.0-alpha.1",
"version": "3.5.0-alpha.2",
"keywords": [

@@ -19,3 +19,3 @@ "javascript",

},
"types": "src/index.ts",
"types": "dist/index.d.ts",
"main": "dist/es5/index.js",

@@ -30,3 +30,3 @@ "module": "dist/esm/index.js",

},
"gitHead": "bf4fa2cbf7acca20d734838560321f36a1ec0ee3"
"gitHead": "2703244b2ef59a86a56b1990da4ce34ce3b3d10a"
}
import getHiResTimestamp from '../utils/hi-res-timestamp';
/** Tracks a single statistic */
export default class Stat {

@@ -5,0 +4,0 @@ readonly name: string;

@@ -6,3 +6,3 @@ import Stat from './stat';

readonly id: string;
private stats = {};
readonly stats: Record<string, Stat> = {};

@@ -9,0 +9,0 @@ constructor(options: {id: string; stats?: Stats | Stat[] | {name: string; type?: string}[]}) {

@@ -21,3 +21,3 @@ // Copyright (c) 2017 Uber Technologies, Inc.

export default function getHiResTimestamp() {
export default function getHiResTimestamp(): number {
let timestamp;

@@ -24,0 +24,0 @@ // Get best timer available.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc