All files / rmrk1.0.0/classes emote.ts

100% Statements 10/10
100% Branches 0/0
100% Functions 2/2
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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          1x     22x 22x       51x 51x 22x 22x   29x 29x 29x        
import { validateEmote } from "../../tools/validate-remark";
 
export class Emote {
  unicode: string;
  id: string;
  static V = "1.0.0";
 
  constructor(id: string, unicode: string) {
    this.unicode = unicode;
    this.id = id;
  }
 
  static fromRemark(remark: string): Emote | string {
    try {
      validateEmote(remark);
      const [_prefix, _op_type, _version, id, unicode] = remark.split("::");
      return new Emote(id, unicode);
    } catch (e) {
      console.error(e.message);
      console.log(`EMOTE error: full input was ${remark}`);
      return e.message;
    }
  }
}