mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-05 13:57:10 -04:00
1 line
2.5 KiB
JavaScript
1 line
2.5 KiB
JavaScript
import{b as T}from"./chunk-a740628f.js";import{d as h,r as b,c as f,j as I,D as S,m as r,l as p,q as a,S as d,E as x,z as v,F as A,K as E}from"./chunk-449c23a2.js";import{_ as j}from"./chunk-6deddc2e.js";import{w as N}from"./chunk-4d6daddf.js";import{u as _}from"./chunk-767079b6.js";import{i as k}from"./chunk-c7e7c785.js";import"./chunk-9a43cce8.js";import"./chunk-340feaf0.js";function F(i,{separator:e=" "}={}){return i.split("").map(o=>o.charCodeAt(0).toString(2).padStart(8,"0")).join(e)}function g(i){const e=i.replace(/[^01]/g,"");if(e.length%8)throw new Error("Invalid binary string");return e.split(/(\d{8})/).filter(Boolean).map(o=>String.fromCharCode(Number.parseInt(o,2))).join("")}const U={"mt-2":"",flex:"","justify-center":""},V={"mt-2":"",flex:"","justify-center":""},G=h({__name:"text-to-binary",setup(i){const e=b(""),o=f(()=>F(e.value)),{copy:w}=_({source:o}),u=b(""),l=f(()=>N(()=>g(u.value),"")),B=[{validator:m=>k(()=>g(m)),message:"Binary should be a valid ASCII binary string with multiples of 8 bits"}],{copy:C}=_({source:l});return(m,t)=>{const s=j,c=E,y=T;return I(),S(A,null,[r(y,{title:"Text to ASCII binary"},{default:p(()=>[r(s,{value:a(e),"onUpdate:value":t[0]||(t[0]=n=>d(e)?e.value=n:null),multiline:"",placeholder:"e.g. 'Hello world'",label:"Enter text to convert to binary",autosize:"",autofocus:"","raw-text":"","test-id":"text-to-binary-input"},null,8,["value"]),r(s,{value:a(o),"onUpdate:value":t[1]||(t[1]=n=>d(o)?o.value=n:null),label:"Binary from your text",multiline:"","raw-text":"",readonly:"","mt-2":"",placeholder:"The binary representation of your text will be here","test-id":"text-to-binary-output"},null,8,["value"]),x("div",U,[r(c,{disabled:!a(o),onClick:t[2]||(t[2]=n=>a(w)())},{default:p(()=>[v(" Copy binary to clipboard ")]),_:1},8,["disabled"])])]),_:1}),r(y,{title:"ASCII binary to text"},{default:p(()=>[r(s,{value:a(u),"onUpdate:value":t[3]||(t[3]=n=>d(u)?u.value=n:null),multiline:"",placeholder:"e.g. '01001000 01100101 01101100 01101100 01101111'",label:"Enter binary to convert to text",autosize:"","raw-text":"","validation-rules":B,"test-id":"binary-to-text-input"},null,8,["value"]),r(s,{value:a(l),"onUpdate:value":t[4]||(t[4]=n=>d(l)?l.value=n:null),label:"Text from your binary",multiline:"","raw-text":"",readonly:"","mt-2":"",placeholder:"The text representation of your binary will be here","test-id":"binary-to-text-output"},null,8,["value"]),x("div",V,[r(c,{disabled:!a(l),onClick:t[5]||(t[5]=n=>a(C)())},{default:p(()=>[v(" Copy text to clipboard ")]),_:1},8,["disabled"])])]),_:1})],64)}}});export{G as default};
|