Comparing version 1.1.0 to 1.2.0
@@ -38,2 +38,3 @@ var __defProp = Object.defineProperty; | ||
createCodec: () => createCodec, | ||
createEncoder: () => createEncoder, | ||
enhanceCodec: () => enhanceCodec, | ||
@@ -58,13 +59,2 @@ enhanceDecoder: () => enhanceDecoder, | ||
// src/utils.ts | ||
var createCodec = (encoder, decoder) => { | ||
const result = [encoder, decoder]; | ||
result.enc = encoder; | ||
result.dec = decoder; | ||
return result; | ||
}; | ||
var enhanceEncoder = (encoder, mapper) => (value) => encoder(mapper(value)); | ||
var enhanceDecoder = (decoder, mapper) => (value) => mapper(decoder(value)); | ||
var enhanceCodec = ([encoder, decoder], toFrom, fromTo) => createCodec(enhanceEncoder(encoder, toFrom), enhanceDecoder(decoder, fromTo)); | ||
// src/internal/toInternalBytes.ts | ||
@@ -147,2 +137,14 @@ var HEX_MAP = { | ||
// src/utils.ts | ||
var createEncoder = toInternalBytes; | ||
var createCodec = (encoder, decoder) => { | ||
const result = [encoder, decoder]; | ||
result.enc = encoder; | ||
result.dec = decoder; | ||
return result; | ||
}; | ||
var enhanceEncoder = (encoder, mapper) => (value) => encoder(mapper(value)); | ||
var enhanceDecoder = (decoder, mapper) => (value) => mapper(decoder(value)); | ||
var enhanceCodec = ([encoder, decoder], toFrom, fromTo) => createCodec(enhanceEncoder(encoder, toFrom), enhanceDecoder(decoder, fromTo)); | ||
// src/codecs/fixed-width-ints.ts | ||
@@ -149,0 +151,0 @@ function decodeInt(nBytes, getter) { |
@@ -1,2 +0,2 @@ | ||
var E=Object.defineProperty;var ee=Object.getOwnPropertyDescriptor;var te=Object.getOwnPropertyNames;var ne=Object.prototype.hasOwnProperty;var re=(t,e,n)=>e in t?E(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var oe=(t,e)=>{for(var n in e)E(t,n,{get:e[n],enumerable:!0})},ce=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of te(e))!ne.call(t,o)&&o!==n&&E(t,o,{get:()=>e[o],enumerable:!(r=ee(e,o))||r.enumerable});return t};var ie=t=>ce(E({},"__esModule",{value:!0}),t);var v=(t,e,n)=>(re(t,typeof e!="symbol"?e+"":e,n),n);var he={};oe(he,{Bytes:()=>C,Enum:()=>b,Option:()=>U,Result:()=>w,Struct:()=>B,Tuple:()=>g,Vector:()=>k,_void:()=>L,bool:()=>D,compact:()=>u,createCodec:()=>c,enhanceCodec:()=>R,enhanceDecoder:()=>T,enhanceEncoder:()=>I,i128:()=>Oe,i16:()=>ue,i256:()=>ye,i32:()=>fe,i64:()=>pe,i8:()=>me,str:()=>S,u128:()=>ge,u16:()=>l,u256:()=>le,u32:()=>y,u64:()=>K,u8:()=>m});module.exports=ie(he);var c=(t,e)=>{let n=[t,e];return n.enc=t,n.dec=e,n},I=(t,e)=>n=>t(e(n)),T=(t,e)=>n=>e(t(n)),R=([t,e],n,r)=>c(I(t,n),T(e,r));var V={0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,a:10,b:11,c:12,d:13,e:14,f:15,A:10,B:11,C:12,D:13,E:14,F:15};function de(t){let e=t.length%2,n=(t[1]==="x"?2:0)+e,r=(t.length-n)/2+e,o=new Uint8Array(r);e&&(o[0]=0|V[t[2]]);for(let i=0;i<r;){let s=n+i*2,p=V[t[s]],x=V[t[s+1]];o[e+i++]=p<<4|x}return o}var A=class extends Uint8Array{constructor(n){super(n);v(this,"i",0);v(this,"v");this.v=new DataView(n)}},d=t=>e=>t(e instanceof A?e:new A(e instanceof Uint8Array?e.buffer:typeof e=="string"?de(e).buffer:e));var a=(...t)=>{let e=t.length,n=0;for(let o=0;o<e;o++)n+=t[o].byteLength;let r=new Uint8Array(n);for(let o=0,i=0;o<e;o++){let s=t[o];r.set(s,i),i+=s.byteLength}return r};function O(t,e){let n=Object.keys(t),r=n.length,o={};for(let i=0;i<r;i++){let s=n[i];o[s]=e(t[s],s)}return o}function se(t,e){return d(n=>{let r=n.v[e](n.i,!0);return n.i+=t,r})}function ae(t,e){return n=>{let r=new Uint8Array(t);return new DataView(r.buffer)[e](0,n,!0),r}}function f(t,e,n){return c(ae(t,n),se(t,e))}var m=f(1,"getUint8","setUint8"),l=f(2,"getUint16","setUint16"),y=f(4,"getUint32","setUint32"),K=f(8,"getBigUint64","setBigUint64"),me=f(1,"getInt8","setInt8"),ue=f(2,"getInt16","setInt16"),fe=f(4,"getInt32","setInt32"),pe=f(8,"getBigInt64","setBigInt64"),h=t=>{let e=new Uint8Array(16),n=new DataView(e.buffer);return n.setBigInt64(0,t,!0),n.setBigInt64(8,t>>64n,!0),e},_=t=>d(e=>{let{v:n,i:r}=e,o=n.getBigUint64(r,!0),i=n[t](r+8,!0);return e.i+=16,i<<64n|o}),ge=c(h,_("getBigUint64")),Oe=c(h,_("getBigInt64")),j=t=>{let e=new Uint8Array(32),n=new DataView(e.buffer);return n.setBigInt64(0,t,!0),n.setBigInt64(8,t>>64n,!0),n.setBigInt64(16,t>>128n,!0),n.setBigInt64(24,t>>192n,!0),e},M=t=>d(e=>{let n=e.v.getBigUint64(e.i,!0);return e.i+=8,n|=e.v.getBigUint64(e.i,!0)<<64n,e.i+=8,n|=e.v.getBigUint64(e.i,!0)<<128n,e.i+=8,n|=e.v[t](e.i,!0)<<192n,e.i+=8,n}),le=c(j,M("getBigUint64")),ye=c(j,M("getBigInt64"));var D=R(m,t=>t?1:0,Boolean);var De=[m[1],l[1],y[1]],xe=d(t=>{let e=t[t.i],n=e&3;if(n<3)return De[n](t)>>>2;let r=(e>>>2)+4;t.i++;let o=0n,i=r/8|0,s=0n;for(let x=0;x<i;x++)o=K[1](t)<<s|o,s+=64n;let p=r%8;return p>3&&(o=BigInt(y[1](t))<<s|o,s+=32n,p-=4),p>1&&(o=BigInt(l[1](t))<<s|o,s+=16n,p-=2),p&&(o=BigInt(m[1](t))<<s|o),o}),Ee=1n<<56n,Ie=1<<24,Te=256,Ae=4294967295n,Ke=1<<6,Ce=1<<14,be=1<<30,Ue=t=>{if(t<0)throw new Error(`Wrong compact input (${t})`);let e=Number(t)<<2;if(t<Ke)return m[0](e);if(t<Ce)return l[0](e|1);if(t<be)return y[0](e|2);let n=[new Uint8Array(1)],r=BigInt(t);for(;r>=Ee;)n.push(K[0](r)),r>>=64n;r>=Ie&&(n.push(y[0](Number(r&Ae))),r>>=32n);let o=Number(r);o>=Te&&(n.push(l[0](o)),o>>=16),o&&n.push(m[0](o));let i=a(...n);return i[0]=i.length-5<<2|3,i},u=c(Ue,xe);var we=new TextEncoder,Be=t=>{let e=we.encode(t);return a(u.enc(e.length),e)},ke=new TextDecoder,ve=d(t=>{let e=u.dec(t),n=new DataView(t.buffer,t.i,e);return t.i+=e,ke.decode(n)}),S=c(Be,ve);var Re=()=>{},Ve=new Uint8Array(0),L=c(()=>Ve,Re);var N=t=>t===void 0?e=>a(u.enc(e.length),e):e=>e.length===t?e:e.slice(0,t),P=t=>d(e=>{let n=t===void 0?u.dec(e):t!==1/0?t:e.byteLength-e.i,r=new Uint8Array(e.buffer.slice(e.i,e.i+n));return e.i+=n,r}),C=t=>c(N(t),P(t));C.enc=N;C.dec=P;var Y=t=>{let e=Object.keys(t);return({tag:n,value:r})=>a(m.enc(e.indexOf(n)),t[n](r))},F=t=>{let e=Object.entries(t);return d(n=>{let r=m.dec(n),[o,i]=e[r];return{tag:o,value:i(n)}})},b=t=>c(Y(O(t,([e])=>e)),F(O(t,([,e])=>e)));b.enc=Y;b.dec=F;var H=t=>d(e=>{let n=m.dec(e);if(n!==0)return t===D[1]?n===1:t(e)}),W=t=>e=>{let n=new Uint8Array(1);return e===void 0?(n[0]=0,n):(n[0]=1,t===D[0]?(n[0]=e?1:2,n):a(n,t(e)))},U=t=>c(W(t[0]),H(t[1]));U.enc=W;U.dec=H;var G=(t,e)=>d(n=>{let r=m[1](n)===0,i=(r?t:e)(n);return{success:r,value:i}}),X=(t,e)=>({success:n,value:r})=>a(m[0](n?0:1),(n?t:e)(r)),w=(t,e)=>c(X(t[0],e[0]),G(t[1],e[1]));w.dec=G;w.enc=X;var $=(...t)=>d(e=>t.map(n=>n(e))),q=(...t)=>e=>a(...e.map((n,r)=>t[r](n))),g=(...t)=>c(q(...t.map(([e])=>e)),$(...t.map(([,e])=>e)));g.enc=q;g.dec=$;var J=t=>{let e=Object.keys(t);return I(g.enc(...Object.values(t)),n=>e.map(r=>n[r]))},Q=t=>{let e=Object.keys(t);return T(g.dec(...Object.values(t)),n=>Object.fromEntries(n.map((r,o)=>[e[o],r])))},B=t=>c(J(O(t,e=>e[0])),Q(O(t,e=>e[1])));B.enc=J;B.dec=Q;var Z=(t,e)=>e>=0?n=>a(...n.map(t)):n=>a(u.enc(n.length),...n.map(t)),z=(t,e)=>d(n=>{let r=e>=0?e:u.dec(n),o=new Array(r);for(let i=0;i<r;i++)o[i]=t(n);return o}),k=(t,e)=>c(Z(t[0],e),z(t[1],e));k.enc=Z;k.dec=z; | ||
var E=Object.defineProperty;var ee=Object.getOwnPropertyDescriptor;var te=Object.getOwnPropertyNames;var ne=Object.prototype.hasOwnProperty;var re=(t,e,n)=>e in t?E(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var oe=(t,e)=>{for(var n in e)E(t,n,{get:e[n],enumerable:!0})},ce=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of te(e))!ne.call(t,o)&&o!==n&&E(t,o,{get:()=>e[o],enumerable:!(r=ee(e,o))||r.enumerable});return t};var ie=t=>ce(E({},"__esModule",{value:!0}),t);var v=(t,e,n)=>(re(t,typeof e!="symbol"?e+"":e,n),n);var _e={};oe(_e,{Bytes:()=>C,Enum:()=>b,Option:()=>U,Result:()=>B,Struct:()=>w,Tuple:()=>g,Vector:()=>k,_void:()=>L,bool:()=>D,compact:()=>u,createCodec:()=>c,createEncoder:()=>se,enhanceCodec:()=>V,enhanceDecoder:()=>A,enhanceEncoder:()=>T,i128:()=>ye,i16:()=>fe,i256:()=>De,i32:()=>pe,i64:()=>ge,i8:()=>ue,str:()=>S,u128:()=>Oe,u16:()=>y,u256:()=>le,u32:()=>l,u64:()=>K,u8:()=>m});module.exports=ie(_e);var R={0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,a:10,b:11,c:12,d:13,e:14,f:15,A:10,B:11,C:12,D:13,E:14,F:15};function de(t){let e=t.length%2,n=(t[1]==="x"?2:0)+e,r=(t.length-n)/2+e,o=new Uint8Array(r);e&&(o[0]=0|R[t[2]]);for(let i=0;i<r;){let s=n+i*2,p=R[t[s]],x=R[t[s+1]];o[e+i++]=p<<4|x}return o}var I=class extends Uint8Array{constructor(n){super(n);v(this,"i",0);v(this,"v");this.v=new DataView(n)}},d=t=>e=>t(e instanceof I?e:new I(e instanceof Uint8Array?e.buffer:typeof e=="string"?de(e).buffer:e));var a=(...t)=>{let e=t.length,n=0;for(let o=0;o<e;o++)n+=t[o].byteLength;let r=new Uint8Array(n);for(let o=0,i=0;o<e;o++){let s=t[o];r.set(s,i),i+=s.byteLength}return r};function O(t,e){let n=Object.keys(t),r=n.length,o={};for(let i=0;i<r;i++){let s=n[i];o[s]=e(t[s],s)}return o}var se=d,c=(t,e)=>{let n=[t,e];return n.enc=t,n.dec=e,n},T=(t,e)=>n=>t(e(n)),A=(t,e)=>n=>e(t(n)),V=([t,e],n,r)=>c(T(t,n),A(e,r));function ae(t,e){return d(n=>{let r=n.v[e](n.i,!0);return n.i+=t,r})}function me(t,e){return n=>{let r=new Uint8Array(t);return new DataView(r.buffer)[e](0,n,!0),r}}function f(t,e,n){return c(me(t,n),ae(t,e))}var m=f(1,"getUint8","setUint8"),y=f(2,"getUint16","setUint16"),l=f(4,"getUint32","setUint32"),K=f(8,"getBigUint64","setBigUint64"),ue=f(1,"getInt8","setInt8"),fe=f(2,"getInt16","setInt16"),pe=f(4,"getInt32","setInt32"),ge=f(8,"getBigInt64","setBigInt64"),h=t=>{let e=new Uint8Array(16),n=new DataView(e.buffer);return n.setBigInt64(0,t,!0),n.setBigInt64(8,t>>64n,!0),e},_=t=>d(e=>{let{v:n,i:r}=e,o=n.getBigUint64(r,!0),i=n[t](r+8,!0);return e.i+=16,i<<64n|o}),Oe=c(h,_("getBigUint64")),ye=c(h,_("getBigInt64")),j=t=>{let e=new Uint8Array(32),n=new DataView(e.buffer);return n.setBigInt64(0,t,!0),n.setBigInt64(8,t>>64n,!0),n.setBigInt64(16,t>>128n,!0),n.setBigInt64(24,t>>192n,!0),e},M=t=>d(e=>{let n=e.v.getBigUint64(e.i,!0);return e.i+=8,n|=e.v.getBigUint64(e.i,!0)<<64n,e.i+=8,n|=e.v.getBigUint64(e.i,!0)<<128n,e.i+=8,n|=e.v[t](e.i,!0)<<192n,e.i+=8,n}),le=c(j,M("getBigUint64")),De=c(j,M("getBigInt64"));var D=V(m,t=>t?1:0,Boolean);var xe=[m[1],y[1],l[1]],Ee=d(t=>{let e=t[t.i],n=e&3;if(n<3)return xe[n](t)>>>2;let r=(e>>>2)+4;t.i++;let o=0n,i=r/8|0,s=0n;for(let x=0;x<i;x++)o=K[1](t)<<s|o,s+=64n;let p=r%8;return p>3&&(o=BigInt(l[1](t))<<s|o,s+=32n,p-=4),p>1&&(o=BigInt(y[1](t))<<s|o,s+=16n,p-=2),p&&(o=BigInt(m[1](t))<<s|o),o}),Ie=1n<<56n,Te=1<<24,Ae=256,Ke=4294967295n,Ce=1<<6,be=1<<14,Ue=1<<30,Be=t=>{if(t<0)throw new Error(`Wrong compact input (${t})`);let e=Number(t)<<2;if(t<Ce)return m[0](e);if(t<be)return y[0](e|1);if(t<Ue)return l[0](e|2);let n=[new Uint8Array(1)],r=BigInt(t);for(;r>=Ie;)n.push(K[0](r)),r>>=64n;r>=Te&&(n.push(l[0](Number(r&Ke))),r>>=32n);let o=Number(r);o>=Ae&&(n.push(y[0](o)),o>>=16),o&&n.push(m[0](o));let i=a(...n);return i[0]=i.length-5<<2|3,i},u=c(Be,Ee);var we=new TextEncoder,ke=t=>{let e=we.encode(t);return a(u.enc(e.length),e)},ve=new TextDecoder,Re=d(t=>{let e=u.dec(t),n=new DataView(t.buffer,t.i,e);return t.i+=e,ve.decode(n)}),S=c(ke,Re);var Ve=()=>{},he=new Uint8Array(0),L=c(()=>he,Ve);var N=t=>t===void 0?e=>a(u.enc(e.length),e):e=>e.length===t?e:e.slice(0,t),P=t=>d(e=>{let n=t===void 0?u.dec(e):t!==1/0?t:e.byteLength-e.i,r=new Uint8Array(e.buffer.slice(e.i,e.i+n));return e.i+=n,r}),C=t=>c(N(t),P(t));C.enc=N;C.dec=P;var Y=t=>{let e=Object.keys(t);return({tag:n,value:r})=>a(m.enc(e.indexOf(n)),t[n](r))},F=t=>{let e=Object.entries(t);return d(n=>{let r=m.dec(n),[o,i]=e[r];return{tag:o,value:i(n)}})},b=t=>c(Y(O(t,([e])=>e)),F(O(t,([,e])=>e)));b.enc=Y;b.dec=F;var H=t=>d(e=>{let n=m.dec(e);if(n!==0)return t===D[1]?n===1:t(e)}),W=t=>e=>{let n=new Uint8Array(1);return e===void 0?(n[0]=0,n):(n[0]=1,t===D[0]?(n[0]=e?1:2,n):a(n,t(e)))},U=t=>c(W(t[0]),H(t[1]));U.enc=W;U.dec=H;var G=(t,e)=>d(n=>{let r=m[1](n)===0,i=(r?t:e)(n);return{success:r,value:i}}),X=(t,e)=>({success:n,value:r})=>a(m[0](n?0:1),(n?t:e)(r)),B=(t,e)=>c(X(t[0],e[0]),G(t[1],e[1]));B.dec=G;B.enc=X;var $=(...t)=>d(e=>t.map(n=>n(e))),q=(...t)=>e=>a(...e.map((n,r)=>t[r](n))),g=(...t)=>c(q(...t.map(([e])=>e)),$(...t.map(([,e])=>e)));g.enc=q;g.dec=$;var J=t=>{let e=Object.keys(t);return T(g.enc(...Object.values(t)),n=>e.map(r=>n[r]))},Q=t=>{let e=Object.keys(t);return A(g.dec(...Object.values(t)),n=>Object.fromEntries(n.map((r,o)=>[e[o],r])))},w=t=>c(J(O(t,e=>e[0])),Q(O(t,e=>e[1])));w.enc=J;w.dec=Q;var Z=(t,e)=>e>=0?n=>a(...n.map(t)):n=>a(u.enc(n.length),...n.map(t)),z=(t,e)=>d(n=>{let r=e>=0?e:u.dec(n),o=new Array(r);for(let i=0;i<r;i++)o[i]=t(n);return o}),k=(t,e)=>c(Z(t[0],e),z(t[1],e));k.enc=Z;k.dec=z; | ||
//# sourceMappingURL=scale-ts.cjs.production.min.js.map |
@@ -8,13 +8,2 @@ var __defProp = Object.defineProperty; | ||
// src/utils.ts | ||
var createCodec = (encoder, decoder) => { | ||
const result = [encoder, decoder]; | ||
result.enc = encoder; | ||
result.dec = decoder; | ||
return result; | ||
}; | ||
var enhanceEncoder = (encoder, mapper) => (value) => encoder(mapper(value)); | ||
var enhanceDecoder = (decoder, mapper) => (value) => mapper(decoder(value)); | ||
var enhanceCodec = ([encoder, decoder], toFrom, fromTo) => createCodec(enhanceEncoder(encoder, toFrom), enhanceDecoder(decoder, fromTo)); | ||
// src/internal/toInternalBytes.ts | ||
@@ -97,2 +86,14 @@ var HEX_MAP = { | ||
// src/utils.ts | ||
var createEncoder = toInternalBytes; | ||
var createCodec = (encoder, decoder) => { | ||
const result = [encoder, decoder]; | ||
result.enc = encoder; | ||
result.dec = decoder; | ||
return result; | ||
}; | ||
var enhanceEncoder = (encoder, mapper) => (value) => encoder(mapper(value)); | ||
var enhanceDecoder = (decoder, mapper) => (value) => mapper(decoder(value)); | ||
var enhanceCodec = ([encoder, decoder], toFrom, fromTo) => createCodec(enhanceEncoder(encoder, toFrom), enhanceDecoder(decoder, fromTo)); | ||
// src/codecs/fixed-width-ints.ts | ||
@@ -371,2 +372,3 @@ function decodeInt(nBytes, getter) { | ||
createCodec, | ||
createEncoder, | ||
enhanceCodec, | ||
@@ -373,0 +375,0 @@ enhanceDecoder, |
import type { Codec, Decoder, Encoder } from "./types"; | ||
export declare const createEncoder: <T>(fn: (input: Uint8Array) => T) => Decoder<T>; | ||
export declare const createCodec: <T>(encoder: Encoder<T>, decoder: Decoder<T>) => Codec<T>; | ||
@@ -3,0 +4,0 @@ export declare const enhanceEncoder: <I, O>(encoder: Encoder<I>, mapper: (value: O) => I) => Encoder<O>; |
{ | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"repository": { | ||
@@ -4,0 +4,0 @@ "type": "git", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
177293
1291
1