UNPKG

gnablib

Version:

A lean, zero dependency library to provide a useful base for your project.

1 lines 1.04 kB
import{color as e}from"../../cli/csi-tables.js";const t=Symbol.for("nodejs.util.inspect.custom"),{cyan:r,yellow:n,magenta:s,green:o,reset:l}=e;export class RangeProblem{constructor(e,t,r){this.noun=e,this.value=r,this._descr=t}toString(){let e=""+this.value;return"string"==typeof this.value&&(e="'"+e+"'"),`${this.noun} ${this._descr}, got: ${e}`}inColor(){let e=""+this.value,t=s;switch(typeof this.value){case"string":t=o,e="'"+e+"'";break;case"number":t=n}return`${r}${this.noun}${l} ${this._descr}, got: ${t}${e}${l}`}get name(){return"RangeProblem"}get[Symbol.toStringTag](){return"RangeProblem"}[t](){return this.inColor()}static IncInc(e,t,r,n){return new RangeProblem(e,`should be [${r},${n}]`,t)}static Lte(e,t,r){return new RangeProblem(e,`should be <= ${r}`,t)}static Lt(e,t,r){return new RangeProblem(e,`should be < ${r}`,t)}static Gte(e,t,r){return new RangeProblem(e,`should be >= ${r}`,t)}static Gt(e,t,r){return new RangeProblem(e,`should be > ${r}`,t)}static Eq(e,t,r){return new RangeProblem(e,`should be == ${r}`,t)}}