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.6.0 to 4.0.0-alpha.1

dist/index.cjs

8

dist/index.js

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

export { default as Stats } from './lib/stats';
export { default as Stat } from './lib/stat';
// UTILITIES
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.js.map
export default class Stat {
readonly name: string;
readonly type: string;
readonly type: string | undefined;
sampleSize: number;

@@ -17,2 +17,3 @@ time: number;

constructor(name: string, type?: string);
reset(): this;
setSampleSize(samples: number): this;

@@ -43,5 +44,4 @@ /** Call to increment count (+1) */

getHz(): number;
reset(): this;
_checkSampling(): void;
}
//# sourceMappingURL=stat.d.ts.map

@@ -1,114 +0,153 @@

import getHiResTimestamp from '../utils/hi-res-timestamp';
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import getHiResTimestamp from "../utils/hi-res-timestamp.js";
export default class Stat {
constructor(name, type) {
this.sampleSize = 1;
this._count = 0;
this._time = 0;
this._samples = 0;
this._startTime = 0;
this._timerPending = false;
this.name = name;
this.type = type;
this.reset();
constructor(name, type) {
_defineProperty(this, "name", void 0);
_defineProperty(this, "type", void 0);
_defineProperty(this, "sampleSize", 1);
_defineProperty(this, "time", 0);
_defineProperty(this, "count", 0);
_defineProperty(this, "samples", 0);
_defineProperty(this, "lastTiming", 0);
_defineProperty(this, "lastSampleTime", 0);
_defineProperty(this, "lastSampleCount", 0);
_defineProperty(this, "_count", 0);
_defineProperty(this, "_time", 0);
_defineProperty(this, "_samples", 0);
_defineProperty(this, "_startTime", 0);
_defineProperty(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;
}
setSampleSize(samples) {
this.sampleSize = samples;
return this;
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;
}
/** 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;
}
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._samples = 0;
}
}
}
}
//# sourceMappingURL=stat.js.map
import Stat from './stat';
declare type TableEntry = {
time: number;
count: number;
average: number;
hz: number;
};
/** A "bag" of `Stat` objects, can be visualized using `StatsWidget` */

@@ -14,3 +20,3 @@ export default class Stats {

/** Acquire a stat. Create if it doesn't exist. */
get(name: string, type?: string): Stat;
get(name: string, type?: string): Stat | null;
get size(): number;

@@ -20,8 +26,3 @@ /** Reset all stats */

forEach(fn: (stat: Stat) => void): void;
getTable(): Record<string, {
time: number;
count: number;
average: number;
hz: number;
}>;
getTable(): Record<string, TableEntry>;
_initializeStats(stats?: Stats | Stat[] | {

@@ -31,4 +32,8 @@ name: string;

}[]): void;
_getOrCreate(stat: any): Stat;
_getOrCreate(stat: Stat | {
name: string;
type?: string;
}): Stat | null;
}
export {};
//# sourceMappingURL=stats.d.ts.map

@@ -1,60 +0,83 @@

import Stat from './stat';
/** A "bag" of `Stat` objects, can be visualized using `StatsWidget` */
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import Stat from "./stat.js";
export default class Stats {
constructor(options) {
this.stats = {};
this.id = options.id;
this.stats = {};
this._initializeStats(options.stats);
Object.seal(this);
constructor(options) {
_defineProperty(this, "id", void 0);
_defineProperty(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();
}
/** Acquire a stat. Create if it doesn't exist. */
get(name, type = 'count') {
return this._getOrCreate({ name, type });
return this;
}
forEach(fn) {
for (const stat of Object.values(this.stats)) {
fn(stat);
}
get size() {
return Object.keys(this.stats).length;
}
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) {
if (!stat || !stat.name) {
return null;
}
/** Reset all stats */
reset() {
for (const key in this.stats) {
this.stats[key].reset();
}
return this;
const {
name,
type
} = stat;
if (!this.stats[name]) {
if (stat instanceof Stat) {
this.stats[name] = stat;
} else {
this.stats[name] = new Stat(name, type);
}
}
forEach(fn) {
for (const key in this.stats) {
fn(this.stats[key]);
}
}
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;
}
const { name, type } = stat;
if (!this.stats[name]) {
if (stat instanceof Stat) {
this.stats[name] = stat;
}
else {
this.stats[name] = new Stat(name, type);
}
}
return this.stats[name];
}
return this.stats[name] || null;
}
}
//# sourceMappingURL=stats.js.map

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

// 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;
// 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;
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;
}
//# sourceMappingURL=hi-res-timestamp.js.map

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

"license": "MIT",
"version": "3.6.0",
"type": "module",
"version": "4.0.0-alpha.1",
"keywords": [

@@ -20,4 +21,11 @@ "javascript",

"types": "dist/index.d.ts",
"main": "dist/es5/index.js",
"module": "dist/esm/index.js",
"main": "dist/index.cjs",
"module": "dist/index.js",
"exports": {
".": {
"require": "./dist/index.cjs",
"import": "./dist/index.js",
"types": "./dist/index.d.ts"
}
},
"files": [

@@ -30,3 +38,3 @@ "dist",

},
"gitHead": "4317dfd211d771250d91c10784461106fd8cb45d"
"gitHead": "b0ccf490575a284b75b761408e047cdda591f96a"
}

@@ -5,10 +5,10 @@ import getHiResTimestamp from '../utils/hi-res-timestamp';

readonly name: string;
readonly type: string;
readonly type: string | undefined;
sampleSize: number = 1;
time: number;
count: number;
samples: number;
lastTiming: number;
lastSampleTime: number;
lastSampleCount: number;
time: number = 0;
count: number = 0;
samples: number = 0;
lastTiming: number = 0;
lastSampleTime: number = 0;
lastSampleCount: number = 0;

@@ -27,2 +27,18 @@ _count: number = 0;

reset(): this {
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: number): this {

@@ -123,18 +139,2 @@ this.sampleSize = samples;

reset(): this {
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(): void {

@@ -141,0 +141,0 @@ if (this._samples === this.sampleSize) {

@@ -0,3 +1,12 @@

// probe.gl, MIT license
import Stat from './stat';
type TableEntry = {
time: number;
count: number;
average: number;
hz: number;
};
/** A "bag" of `Stat` objects, can be visualized using `StatsWidget` */

@@ -18,3 +27,3 @@ export default class Stats {

/** Acquire a stat. Create if it doesn't exist. */
get(name: string, type: string = 'count'): Stat {
get(name: string, type: string = 'count'): Stat | null {
return this._getOrCreate({name, type});

@@ -29,4 +38,4 @@ }

reset(): this {
for (const key in this.stats) {
this.stats[key].reset();
for (const stat of Object.values(this.stats)) {
stat.reset();
}

@@ -38,17 +47,9 @@

forEach(fn: (stat: Stat) => void): void {
for (const key in this.stats) {
fn(this.stats[key]);
for (const stat of Object.values(this.stats)) {
fn(stat);
}
}
getTable(): Record<
string,
{
time: number;
count: number;
average: number;
hz: number;
}
> {
const table = {};
getTable(): Record<string, TableEntry> {
const table: Record<string, TableEntry> = {};
this.forEach(stat => {

@@ -70,3 +71,3 @@ table[stat.name] = {

_getOrCreate(stat): Stat {
_getOrCreate(stat: Stat | {name: string, type?: string}): Stat | null {
if (!stat || !stat.name) {

@@ -84,4 +85,4 @@ return null;

}
return this.stats[name];
return this.stats[name] || null;
}
}

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