UNPKG

tctx

Version:

W3C Trace Contexts made simple

1 lines 900 B
const { random:t } = require('@lukeed/csprng');var r=1,n=2;function i(t,n,e,s){return{version:t,trace_id:n,parent_id:e,flags:s,child(){return i(this.version,this.trace_id,g(8),this.flags|r)},toString(){let t=this.flags.toString(16).padStart(2,"0");return`${this.version}-${this.trace_id}-${this.parent_id}-${t}`}}}function e(){let t=g(24);return i("00",t.slice(0,32),t.slice(32),2|r)}function s(t){if(t.length>55)return null;let r=t.split("-");return i(r[0],r[1],r[2],parseInt(r[3],16))}function l(t){t.flags|=r}function o(t){t.flags&=~r}function u(t){return(t.flags&r)==r}function a(t){return 2==(2&t.flags)}for(var f=256,c=[];f--;)c[f]=(f+256).toString(16).substring(1);function g(r){let n=t(r),i=0,e="";for(;i<n.length;i++)e+=c[n[i]];return e}exports.FLAG_RANDOM=n;exports.FLAG_SAMPLE=r;exports.is_randomed=a;exports.is_sampled=u;exports.make=e;exports.parse=s;exports.sample=l;exports.unsample=o;