TinyBase logoTinyBase

hasMetric

The hasMetric method returns a boolean indicating whether a given Metric exists in the Metrics object, and has a value.

hasMetric(metricId: string): boolean
TypeDescription
metricIdstring

The Id of a possible Metric in the Metrics object.

returnsboolean

Whether a Metric with that Id exists.

Example

This example shows two simple Metric existence checks.

import {createMetrics, createStore} from 'tinybase';

const store = createStore();
const metrics = createMetrics(store);
metrics.setMetricDefinition('highestPrice', 'species', 'max', 'price');

console.log(metrics.hasMetric('lowestPrice'));
// -> false
console.log(metrics.hasMetric('highestPrice'));
// -> false
store.setTable('species', {dog: {price: 5}, cat: {price: 4}});
console.log(metrics.hasMetric('highestPrice'));
// -> true

Since

v1.0.0