diff --git a/README.md b/README.md index 3965309..7926102 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/components/Main.tsx b/src/components/Main.tsx index eb2df35..2bbf204 100644 --- a/src/components/Main.tsx +++ b/src/components/Main.tsx @@ -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; @@ -143,6 +144,13 @@ const defaultRoutes: MenuItem[] = [ show: false, Component: UrlCodec, }, + { + icon: , + path: '/back-slash-encoder', + name: 'Backslash Encoder', + show: false, + Component: BackSlashCodec, + }, ]; const Main = () => { diff --git a/src/components/common/1-to-1.tsx b/src/components/common/1-to-1.tsx index 24d28f1..9719af5 100644 --- a/src/components/common/1-to-1.tsx +++ b/src/components/common/1-to-1.tsx @@ -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) => { diff --git a/src/components/html/HtmlEntityCodec.tsx b/src/components/html/HtmlEntityCodec.tsx index 25d6b59..2c3ec20 100644 --- a/src/components/html/HtmlEntityCodec.tsx +++ b/src/components/html/HtmlEntityCodec.tsx @@ -5,8 +5,8 @@ import OneToOne from '../common/1-to-1'; const HtmlEntityCodec = () => { return ( ); diff --git a/src/components/text/BackSlash.tsx b/src/components/text/BackSlash.tsx new file mode 100644 index 0000000..5081bf2 --- /dev/null +++ b/src/components/text/BackSlash.tsx @@ -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 ( + + ); +}; + +export default BackSlashCodec; diff --git a/src/components/url/UrlCodec.tsx b/src/components/url/UrlCodec.tsx index a2ae182..10d190c 100644 --- a/src/components/url/UrlCodec.tsx +++ b/src/components/url/UrlCodec.tsx @@ -4,8 +4,8 @@ import OneToOne from '../common/1-to-1'; const UrlCodec = () => { return ( ); diff --git a/src/helpers/fontAwesome.ts b/src/helpers/fontAwesome.ts index 605f229..30e9283 100644 --- a/src/helpers/fontAwesome.ts +++ b/src/helpers/fontAwesome.ts @@ -25,6 +25,7 @@ import { faCheck, faLink, faFileCode, + faSlash, } from '@fortawesome/free-solid-svg-icons'; library.add( @@ -50,5 +51,6 @@ library.add( faSlidersH, faLink, faFileCode, + faSlash, faCheck ); diff --git a/src/package.json b/src/package.json index 38b9765..cc02e37 100644 --- a/src/package.json +++ b/src/package.json @@ -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": {