Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- [x] 13. Js Console
- [x] 14. HTML Entity Encode / Decode
- [x] 15. URL Encode / Decode
- [x] 16. Backslash Encode / Decode

## Demo

Expand Down
8 changes: 8 additions & 0 deletions src/components/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import CronEditor from './cron/Cron';
import JsConsole from './notebook/JavaScript';
import HtmlEntityCodec from './html/HtmlEntityCodec';
import UrlCodec from './url/UrlCodec';
import BackSlashCodec from './text/BackSlash';

interface MenuItem {
path: string;
Expand Down Expand Up @@ -143,6 +144,13 @@ const defaultRoutes: MenuItem[] = [
show: false,
Component: UrlCodec,
},
{
icon: <FontAwesomeIcon icon="slash" transform={{ rotate: 42 }} />,
path: '/back-slash-encoder',
name: 'Backslash Encoder',
show: false,
Component: BackSlashCodec,
},
];

const Main = () => {
Expand Down
16 changes: 10 additions & 6 deletions src/components/common/1-to-1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@ import { clipboard } from 'electron';
import React, { useState } from 'react';

interface OneToOneProps {
fromDefault: string;
fromFunc: (f: string) => string;
defaultInput: string;
forwardFunc: (f: string) => string;
inverseFunc: (r: string) => string;
}

const OneToOne = ({ fromDefault, fromFunc, inverseFunc }: OneToOneProps) => {
const [from, setFrom] = useState(fromDefault);
const [to, setTo] = useState(fromFunc(from));
const OneToOne = ({
defaultInput,
forwardFunc,
inverseFunc,
}: OneToOneProps) => {
const [from, setFrom] = useState(defaultInput);
const [to, setTo] = useState(forwardFunc(from));

const [fromCopied, setFromCopied] = useState(false);
const [toCopied, setToCopied] = useState(false);

const changeFrom = (value: string) => {
setFrom(value);
setTo(fromFunc(value));
setTo(forwardFunc(value));
};

const changeTo = (value: string) => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/html/HtmlEntityCodec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import OneToOne from '../common/1-to-1';
const HtmlEntityCodec = () => {
return (
<OneToOne
fromDefault='<script>alert("Hello");</script>'
fromFunc={escape}
defaultInput='<script>alert("Hello");</script>'
forwardFunc={escape}
inverseFunc={unescape}
/>
);
Expand Down
41 changes: 41 additions & 0 deletions src/components/text/BackSlash.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from 'react';
import OneToOne from '../common/1-to-1';

const addSlashes = (string: string) => {
return (
string
.replace(/\\/g, '\\\\')
// eslint-disable-next-line no-control-regex
.replace(/\u0008/g, '\\b')
.replace(/\t/g, '\\t')
.replace(/\n/g, '\\n')
.replace(/\f/g, '\\f')
.replace(/\r/g, '\\r')
.replace(/'/g, "\\'")
.replace(/"/g, '\\"')
);
};

const removeSlashes = (string: string) => {
return string
.replace(/\\"/g, '"')
.replace(/\\'/g, "'")
.replace(/\\r/g, '\r')
.replace(/\\f/g, '\f')
.replace(/\\n/g, '\n')
.replace(/\\t/g, '\t')
.replace(/\\b/, '\u0008')
.replace(/\\\\/g, '\\');
};

const BackSlashCodec = () => {
return (
<OneToOne
defaultInput="Hello\nworld!"
forwardFunc={removeSlashes}
inverseFunc={addSlashes}
/>
);
};

export default BackSlashCodec;
4 changes: 2 additions & 2 deletions src/components/url/UrlCodec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import OneToOne from '../common/1-to-1';
const UrlCodec = () => {
return (
<OneToOne
fromDefault="https://plainlab.github.io/?q=plainbelt"
fromFunc={encodeURIComponent}
defaultInput="https://plainlab.github.io/?q=plainbelt"
forwardFunc={encodeURIComponent}
inverseFunc={decodeURIComponent}
/>
);
Expand Down
2 changes: 2 additions & 0 deletions src/helpers/fontAwesome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
faCheck,
faLink,
faFileCode,
faSlash,
} from '@fortawesome/free-solid-svg-icons';

library.add(
Expand All @@ -50,5 +51,6 @@ library.add(
faSlidersH,
faLink,
faFileCode,
faSlash,
faCheck
);
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "plainbelt",
"productName": "PlainBelt",
"version": "0.0.16",
"version": "0.0.17",
"description": "A plain toolbelt for developers",
"main": "./main.prod.js",
"author": {
Expand Down