-
Notifications
You must be signed in to change notification settings - Fork 0
/
PrometheusMetricName.ts
22 lines (17 loc) · 1.23 KB
/
PrometheusMetricName.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { ValidatedString, type ValidatedStringFactory } from './ValidatedString.ts';
const isPrometheusMetricName = (s: string): boolean => /^[a-zA-Z_:][a-zA-Z0-9_:]*$/.test(s);
/**
Why JSRCompatibleFactory? See https://github.com/axhxrx/validated-string/issues/1 — consumers of this lib probably don't need to deal with this
*/
const JSRCompatibleFactory = ValidatedString.create(isPrometheusMetricName, {
name: 'PrometheusMetricName',
description: 'must start with a letter, underscore, or colon, followed by letters, digits, underscores, or colons',
});
const type: ValidatedString<typeof isPrometheusMetricName> = JSRCompatibleFactory.type;
const factory: ValidatedStringFactory<typeof isPrometheusMetricName> = JSRCompatibleFactory.factory;
/**
A validated string that represents a Prometheus metric name. See {@link ValidatedString} for more information. Note that this might not really exactly match the rules for Prometheus metric names, but it's close enough for our purposes; namely, generating metrics — don't rely on this to *validate* Prometheus metric names, as it is based on a quick skim of the Prometheus docs.
@category Prometheus
*/
export type PrometheusMetricName = typeof type;
export const PrometheusMetricName = factory;