gnablib
Version:
A lean, zero dependency library to provide a useful base for your project.
2 lines • 1.45 kB
JavaScript
/*! Copyright 2023-2024 the gnablib contributors MPL-1.1 */
import{utf8 as t}from"../../codec/Utf8.js";import{sLen as e}from"../../safe/safe.js";export class Command{constructor(t,r){e("char",t).exactly(1).throwNot(),this.char=t,this.human=r}toBin(){return t.toBytes(this.char)}}export class CommandCtrl extends Command{get isCreate(){return"c"===this.char}get isInsCols(){return"i"===this.char}get isRemCols(){return"r"===this.char}get isDrop(){return"d"===this.char}static get Create(){return new CommandCtrl("c","create")}static get InsCols(){return new CommandCtrl("i","insert-cols")}static get RemCols(){return new CommandCtrl("r","remove-cols")}static get Drop(){return new CommandCtrl("d","drop")}static fromByte(t){switch(t){case 99:return CommandCtrl.Create;case 105:return CommandCtrl.InsCols;case 114:return CommandCtrl.RemCols;case 100:return CommandCtrl.Drop}}}export class CommandData extends Command{get isInsert(){return"i"===this.char}get isPut(){return"u"===this.char}get isPatch(){return"a"===this.char}get isDelete(){return"d"===this.char}static get Insert(){return new CommandData("i","insert")}static get Put(){return new CommandData("u","put")}static get Patch(){return new CommandData("a","patch")}static get Delete(){return new CommandData("d","delete")}static fromByte(t){switch(t){case 105:return CommandData.Insert;case 117:return CommandData.Put;case 97:return CommandData.Patch;case 100:return CommandData.Delete}}}