@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 +4 -3
- package/dist/hexdump.js +2 -2
- package/package.json +1 -1
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'
|
|
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
|
|
2
|
-
`)}}export const hexdump=Object.assign(
|
|
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=>({"&":"&","<":"<",">":">"})[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};
|