-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
139 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export * from './RandomPasswordTool'; | ||
export * from './Convert'; | ||
export * from "./remove-lines" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import {} from '@emotion/react'; | ||
import Editor from '@monaco-editor/react'; | ||
import { Select } from 'antd'; | ||
import { BaseOptionType } from 'antd/es/select'; | ||
import { formatFunc, FormatTool } from './utils'; | ||
|
||
const convertOption: BaseOptionType[] = Object.keys(FormatTool).map((e) => { | ||
return { | ||
label: FormatTool[e as keyof typeof FormatTool], | ||
value: FormatTool[e as keyof typeof FormatTool], | ||
}; | ||
}); | ||
|
||
const RemoveLines = () => { | ||
const [fromValue, setFromValue] = useState(''); | ||
const [toValue, setToValue] = useState(''); | ||
const [convertFunction, setConvertFunction] = useState(''); | ||
const [convertSelected, setConvertSelected] = useState<FormatTool>(FormatTool.DEFAULT); | ||
|
||
const handleConvert = () => { | ||
console.log(convertSelected); | ||
const _formatFunc = formatFunc[convertSelected]; | ||
try { | ||
const _output = _formatFunc(fromValue); | ||
console.log('🚀 ~ file: index.tsx:26 ~ handleConvert ~ _output:', _output); | ||
setToValue(_output); | ||
} catch (e) { | ||
setToValue(JSON.stringify(e, null, 2)); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className="flex h-0 flex-1 flex-shrink items-stretch space-x-3 rounded-md p-1"> | ||
<div className="flex h-full flex-1 rounded-md bg-white shadow-md"> | ||
<div className="flex flex-1 flex-col"> | ||
{/* <div className='h-10'> | ||
copy | ||
</div> */} | ||
<Editor | ||
theme="vs-dark" | ||
height="100%" | ||
width="100%" | ||
defaultLanguage="plaintext" | ||
value={fromValue} | ||
onChange={(value) => value && setFromValue(value)} | ||
defaultValue="" | ||
/> | ||
</div> | ||
</div> | ||
<div className="flex h-full min-w-[300px] flex-col items-stretch justify-center space-y-4 rounded-md bg-white shadow-md"> | ||
<Select | ||
showSearch | ||
defaultValue="default" | ||
onChange={(value) => setConvertSelected(value)} | ||
Check failure on line 55 in src/modules/tools/tools/remove-lines/index.tsx GitHub Actions / build-app (macos-latest)
Check failure on line 55 in src/modules/tools/tools/remove-lines/index.tsx GitHub Actions / build-app (ubuntu-20.04)
Check failure on line 55 in src/modules/tools/tools/remove-lines/index.tsx GitHub Actions / build-app (windows-latest)
Check failure on line 55 in src/modules/tools/tools/remove-lines/index.tsx GitHub Actions / build-app (ubuntu-20.04)
|
||
value={convertSelected} | ||
options={convertOption} | ||
className="w-full" | ||
/> | ||
<button className="rounded-lg bg-blue-300 px-3 py-2 " onClick={handleConvert}> | ||
Convert | ||
</button> | ||
{/* <Editor | ||
theme="vs-dark" | ||
height="100%" | ||
width="100%" | ||
defaultLanguage="javascript" | ||
defaultValue="" | ||
value={convertFunction} | ||
onChange={(value) => value && setConvertFunction(value)} | ||
options={{ | ||
minimap: { | ||
enabled: false, | ||
}, | ||
}} | ||
/> */} | ||
</div> | ||
<div className="flex h-full flex-1 rounded-md bg-white shadow-md"> | ||
<Editor | ||
theme="vs-dark" | ||
height="100%" | ||
width="100%" | ||
defaultLanguage="plaintext" | ||
defaultValue="" | ||
value={toValue} | ||
onChange={(value) => value && setToValue(value)} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default RemoveLines; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { getUniqueCharacters, removeDuplicatedLines, sortLines } from './text'; | ||
|
||
export enum FormatTool { | ||
DEFAULT = 'Default', | ||
REMOVE_DUMPLICATE_LINE = 'remove dumplicate line', | ||
SORT_LINE = 'Sort line', | ||
GET_CHAR = 'Get char', | ||
} | ||
|
||
export const formatFunc = { | ||
[FormatTool.DEFAULT]: (text: string) => text, | ||
[FormatTool.REMOVE_DUMPLICATE_LINE]: removeDuplicatedLines, | ||
[FormatTool.SORT_LINE]: sortLines, | ||
[FormatTool.GET_CHAR]: getUniqueCharacters, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import * as _ from 'lodash'; | ||
|
||
const getLines = (text: string): string[] => { | ||
const lines = _.split(text, /\r?\n/); | ||
return lines; | ||
}; | ||
|
||
export function removeDuplicatedLines(text: string): string { | ||
const lines = getLines(text); | ||
const uniqueLines = _.uniq(lines); | ||
return uniqueLines.join('\n'); | ||
} | ||
|
||
export function sortLines(text: string): string { | ||
const lines = _.split(text, /\r?\n/); | ||
const sortedLines = _.sortBy(lines); | ||
return sortedLines.join('\n'); | ||
} | ||
|
||
export function getUniqueCharacters(text: string): string { | ||
const uniqueChars = new Set(text.split(/\s+|\r\n|\r|\n/)); | ||
const sortedUniqueChars = Array.from(uniqueChars).sort(); | ||
return sortedUniqueChars.join('\n'); | ||
} |