From 565f423dd97a911908edeb6ce88304791a5fe5cf Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Thu, 24 Nov 2022 19:24:00 +0100 Subject: [PATCH] Extract stringReverse() function --- src/prometheus.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/prometheus.ts b/src/prometheus.ts index 94790c7..60d9d6c 100644 --- a/src/prometheus.ts +++ b/src/prometheus.ts @@ -26,12 +26,14 @@ export class MetricsRenderer { private metricName(name: string): string { name = name.replace(/^(.*_)?(total)_(.*)$/, '$1$3_$2') - return sanitizePrometheusMetricName( - this.prefix.split('').reverse().join('').replace(/^_+/, '').split('').reverse().join('') + '_' + name, - ) + return sanitizePrometheusMetricName(stringReverse(stringReverse(this.prefix).replace(/^_+/, '')) + '_' + name) } } +function stringReverse(str: string): string { + return str.split('').reverse().join('') +} + const retryAfterWhileDiscovery = 15 const textContentType = 'text/plain; charset=utf-8' const prometheusSpecVersion = '0.0.4'