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 4.0.6 to 4.0.7

6

dist/index.d.ts

@@ -1,4 +0,4 @@

export { default as Stats } from './lib/stats';
export { default as Stat } from './lib/stat';
export { default as _getHiResTimestamp } from './utils/hi-res-timestamp';
export { default as Stats } from "./lib/stats.js";
export { default as Stat } from "./lib/stat.js";
export { default as _getHiResTimestamp } from "./utils/hi-res-timestamp.js";
//# sourceMappingURL=index.d.ts.map
export { default as Stats } from "./lib/stats.js";
export { default as Stat } from "./lib/stat.js";
// UTILITIES
export { default as _getHiResTimestamp } from "./utils/hi-res-timestamp.js";
//# sourceMappingURL=index.js.map
import getHiResTimestamp from "../utils/hi-res-timestamp.js";
export default class Stat {
constructor(name, type) {
this.name = void 0;
this.type = void 0;
this.sampleSize = 1;
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;
this.name = name;
this.type = type;
this.reset();
}
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;
}
setSampleSize(samples) {
this.sampleSize = samples;
return this;
}
incrementCount() {
this.addCount(1);
return this;
}
decrementCount() {
this.subtractCount(1);
return this;
}
addCount(value) {
this._count += value;
this._samples++;
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 = getHiResTimestamp();
this._timerPending = true;
return this;
}
timeEnd() {
if (!this._timerPending) {
return this;
constructor(name, type) {
this.sampleSize = 1;
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;
this.name = name;
this.type = type;
this.reset();
}
this.addTime(getHiResTimestamp() - this._startTime);
this._timerPending = false;
this._checkSampling();
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;
}
_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;
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;
}
}
setSampleSize(samples) {
this.sampleSize = samples;
return this;
}
/** Call to increment count (+1) */
incrementCount() {
this.addCount(1);
return this;
}
/** Call to decrement count (-1) */
decrementCount() {
this.subtractCount(1);
return this;
}
/** Increase count */
addCount(value) {
this._count += value;
this._samples++;
this._checkSampling();
return this;
}
/** Decrease count */
subtractCount(value) {
this._count -= value;
this._samples++;
this._checkSampling();
return this;
}
/** Add an arbitrary timing and bump the count */
addTime(time) {
this._time += time;
this.lastTiming = time;
this._samples++;
this._checkSampling();
return this;
}
/** Start a timer */
timeStart() {
this._startTime = getHiResTimestamp();
this._timerPending = true;
return this;
}
/** End a timer. Adds to time and bumps the timing count. */
timeEnd() {
if (!this._timerPending) {
return this;
}
this.addTime(getHiResTimestamp() - this._startTime);
this._timerPending = false;
this._checkSampling();
return this;
}
getSampleAverageCount() {
return this.sampleSize > 0 ? this.lastSampleCount / this.sampleSize : 0;
}
/** Calculate average time / count for the previous window */
getSampleAverageTime() {
return this.sampleSize > 0 ? this.lastSampleTime / this.sampleSize : 0;
}
/** Calculate counts per second for the previous window */
getSampleHz() {
return this.lastSampleTime > 0 ? this.sampleSize / (this.lastSampleTime / 1000) : 0;
}
getAverageCount() {
return this.samples > 0 ? this.count / this.samples : 0;
}
/** Calculate average time / count */
getAverageTime() {
return this.samples > 0 ? this.time / this.samples : 0;
}
/** Calculate counts per second */
getHz() {
return this.time > 0 ? this.samples / (this.time / 1000) : 0;
}
_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;
}
}
}
//# sourceMappingURL=stat.js.map

@@ -1,2 +0,2 @@

import Stat from './stat';
import Stat from "./stat.js";
type TableEntry = {

@@ -3,0 +3,0 @@ time: number;

@@ -0,79 +1,60 @@

// probe.gl, MIT license
import Stat from "./stat.js";
/** A "bag" of `Stat` objects, can be visualized using `StatsWidget` */
export default class Stats {
constructor(options) {
this.id = void 0;
this.stats = {};
this.id = options.id;
this.stats = {};
this._initializeStats(options.stats);
Object.seal(this);
}
get(name) {
let type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'count';
return this._getOrCreate({
name,
type
});
}
get size() {
return Object.keys(this.stats).length;
}
reset() {
for (const stat of Object.values(this.stats)) {
stat.reset();
constructor(options) {
this.stats = {};
this.id = options.id;
this.stats = {};
this._initializeStats(options.stats);
Object.seal(this);
}
return this;
}
forEach(fn) {
for (const stat of Object.values(this.stats)) {
fn(stat);
/** Acquire a stat. Create if it doesn't exist. */
get(name, type = 'count') {
return this._getOrCreate({ name, type });
}
}
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() {
let stats = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
stats.forEach(stat => this._getOrCreate(stat));
}
_getOrCreate(stat) {
const {
name,
type
} = stat;
let result = this.stats[name];
if (!result) {
if (stat instanceof Stat) {
result = stat;
} else {
result = new Stat(name, type);
}
this.stats[name] = result;
get size() {
return Object.keys(this.stats).length;
}
return result;
}
/** Reset all stats */
reset() {
for (const stat of Object.values(this.stats)) {
stat.reset();
}
return this;
}
forEach(fn) {
for (const stat of Object.values(this.stats)) {
fn(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) {
const { name, type } = stat;
let result = this.stats[name];
if (!result) {
if (stat instanceof Stat) {
result = stat;
}
else {
result = new Stat(name, type);
}
this.stats[name] = result;
}
return result;
}
}
//# sourceMappingURL=stats.js.map

@@ -0,15 +1,34 @@

// Copyright (c) 2017 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
export default function getHiResTimestamp() {
let timestamp;
if (typeof window !== 'undefined' && window.performance) {
timestamp = window.performance.now();
} else if (typeof process !== 'undefined' && process.hrtime) {
const timeParts = process.hrtime();
timestamp = timeParts[0] * 1000 + timeParts[1] / 1e6;
} else {
timestamp = Date.now();
}
return timestamp;
let timestamp;
// Get best timer available.
if (typeof window !== 'undefined' && window.performance) {
timestamp = window.performance.now();
}
else if (typeof process !== 'undefined' && process.hrtime) {
const timeParts = process.hrtime();
timestamp = timeParts[0] * 1000 + timeParts[1] / 1e6;
}
else {
timestamp = Date.now();
}
return timestamp;
}
//# sourceMappingURL=hi-res-timestamp.js.map

@@ -6,3 +6,3 @@ {

"type": "module",
"version": "4.0.6",
"version": "4.0.7",
"keywords": [

@@ -34,6 +34,3 @@ "javascript",

],
"dependencies": {
"@babel/runtime": "^7.0.0"
},
"gitHead": "ed10fc803b4b0feb08bdcde39ef9407db1f79e64"
"gitHead": "e1192bb8b78fb8f713519ab693638408da08de16"
}

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