File tree Expand file tree Collapse file tree 8 files changed +67
-11
lines changed Expand file tree Collapse file tree 8 files changed +67
-11
lines changed Original file line number Diff line number Diff line change 2828- [x] 13 . Js Console
2929- [x] 14 . HTML Entity Encode / Decode
3030- [x] 15 . URL Encode / Decode
31+ - [x] 16 . Backslash Encode / Decode
3132
3233## Demo
3334
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import CronEditor from './cron/Cron';
2121import JsConsole from './notebook/JavaScript' ;
2222import HtmlEntityCodec from './html/HtmlEntityCodec' ;
2323import UrlCodec from './url/UrlCodec' ;
24+ import BackSlashCodec from './text/BackSlash' ;
2425
2526interface MenuItem {
2627 path : string ;
@@ -143,6 +144,13 @@ const defaultRoutes: MenuItem[] = [
143144 show : false ,
144145 Component : UrlCodec ,
145146 } ,
147+ {
148+ icon : < FontAwesomeIcon icon = "slash" transform = { { rotate : 42 } } /> ,
149+ path : '/back-slash-encoder' ,
150+ name : 'Backslash Encoder' ,
151+ show : false ,
152+ Component : BackSlashCodec ,
153+ } ,
146154] ;
147155
148156const Main = ( ) => {
Original file line number Diff line number Diff line change @@ -2,21 +2,25 @@ import { clipboard } from 'electron';
22import React , { useState } from 'react' ;
33
44interface OneToOneProps {
5- fromDefault : string ;
6- fromFunc : ( f : string ) => string ;
5+ defaultInput : string ;
6+ forwardFunc : ( f : string ) => string ;
77 inverseFunc : ( r : string ) => string ;
88}
99
10- const OneToOne = ( { fromDefault, fromFunc, inverseFunc } : OneToOneProps ) => {
11- const [ from , setFrom ] = useState ( fromDefault ) ;
12- const [ to , setTo ] = useState ( fromFunc ( from ) ) ;
10+ const OneToOne = ( {
11+ defaultInput,
12+ forwardFunc,
13+ inverseFunc,
14+ } : OneToOneProps ) => {
15+ const [ from , setFrom ] = useState ( defaultInput ) ;
16+ const [ to , setTo ] = useState ( forwardFunc ( from ) ) ;
1317
1418 const [ fromCopied , setFromCopied ] = useState ( false ) ;
1519 const [ toCopied , setToCopied ] = useState ( false ) ;
1620
1721 const changeFrom = ( value : string ) => {
1822 setFrom ( value ) ;
19- setTo ( fromFunc ( value ) ) ;
23+ setTo ( forwardFunc ( value ) ) ;
2024 } ;
2125
2226 const changeTo = ( value : string ) => {
Original file line number Diff line number Diff line change @@ -5,8 +5,8 @@ import OneToOne from '../common/1-to-1';
55const HtmlEntityCodec = ( ) => {
66 return (
77 < OneToOne
8- fromDefault = '<script>alert("Hello");</script>'
9- fromFunc = { escape }
8+ defaultInput = '<script>alert("Hello");</script>'
9+ forwardFunc = { escape }
1010 inverseFunc = { unescape }
1111 />
1212 ) ;
Original file line number Diff line number Diff line change 1+ import React from 'react' ;
2+ import OneToOne from '../common/1-to-1' ;
3+
4+ const addSlashes = ( string : string ) => {
5+ return (
6+ string
7+ . replace ( / \\ / g, '\\\\' )
8+ // eslint-disable-next-line no-control-regex
9+ . replace ( / \u0008 / g, '\\b' )
10+ . replace ( / \t / g, '\\t' )
11+ . replace ( / \n / g, '\\n' )
12+ . replace ( / \f / g, '\\f' )
13+ . replace ( / \r / g, '\\r' )
14+ . replace ( / ' / g, "\\'" )
15+ . replace ( / " / g, '\\"' )
16+ ) ;
17+ } ;
18+
19+ const removeSlashes = ( string : string ) => {
20+ return string
21+ . replace ( / \\ " / g, '"' )
22+ . replace ( / \\ ' / g, "'" )
23+ . replace ( / \\ r / g, '\r' )
24+ . replace ( / \\ f / g, '\f' )
25+ . replace ( / \\ n / g, '\n' )
26+ . replace ( / \\ t / g, '\t' )
27+ . replace ( / \\ b / , '\u0008' )
28+ . replace ( / \\ \\ / g, '\\' ) ;
29+ } ;
30+
31+ const BackSlashCodec = ( ) => {
32+ return (
33+ < OneToOne
34+ defaultInput = "Hello\nworld!"
35+ forwardFunc = { removeSlashes }
36+ inverseFunc = { addSlashes }
37+ />
38+ ) ;
39+ } ;
40+
41+ export default BackSlashCodec ;
Original file line number Diff line number Diff line change @@ -4,8 +4,8 @@ import OneToOne from '../common/1-to-1';
44const UrlCodec = ( ) => {
55 return (
66 < OneToOne
7- fromDefault = "https://plainlab.github.io/?q=plainbelt"
8- fromFunc = { encodeURIComponent }
7+ defaultInput = "https://plainlab.github.io/?q=plainbelt"
8+ forwardFunc = { encodeURIComponent }
99 inverseFunc = { decodeURIComponent }
1010 />
1111 ) ;
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ import {
2525 faCheck ,
2626 faLink ,
2727 faFileCode ,
28+ faSlash ,
2829} from '@fortawesome/free-solid-svg-icons' ;
2930
3031library . add (
@@ -50,5 +51,6 @@ library.add(
5051 faSlidersH ,
5152 faLink ,
5253 faFileCode ,
54+ faSlash ,
5355 faCheck
5456) ;
Original file line number Diff line number Diff line change 11{
22 "name" : " plainbelt" ,
33 "productName" : " PlainBelt" ,
4- "version" : " 0.0.16 " ,
4+ "version" : " 0.0.17 " ,
55 "description" : " A plain toolbelt for developers" ,
66 "main" : " ./main.prod.js" ,
77 "author" : {
You can’t perform that action at this time.
0 commit comments