From 43b340790a147eb61c866847317bbb93245a3a01 Mon Sep 17 00:00:00 2001 From: rob Date: Tue, 16 Aug 2022 07:00:03 -0400 Subject: [PATCH] added `parseTagList` --- lib/site-common.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/site-common.js b/lib/site-common.js index c3bce95..8c00f31 100644 --- a/lib/site-common.js +++ b/lib/site-common.js @@ -7,6 +7,8 @@ const path = require('path'); const pug = require('pug'); +const striptags = require('striptags'); + const { SiteLog } = require(path.join(__dirname, 'site-log')); const { SiteAsync } = require(path.join(__dirname, 'site-async')); @@ -102,6 +104,25 @@ class SiteCommon extends Events { }, options); return pug.compileFileClient(scriptFile, options); } + + parseTagList (tagList, options) { + options = Object.assign({ + lowercase: true, + filter: [ ], + }, options); + return tagList + .split(',') + .map((metric) => { + metric = striptags(metric.trim()); + return options.lowercase ? metric.toLowerCase() : metric; + }) + .filter((metric) => { + return (typeof metric === 'string') && + (metric.length > 0) && + !options.filter.includes(metric.toLowerCase()) + ; + }); + } } module.exports.SiteCommon = SiteCommon; \ No newline at end of file