Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.1 kB
2
Indexable
Never
export class ClickstreamId extends String {
    private readonly definedId: string;

    private readonly value: string;

    private constructor(value1: string, ids: string) {
        super(value1);
        this.value = value1;
        this.definedId = ids;
    }

    public static Create(value: string) {
        return new ClickstreamId(value, this.toDefinedId(value));
    }

    private static toDefinedId(value: string): string {
        const splitDynamicId = value.split("_");
        if (splitDynamicId.length > 1) {
            return `${splitDynamicId[0]}_[dynamic]`;
        }
        return value;
    }

    public get Value() {
        return this.value;
    }

    public get DefinedId() {
        return this.definedId;
    }

    public static concatClickstreamIds(str: string, ...baseClickstreamId: (ClickstreamId | string)[]) {
        return new ClickstreamId(
            str,
            (baseClickstreamId.filter((x) => x instanceof ClickstreamId).pop() as ClickstreamId).DefinedId,
        );
    }
}