Skip to content

Commit 0a47116

Browse files
authored
Regex tester (#6)
* Regex tester * Fixes * Release 0.0.3
1 parent c470cbd commit 0a47116

File tree

10 files changed

+135
-7
lines changed

10 files changed

+135
-7
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
77
## Features
88

9+
- [x] Multiple plain text tools
10+
- [ ] Clipboard auto detection
11+
- [ ] Tray icon for quick action
12+
13+
## Tools list
14+
915
- [x] Unix Timestamp Converter
1016
- [x] Markdown to HTML Converter
1117
- [x] HTML Preview
@@ -15,11 +21,11 @@
1521
- [x] Text Diff
1622
- [x] JSON Formatter
1723
- [x] SQL Formatter
24+
- [x] Regex Tester
1825
- [ ] JWT Debugger
1926
- [ ] Number Base Converter
2027
- [ ] URL Encode/Decode
2128
- [ ] HTML Entity Encode/Decode
22-
- [ ] Regex Tester
2329

2430
## Installation
2531

src/components/Main.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import DiffText from './diff/TextDiff';
1212
import SqlFormatter from './sql/SqlFormatter';
1313
import JsonFormatter from './json/JsonFormatter';
1414
import QRCodeReader from './qrcode/QrCodeReader';
15+
import RegexTester from './regex/RegexTester';
1516

1617
const Main = () => {
1718
const routes = [
@@ -21,6 +22,12 @@ const Main = () => {
2122
name: 'Unix Time Converter',
2223
Component: UnixTimestamp,
2324
},
25+
{
26+
icon: <FontAwesomeIcon icon="registered" />,
27+
path: '/regex-tester',
28+
name: 'Regex Tester',
29+
Component: RegexTester,
30+
},
2431
{
2532
icon: <FontAwesomeIcon icon={['fab', 'markdown']} />,
2633
path: '/markdown-to-html',

src/components/base64/Base64.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ const Base64 = () => {
112112
</div>
113113
<button
114114
type="button"
115-
className="btn"
115+
className="w-16 btn"
116116
onClick={handleCopyOutput}
117117
disabled={copied}
118118
>

src/components/markdown/MarkdownToHtml.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const Md2Html = () => {
5858
</button>
5959
<button
6060
type="button"
61-
className="btn"
61+
className="w-16 btn"
6262
onClick={handleCopy}
6363
disabled={copied}
6464
>

src/components/qrcode/QrCodeReader.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const QRCodeReader = () => {
5959

6060
<button
6161
type="button"
62-
className="btn"
62+
className="w-16 btn"
6363
onClick={handleCopy}
6464
disabled={copied}
6565
>

src/components/regex/RegexTester.tsx

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/* eslint-disable react/no-danger */
2+
import React, { useEffect, useState } from 'react';
3+
import { clipboard } from 'electron';
4+
5+
const RegexTester = () => {
6+
const [search, setSearch] = useState('plai*');
7+
const [flag, setFlag] = useState('gi');
8+
const [input, setInput] = useState(
9+
'PlainBelt - A toolbelt for your plain text'
10+
);
11+
const [output, setOutput] = useState('');
12+
const [match, setMatch] = useState(0);
13+
14+
const handleChangeSearch = (evt: { target: { value: string } }) =>
15+
setSearch(evt.target.value);
16+
17+
const handleChangeFlag = (evt: { target: { value: string } }) =>
18+
setFlag(evt.target.value);
19+
20+
const handleChangeInput = (evt: { target: { value: string } }) =>
21+
setInput(evt.target.value);
22+
23+
const handleClipboardInput = () => {
24+
setInput(clipboard.readText());
25+
};
26+
27+
const handleClipboardSearch = () => {
28+
setSearch(clipboard.readText());
29+
};
30+
31+
useEffect(() => {
32+
try {
33+
const regex = new RegExp(search, flag);
34+
const out = input.replace(
35+
regex,
36+
(str: string) => `<span class='text-blue-500'>${str}</span>`
37+
);
38+
setMatch(input.match(regex)?.length || 0);
39+
setOutput(out);
40+
} catch (e) {
41+
setOutput(e.message);
42+
}
43+
}, [search, input, flag]);
44+
45+
return (
46+
<div className="flex flex-col h-full">
47+
<section className="flex flex-col flex-1 w-full h-full space-y-4">
48+
<section className="flex flex-col">
49+
<div className="flex justify-between mb-1">
50+
<button
51+
type="button"
52+
className="btn"
53+
onClick={handleClipboardSearch}
54+
>
55+
Clipboard
56+
</button>
57+
</div>
58+
<div className="flex items-center space-x-2">
59+
<input
60+
onChange={handleChangeSearch}
61+
className="flex-1 px-4 py-1 bg-white rounded-md"
62+
value={search}
63+
/>
64+
<input
65+
onChange={handleChangeFlag}
66+
className="w-1/12 px-4 py-1 bg-white rounded-md"
67+
value={flag}
68+
/>
69+
</div>
70+
</section>
71+
72+
<section className="flex flex-col flex-1 h-1/3">
73+
<div className="flex justify-between mb-1">
74+
<span className="flex space-x-2">
75+
<button
76+
type="button"
77+
className="btn"
78+
onClick={handleClipboardInput}
79+
>
80+
Clipboard
81+
</button>
82+
</span>
83+
</div>
84+
<textarea
85+
onChange={handleChangeInput}
86+
className="flex-1 p-4 bg-white rounded-md"
87+
value={input}
88+
/>
89+
</section>
90+
91+
<section className="flex flex-col flex-1 h-1/3">
92+
<div className="flex justify-between mb-1">
93+
<div className="flex items-center my-1 space-x-1">
94+
<span>Search for:</span>
95+
<span className="font-mono text-gray-400">
96+
/<span className="text-gray-700">{search}</span>/{flag}
97+
</span>
98+
</div>
99+
<span className="flex space-x-2">
100+
{match} match{match === 1 ? '' : 'es'}
101+
</span>
102+
</div>
103+
<section
104+
className="flex-1 w-full p-4 whitespace-pre bg-gray-100 rounded-md"
105+
dangerouslySetInnerHTML={{ __html: output }}
106+
/>
107+
</section>
108+
</section>
109+
</div>
110+
);
111+
};
112+
113+
export default RegexTester;

src/components/sql/SqlFormatter.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const SqlFormatter = () => {
5151
<span className="flex space-x-4">
5252
<button
5353
type="button"
54-
className="btn"
54+
className="w-16 btn"
5555
onClick={handleCopyOutput}
5656
disabled={copied}
5757
>

src/components/timestamp/UnixTimestamp.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ const UnixTimestampConverter = () => {
179179
</span>
180180
<button
181181
type="button"
182-
className="btn"
182+
className="w-16 btn"
183183
onClick={handleCopy}
184184
disabled={copied}
185185
>

src/helpers/fontAwesome.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
import {
99
faCamera,
1010
faClock,
11+
faRegistered,
1112
faCode,
1213
faCopy,
1314
faDatabase,
@@ -26,5 +27,6 @@ library.add(
2627
faExchangeAlt,
2728
faDatabase,
2829
faJsSquare,
30+
faRegistered,
2931
faCamera
3032
);

src/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "plainbelt",
33
"productName": "plainbelt",
4-
"version": "0.0.2",
4+
"version": "0.0.3",
55
"description": "A toolbelt for all your plain text",
66
"main": "./main.prod.js",
77
"author": {

0 commit comments

Comments
 (0)