@kikuchan/hexdump 0.1.0-alpha.1 → 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,16 +1,17 @@
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;
13
13
  leave: string;
14
+ escape?: (s: string) => string;
14
15
  } | null;
15
16
  type Colorizer = boolean | undefined | 'simple' | 'html' | ((s: string, ctx: Context) => ColorizerOperation | undefined);
16
17
  type Formatter = undefined | ((s: string, ctx: Context) => string | undefined);
@@ -23,6 +24,7 @@ type Options = {
23
24
  prefix?: string;
24
25
  printChars?: boolean;
25
26
  foldSize?: number;
27
+ footer?: boolean;
26
28
  };
27
29
  interface Hexdumper {
28
30
  (buf: ArrayLike<number> | ArrayBuffer | DataView, options?: Options): string;
package/dist/hexdump.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";function y(t,s){return Number(t).toString(16).padStart(s,"0")}const g=t=>t,z={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>"},separator:{enter:'<span class="hexdump-separator">',leave:"</span>"},control:{enter:'<span class="hexdump-control">',leave:"</span>"},ascii:{enter:'<span class="hexdump-ascii">',leave:"</span>"},exascii:{enter:'<span class="hexdump-exascii">',leave:"</span>"},null:{enter:'<span class="hexdump-null">',leave:"</span>"},normal:null}},H=t=>{let s;if(!t)return g;if(t===!0&&(t="simple"),typeof t=="string"){const e=z[t],n=["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&&n.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,n)=>{const a=n.type==="flush"?null:t(e,n);return a!==void 0&&(s?.enter!==a?.enter||s?.leave!==a?.leave)&&(e=(s?.leave||"")+(a?.enter||"")+e,s=a),e}},w=t=>(t||(t=g),(s,e)=>t(s,e)||"");function f(t){return(s,e,n)=>{const a=ArrayBuffer.isView(s)?new Uint8Array(s.buffer,s.byteOffset,s.byteLength):new Uint8Array(s);typeof e!="number"&&(n=e,e=a.length),n={...n??{}},(e===void 0||e<0)&&(e=a.length),t=n.printer||t;const i=w(n.formatter),v=H(n.color),l=n.foldSize||16,b=n.printChars!==!1;let p=n.addrOffset||0;const c=p%l,C=(c+e+l-1)/l,m=[];let x="";const r=function(d,u){x+=v(i(d,u),u)},h=n?.prefix||"",O=n?.addrLength??8-h.length;for(let d=0;d<C;d++){r("",{type:"line-prefix"}),r(h,{type:"address-prefix"}),r(y(p,O),{type:"address",address:p}),r(": ",{type:"address-suffix"}),p=p/l*l,r(" ",{type:"hex-dump-prefix"}),r("",{type:"hex-group-prefix"});for(let u=0;u<l;u++){const o=d*l+u-c;u&&u%8==0?(r("",{type:"hex-group-suffix"}),r(" ",{type:"hex-group-gap"}),r("",{type:"hex-group-prefix"})):u&&r(" ",{type:"hex-gap"}),o<e?r(y(a[o],2),{type:"hex-value",address:p+o,value:a[o]}):r(" ",{type:"hex-value-no-data",address:p+o})}if(r("",{type:"hex-group-suffix"}),r(" ",{type:"hex-dump-suffix"}),b){r(" |",{type:"character-prefix"});for(let u=0;u<l;u++){const o=d*l+u-c;o<e?r(a[o]>=32&&a[o]<127?String.fromCharCode(a[o]):".",{type:"character-value",address:p+o,value:a[o]}):r(" ",{type:"character-value-no-data",address:p+o})}r("|",{type:"character-suffix"})}r("",{type:"line-suffix"}),r("",{type:"flush"}),t?.(x),m.push(x),x="",p+=l}return m.join(`
2
- `)}}export const hexdump=Object.assign(f(null),{create:f,log:f(console.log),warn:f(console.warn),error:f(console.error),string:f(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.1",
3
+ "version": "0.1.0-alpha.3",
4
4
  "description": "hexdump",
5
5
  "type": "module",
6
6
  "main": "dist/hexdump.js",