@kikuchan/hexdump 0.1.0-alpha.2 → 0.1.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/hexdump.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  type Context = {
2
- type: 'hex-value' | 'character-value';
2
+ type: 'hex-value' | 'hex-value-prefix' | 'hex-value-suffix' | 'character-value';
3
3
  address: number;
4
4
  value: number;
5
5
  } | {
6
- type: 'address' | 'hex-value-no-data' | 'character-value-no-data';
6
+ type: 'address';
7
7
  address: number;
8
8
  } | {
9
- type: 'line-prefix' | 'address-prefix' | 'address-suffix' | 'hex-dump-prefix' | 'hex-group-prefix' | 'hex-gap' | 'hex-group-gap' | 'hex-group-suffix' | 'hex-dump-suffix' | 'character-prefix' | 'character-suffix' | 'line-suffix' | 'flush';
9
+ type: 'line-prefix' | 'address-prefix' | 'address-suffix' | 'hex-dump-prefix' | 'hex-group-prefix' | 'hex-value-no-data' | 'character-value-no-data' | 'hex-gap' | 'hex-group-gap' | 'hex-group-suffix' | 'hex-dump-suffix' | 'character-prefix' | 'character-suffix' | 'line-suffix' | 'flush';
10
10
  };
11
11
  type ColorizerOperation = {
12
12
  enter: string;
@@ -24,6 +24,7 @@ type Options = {
24
24
  prefix?: string;
25
25
  printChars?: boolean;
26
26
  foldSize?: number;
27
+ footer?: boolean;
27
28
  };
28
29
  interface Hexdumper {
29
30
  (buf: ArrayLike<number> | ArrayBuffer | DataView, options?: Options): string;
package/dist/hexdump.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";function v(r,n){return Number(r).toString(16).padStart(n,"0")}const h=r=>r,d=r=>r.replace(/[&<>]/g,n=>({"&":"&amp;","<":"&lt;",">":"&gt;"})[n]),H={simple:{address:{enter:"\x1B[38;5;238m",leave:"\x1B[m"},separator:{enter:"\x1B[38;5;238m",leave:"\x1B[m"},control:{enter:"\x1B[38;5;178m",leave:"\x1B[m"},ascii:{enter:"\x1B[m",leave:"\x1B[m"},exascii:{enter:"\x1B[38;5;209m",leave:"\x1B[m"},null:{enter:"\x1B[38;5;244m",leave:"\x1B[m"},normal:null},html:{address:{enter:'<span class="hexdump-address">',leave:"</span>",escape:d},separator:{enter:'<span class="hexdump-separator">',leave:"</span>",escape:d},control:{enter:'<span class="hexdump-control">',leave:"</span>",escape:d},ascii:{enter:'<span class="hexdump-ascii">',leave:"</span>",escape:d},exascii:{enter:'<span class="hexdump-exascii">',leave:"</span>",escape:d},null:{enter:'<span class="hexdump-null">',leave:"</span>",escape:d},normal:{enter:"",leave:"",escape:d}}},w=r=>{let n;if(!r)return h;if(r===!0&&(r="simple"),typeof r=="string"){const e=H[r],s=["address-prefix","address-suffix","character-prefix","character-suffix"];r=function(a,i){if(a.trim())return e.address&&i.type==="address"?e.address:e.separator&&s.includes(i.type)?e.separator:(i.type==="hex-value"||i.type==="character-value")&&typeof i.value=="number"?e.null!==void 0&&i.value===0?e.null:e.control!==void 0&&i.value<32?e.control:e.ascii!==void 0&&32<=i.value&&i.value<127?e.ascii:e.exascii!==void 0&&128<=i.value&&i.value<=255?e.exascii:e.normal:e.normal}}return(e,s)=>{const a=s.type==="flush"?null:r(e,s);return a!==void 0&&(n?.enter!==a?.enter||n?.leave!==a?.leave||n?.escape!==a?.escape)&&(e=(n?.leave||"")+(a?.enter||"")+(a?.escape||h)(e),n=a),e}},A=r=>(r||(r=h),(n,e)=>r(n,e)||"");function x(r){return(n,e,s)=>{const a=ArrayBuffer.isView(n)?new Uint8Array(n.buffer,n.byteOffset,n.byteLength):new Uint8Array(n);typeof e!="number"&&(s=e,e=a.length),s={...s??{}},(e===void 0||e<0)&&(e=a.length),r=s.printer||r;const i=A(s.formatter),b=w(s.color),o=s.foldSize||16,C=s.printChars!==!1;let l=s.addrOffset||0;const m=l%o,O=(m+e+o-1)/o,g=[];let c="";const t=function(f,p){c+=b(i(f,p),p)},y=s?.prefix||"",z=s?.addrLength??8-y.length;for(let f=0;f<O;f++){t("",{type:"line-prefix"}),t(y,{type:"address-prefix"}),t(v(l,z),{type:"address",address:l}),t(": ",{type:"address-suffix"}),l=l/o*o,t(" ",{type:"hex-dump-prefix"}),t("",{type:"hex-group-prefix"});for(let p=0;p<o;p++){const u=f*o+p-m;p&&p%8==0?(t("",{type:"hex-group-suffix"}),t(" ",{type:"hex-group-gap"}),t("",{type:"hex-group-prefix"})):p&&t(" ",{type:"hex-gap"}),u<e?t(v(a[u],2),{type:"hex-value",address:l+u,value:a[u]}):t(" ",{type:"hex-value-no-data",address:l+u})}if(t("",{type:"hex-group-suffix"}),t(" ",{type:"hex-dump-suffix"}),C){t(" |",{type:"character-prefix"});for(let p=0;p<o;p++){const u=f*o+p-m;u<e?t(a[u]>=32&&a[u]<127?String.fromCharCode(a[u]):".",{type:"character-value",address:l+u,value:a[u]}):t(" ",{type:"character-value-no-data",address:l+u})}t("|",{type:"character-suffix"})}t("",{type:"line-suffix"}),t("",{type:"flush"}),r?.(c),g.push(c),c="",l+=o}return g.join(`
2
- `)}}export const hexdump=Object.assign(x(null),{create:x,log:x(console.log),warn:x(console.warn),error:x(console.error),string:x(null)});export default{hexdump};
1
+ "use strict";function C(t,n){return Number(t).toString(16).padStart(n,"0")}const g=t=>t,f=t=>t.replace(/[&<>]/g,n=>({"&":"&amp;","<":"&lt;",">":"&gt;"})[n]),A={simple:{address:{enter:"\x1B[38;5;238m",leave:"\x1B[m"},separator:{enter:"\x1B[38;5;238m",leave:"\x1B[m"},control:{enter:"\x1B[38;5;178m",leave:"\x1B[m"},ascii:{enter:"\x1B[m",leave:"\x1B[m"},exascii:{enter:"\x1B[38;5;209m",leave:"\x1B[m"},null:{enter:"\x1B[38;5;244m",leave:"\x1B[m"},normal:null},html:{address:{enter:'<span class="hexdump-address">',leave:"</span>",escape:f},separator:{enter:'<span class="hexdump-separator">',leave:"</span>",escape:f},control:{enter:'<span class="hexdump-control">',leave:"</span>",escape:f},ascii:{enter:'<span class="hexdump-ascii">',leave:"</span>",escape:f},exascii:{enter:'<span class="hexdump-exascii">',leave:"</span>",escape:f},null:{enter:'<span class="hexdump-null">',leave:"</span>",escape:f},normal:{enter:"",leave:"",escape:f}}},L=t=>{let n;if(!t)return g;if(t===!0&&(t="simple"),typeof t=="string"){const e=A[t],s=["address-prefix","address-suffix","character-prefix","character-suffix"];t=function(a,i){if(a.trim())return e.address&&i.type==="address"?e.address:e.separator&&s.includes(i.type)?e.separator:(i.type==="hex-value"||i.type==="character-value")&&typeof i.value=="number"?e.null!==void 0&&i.value===0?e.null:e.control!==void 0&&i.value<32?e.control:e.ascii!==void 0&&32<=i.value&&i.value<127?e.ascii:e.exascii!==void 0&&128<=i.value&&i.value<=255?e.exascii:e.normal:e.normal}}return(e,s)=>{const a=s.type==="flush"?null:t(e,s);return a!==void 0&&(n?.enter!==a?.enter||n?.leave!==a?.leave||n?.escape!==a?.escape)&&(e=(n?.leave||"")+(a?.enter||"")+(a?.escape||g)(e),n=a),e}},S=t=>(t||(t=g),(n,e)=>t(n,e)||"");function c(t){return(n,e,s)=>{const a=ArrayBuffer.isView(n)?new Uint8Array(n.buffer,n.byteOffset,n.byteLength):new Uint8Array(n);typeof e!="number"&&(s=e,e=a.length),s={...s??{}},(e===void 0||e<0)&&(e=a.length),t=s.printer||t;const i=S(s.formatter),O=L(s.color),l=s.foldSize||16,z=s.printChars!==!1;let p=s.addrOffset||0;const y=p%l,w=(e?Math.ceil((y%l+e)/l):0)+(s.footer!==!1?1:0),v=[];let m="";const r=function(d,h){m+=O(i(d,h),h)},b=s?.prefix||"",H=s?.addrLength??8-b.length;for(let d=0;d<w;d++){const h=p;r("",{type:"line-prefix"}),r(b,{type:"address-prefix"}),r(C(p,H),{type:"address",address:p}),r(": ",{type:"address-suffix"}),r(" ",{type:"hex-dump-prefix"}),r("",{type:"hex-group-prefix"});for(let o=0;o<l;o++){const u=d*l+o-y;o&&o%8==0?(r("",{type:"hex-group-suffix"}),r(" ",{type:"hex-group-gap"}),r("",{type:"hex-group-prefix"})):o&&r(" ",{type:"hex-gap"}),0<=u&&u<e?(r("",{type:"hex-value-prefix",address:p,value:a[u]}),r(C(a[u],2),{type:"hex-value",address:p,value:a[u]}),r("",{type:"hex-value-suffix",address:p,value:a[u]}),p++):r(" ",{type:"hex-value-no-data"})}if(r("",{type:"hex-group-suffix"}),r(" ",{type:"hex-dump-suffix"}),z){let o=h;r(" |",{type:"character-prefix"});for(let u=0;u<l;u++){const x=d*l+u-y;0<=x&&x<e?(r(a[x]>=32&&a[x]<127?String.fromCharCode(a[x]):".",{type:"character-value",address:o,value:a[x]}),o++):r(" ",{type:"character-value-no-data"})}r("|",{type:"character-suffix"})}r("",{type:"line-suffix"}),r("",{type:"flush"}),t?.(m),v.push(m),m=""}return v.join(`
2
+ `)}}export const hexdump=Object.assign(c(null),{create:c,log:c(console.log),warn:c(console.warn),error:c(console.error),string:c(null)});export default{hexdump};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kikuchan/hexdump",
3
- "version": "0.1.0-alpha.2",
3
+ "version": "0.1.0-alpha.3",
4
4
  "description": "hexdump",
5
5
  "type": "module",
6
6
  "main": "dist/hexdump.js",