@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 858 B
JavaScript
const t=new RegExp("^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$","i");function e(t){let e="";for(let r=0;r<t;r++)e+=(65536*(1+Math.random())|0).toString(16).substring(1);return e}class r{constructor(t){if(this._value="",!t)throw new TypeError("Invalid argument; `value` has no value.");this._value=r.EMPTY,t&&t instanceof r?this._value=t.toString():t&&"[object String]"===Object.prototype.toString.call(t)&&r.isGuid(t)&&(this._value=t)}equals(t){return r.isGuid(t)&&this._value===t}isEmpty(){return this._value===r.EMPTY}toString(){return this._value}toJSON(){return this._value}static isGuid(e){return e&&(e instanceof r||t.test(e.toString()))}static create(){return new r([e(2),e(1),e(1),e(1),e(3)].join("-"))}static raw(){return[e(2),e(1),e(1),e(1),e(3)].join("-")}}r.EMPTY="00000000-0000-0000-0000-000000000000";export{r as default};