function withTag
withTag(
words: string[],
tag: string
): string[]

Adds or replaces a tag in a sentence

Creates a new word array with the specified tag. If a tag already exists, it is removed first before adding the new one.

Examples

Add tag to sentence

import { assertEquals } from "@std/assert";
import { withTag } from "@hertzg/routeros-api/utils/tag";

const words = ["/interface/print"];
const tagged = withTag(words, "req-001");
assertEquals(tagged, ["/interface/print", ".tag=req-001"]);

Replace existing tag

import { assertEquals } from "@std/assert";
import { withTag } from "@hertzg/routeros-api/utils/tag";

const words = ["/interface/print", ".tag=old"];
const tagged = withTag(words, "new");
assertEquals(tagged, ["/interface/print", ".tag=new"]);

Parameters

words: string[]

Array of words from a sentence

tag: string

The tag value to add

Return Type

string[]

New array with the tag word appended

Usage

import { withTag } from "utils/tag.ts";