This repository has been archived by the owner on Apr 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tag.ts
61 lines (55 loc) · 1.53 KB
/
tag.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
* Copyright (c) TIKI Inc.
* MIT license. See LICENSE file in root directory.
*/
import { CommonTags } from './common-tags';
/**
* A metadata tag describing a data asset. Associated with a
* {@link TitleRecord}, tags improve record searchability and filtering.
*/
export class Tag {
/**
* The raw value of the tag.
*/
readonly value: string;
/**
* Constructs a new Tag with the provided value. This constructor is
* private. To create a Tag instance, use the static factory methods.
*
* @private
* @param {string} tag - The tag value.
*/
private constructor(tag: string) {
this.value = tag;
}
/**
* Creates a Tag from a provided raw value. If the tag value matches a
* common tag, a pre-defined Tag is returned. Otherwise, a custom
* Tag is created.
*
* @static
* @param {string} tag - The tag value.
* @returns {Tag} A Tag instance.
*/
static from(tag: string): Tag {
if ((Object as any).values(CommonTags).includes(tag)) {
return new Tag(tag);
} else return new Tag(`custom:${tag}`);
}
/**
* Creates a custom Tag with the provided tag value.
*
* @static
* @param {string} tag - The custom tag value.
* @returns {Tag} A Tag instance.
*/
static custom = (tag: string): Tag => new Tag(`custom:${tag}`);
/**
* Creates a Tag from one of the {@link CommonTags}
*
* @static
* @param {CommonTags} tag - The common tag to use.
* @returns {Tag} A Tag instance.
*/
static common = (tag: CommonTags): Tag => new Tag(tag.valueOf());
}