This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { FC, ReactNode } from "react";
|
||||
import { FC, ReactNode } from 'react'
|
||||
|
||||
import style from './style.module.scss'
|
||||
|
||||
@ -6,7 +6,6 @@ interface AppLayoutProp {
|
||||
children?: ReactNode
|
||||
}
|
||||
|
||||
export const AppLayout: FC<AppLayoutProp> = ({ children }) =>
|
||||
<div className={style.container}>
|
||||
{children}
|
||||
</div>
|
||||
export const AppLayout: FC<AppLayoutProp> = ({ children }) => (
|
||||
<div className={style.container}>{children}</div>
|
||||
)
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { FC } from "react";
|
||||
import { AppLayout } from "./AppLayout";
|
||||
import { Editor } from "../Editor";
|
||||
import { TransformGrid } from "../TransformGrid";
|
||||
import { FC } from 'react'
|
||||
import { AppLayout } from './AppLayout'
|
||||
import { Editor } from '../Editor'
|
||||
import { TransformGrid } from '../TransformGrid'
|
||||
|
||||
export const App: FC = () =>
|
||||
export const App: FC = () => (
|
||||
<AppLayout>
|
||||
<Editor />
|
||||
<TransformGrid />
|
||||
</AppLayout>
|
||||
|
||||
)
|
||||
|
@ -1,4 +1,4 @@
|
||||
import styled from "styled-components";
|
||||
import styled from 'styled-components'
|
||||
|
||||
export const Button = styled.button`
|
||||
border: none;
|
||||
@ -10,7 +10,7 @@ export const Button = styled.button`
|
||||
|
||||
transition: background-color 0.25s ease-out;
|
||||
|
||||
&:hover {
|
||||
&:hover {
|
||||
background-color: #da1c9b;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import styled from "styled-components";
|
||||
import styled from 'styled-components'
|
||||
|
||||
export const Input = styled.input`
|
||||
background-color: transparent;
|
||||
@ -9,10 +9,10 @@ export const Input = styled.input`
|
||||
accent-color: #ff1696;
|
||||
box-sizing: border-box;
|
||||
font-size: 12px;
|
||||
|
||||
|
||||
width: 24px;
|
||||
|
||||
&[type=checkbox] {
|
||||
&[type='checkbox'] {
|
||||
width: auto;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import styled from "styled-components";
|
||||
import styled from 'styled-components'
|
||||
|
||||
export const TextArea = styled.textarea`
|
||||
border: none;
|
||||
|
@ -1,15 +1,16 @@
|
||||
import { createRef, FC, useEffect, useRef } from "react";
|
||||
import { Editor as MonacoEditor } from "@monaco-editor/react";
|
||||
import { useRecoilState } from "recoil";
|
||||
import { EditorValueState } from "../GlobalStates/EditorValueState";
|
||||
import { motion } from "framer-motion";
|
||||
import { VERSION } from "../version";
|
||||
import { createRef, FC, useEffect, useRef } from 'react'
|
||||
import { Editor as MonacoEditor } from '@monaco-editor/react'
|
||||
import { useRecoilState } from 'recoil'
|
||||
import { EditorValueState } from '../GlobalStates/EditorValueState'
|
||||
import { motion } from 'framer-motion'
|
||||
import { VERSION } from '../version'
|
||||
import { editor } from 'monaco-editor'
|
||||
|
||||
import style from "./style.module.scss";
|
||||
import style from './style.module.scss'
|
||||
|
||||
export const Editor: FC = () => {
|
||||
const [value, setValue] = useRecoilState(EditorValueState)
|
||||
const ref = useRef<any>()
|
||||
const ref = useRef<editor.IStandaloneCodeEditor>()
|
||||
const containerRef = createRef<HTMLDivElement>()
|
||||
|
||||
useEffect(() => {
|
||||
@ -20,11 +21,11 @@ export const Editor: FC = () => {
|
||||
const rect = containerRef.current?.getBoundingClientRect()
|
||||
ref.current?.layout({
|
||||
width: rect?.width ?? 0,
|
||||
height: rect?.height ?? 0
|
||||
height: rect?.height ?? 0,
|
||||
})
|
||||
})
|
||||
})
|
||||
}, [])
|
||||
}, [containerRef])
|
||||
|
||||
return (
|
||||
<motion.div
|
||||
@ -32,33 +33,37 @@ export const Editor: FC = () => {
|
||||
ref={containerRef}
|
||||
transition={{ delay: 1.5 }}
|
||||
initial={{ opacity: 0 }}
|
||||
animate={{ opacity: 1 }}>
|
||||
animate={{ opacity: 1 }}
|
||||
>
|
||||
<MonacoEditor
|
||||
loading={<></>}
|
||||
value={value}
|
||||
language="yaml"
|
||||
onMount={(v) => ref.current = v}
|
||||
onMount={(v) => (ref.current = v)}
|
||||
onChange={(v) => setValue(v ?? '')}
|
||||
options={{
|
||||
automaticLayout: true,
|
||||
lineNumbersMinChars: 3,
|
||||
minimap: { enabled: false },
|
||||
theme: "vs-dark",
|
||||
theme: 'vs-dark',
|
||||
fontSize: 24,
|
||||
fontFamily: 'JetBrains Mono Variable',
|
||||
fontLigatures: true,
|
||||
wordWrap: "on",
|
||||
wordWrap: 'on',
|
||||
mouseWheelZoom: true,
|
||||
smoothScrolling: true,
|
||||
cursorSmoothCaretAnimation: 'on',
|
||||
cursorBlinking: 'smooth',
|
||||
cursorStyle: 'line'
|
||||
cursorStyle: 'line',
|
||||
}}
|
||||
theme="vs-dark" />
|
||||
theme="vs-dark"
|
||||
/>
|
||||
|
||||
<div className={style.credit}>
|
||||
<div className={style.creditstr}>
|
||||
<p><b>The PTOOLS</b></p>
|
||||
<p>
|
||||
<b>The PTOOLS</b>
|
||||
</p>
|
||||
<p>v2-{VERSION}</p>
|
||||
<p>© Minhyeok Park</p>
|
||||
</div>
|
||||
|
@ -1,8 +1,12 @@
|
||||
import { atom } from "recoil";
|
||||
import { atom } from 'recoil'
|
||||
|
||||
export const EditorValueState = atom({
|
||||
key: 'editor_value',
|
||||
default: JSON.stringify({
|
||||
Hello: 'world!'
|
||||
}, null, 2)
|
||||
default: JSON.stringify(
|
||||
{
|
||||
Hello: 'world!',
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
})
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { FC, useEffect, useState } from "react";
|
||||
import { FC, useEffect, useState } from 'react'
|
||||
import { AnimatePresence, motion, TargetAndTransition } from 'framer-motion'
|
||||
|
||||
import style from './style.module.scss'
|
||||
@ -7,7 +7,7 @@ import Suika from '../Assets/favicon.webp'
|
||||
export const LandingAnimation: FC = () => {
|
||||
const [isVisible, setVisible] = useState(true)
|
||||
const exitAnimation: TargetAndTransition = {
|
||||
opacity: 0
|
||||
opacity: 0,
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
|
@ -1,22 +1,21 @@
|
||||
import { FC } from "react";
|
||||
import { motion } from "framer-motion";
|
||||
import { FC } from 'react'
|
||||
import { motion } from 'framer-motion'
|
||||
|
||||
import style from './style.module.scss'
|
||||
import { TransformGridItem } from "../TransformGridItem";
|
||||
import { transforms, wrapTransform } from "../Transforms/Transform";
|
||||
import { TransformGridItem } from '../TransformGridItem'
|
||||
import { transforms, wrapTransform } from '../Transforms/Transform'
|
||||
|
||||
export const TransformGrid: FC = () =>
|
||||
export const TransformGrid: FC = () => (
|
||||
<ul className={style.grid}>
|
||||
{transforms.map((transform, i) =>
|
||||
{transforms.map((transform, i) => (
|
||||
<motion.li
|
||||
key={i}
|
||||
initial={{ opacity: 0 }}
|
||||
animate={{ opacity: 1 }}
|
||||
transition={{ delay: i * 0.1 + 1.5 }} >
|
||||
|
||||
<TransformGridItem
|
||||
transform={wrapTransform(transform)}/>
|
||||
|
||||
transition={{ delay: i * 0.1 + 1.5 }}
|
||||
>
|
||||
<TransformGridItem transform={wrapTransform(transform)} />
|
||||
</motion.li>
|
||||
)}
|
||||
))}
|
||||
</ul>
|
||||
)
|
||||
|
@ -1,22 +1,25 @@
|
||||
import { ChangeEvent, FC, useEffect, useState } from "react";
|
||||
// src/components/TransformGridItem.tsx
|
||||
|
||||
import { ChangeEvent, FC, useEffect, useState } from 'react'
|
||||
import style from './style.module.scss'
|
||||
import { Button } from "../Components/Button";
|
||||
import { Input } from "../Components/Input";
|
||||
import { TextArea } from "../Components/TextArea";
|
||||
import clsx from "clsx";
|
||||
import { useRecoilState } from "recoil";
|
||||
import { EditorValueState } from "../GlobalStates/EditorValueState";
|
||||
import { Button } from '../Components/Button'
|
||||
import { Input } from '../Components/Input'
|
||||
// Remove TextArea import as it's no longer used
|
||||
import clsx from 'clsx'
|
||||
import { useRecoilState } from 'recoil'
|
||||
import { EditorValueState } from '../GlobalStates/EditorValueState'
|
||||
import {
|
||||
TransformCheckboxOption,
|
||||
TransformIntboxOption,
|
||||
TransformRadioOption,
|
||||
TransformTextboxOption,
|
||||
WrappedTransform,
|
||||
WrappedTransformResult
|
||||
} from "../Transforms/Transform";
|
||||
import { useLocalStorage } from "@uidotdev/usehooks";
|
||||
import { AnimatePresence, motion } from "framer-motion";
|
||||
WrappedTransformResult,
|
||||
} from '../Transforms/Transform'
|
||||
import { useLocalStorage } from '@uidotdev/usehooks'
|
||||
import { AnimatePresence, motion } from 'framer-motion'
|
||||
import { Tooltip } from 'react-tooltip'
|
||||
import { TextArea } from '../Components/TextArea'
|
||||
|
||||
interface TransformGridItemProp {
|
||||
transform: WrappedTransform
|
||||
@ -25,12 +28,15 @@ interface TransformGridItemProp {
|
||||
export const TransformGridItem: FC<TransformGridItemProp> = ({ transform }) => {
|
||||
const [value, setValue] = useRecoilState(EditorValueState)
|
||||
const [options, setOptions] = useState(transform.options)
|
||||
const [closedToggle, setClosedToggle] = useLocalStorage(`transform_closed__${transform.name}`, false)
|
||||
const [closedToggle, setClosedToggle] = useLocalStorage(
|
||||
`transform_closed__${transform.name}`,
|
||||
false,
|
||||
)
|
||||
const [result, setResult] = useState<WrappedTransformResult>({
|
||||
error: false,
|
||||
value: ''
|
||||
value: '',
|
||||
})
|
||||
|
||||
|
||||
const previewDisabled = value.length > 30000
|
||||
const closed = previewDisabled || closedToggle
|
||||
|
||||
@ -41,102 +47,102 @@ export const TransformGridItem: FC<TransformGridItemProp> = ({ transform }) => {
|
||||
setResult(result)
|
||||
return result
|
||||
})
|
||||
|
||||
// trigger transform when value, option or closed state changed
|
||||
useEffect(() => {
|
||||
if (previewDisabled)
|
||||
return
|
||||
.catch((error) => {
|
||||
setResult({ error: true, value: error.toString() })
|
||||
return { error: true, value: error.toString() }
|
||||
})
|
||||
|
||||
triggerTransform()
|
||||
}, [value, options, closed])
|
||||
|
||||
// reset error state when option changed
|
||||
// Trigger transform when value, option or closed state changes
|
||||
useEffect(() => {
|
||||
if (!previewDisabled)
|
||||
return
|
||||
if (previewDisabled) return
|
||||
|
||||
transform
|
||||
.fn(value, options)
|
||||
.then(setResult.bind(this))
|
||||
.catch((error) => setResult({ error: true, value: error.toString() }))
|
||||
}, [value, options, closed, previewDisabled, transform])
|
||||
|
||||
// Reset error state when options change
|
||||
useEffect(() => {
|
||||
if (!previewDisabled) return
|
||||
|
||||
setResult({
|
||||
error: false,
|
||||
value: ''
|
||||
value: '',
|
||||
})
|
||||
}, [options])
|
||||
}, [options, previewDisabled])
|
||||
|
||||
// forcely disable preview when value is longer than 30,000 chars
|
||||
// Force disable preview when value is longer than 30,000 chars
|
||||
useEffect(() => {
|
||||
if (previewDisabled) {
|
||||
setResult({
|
||||
error: false,
|
||||
value: ''
|
||||
value: '',
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
triggerTransform()
|
||||
}, [value])
|
||||
transform
|
||||
.fn(value, options)
|
||||
.then(setResult.bind(this))
|
||||
.catch((error) => setResult({ error: true, value: error.toString() }))
|
||||
}, [value, previewDisabled, transform, options])
|
||||
|
||||
const onCheckboxOptionChanged =
|
||||
(option: TransformCheckboxOption) =>
|
||||
(event: ChangeEvent<HTMLInputElement>) => {
|
||||
|
||||
options.set(option.key, {
|
||||
...option,
|
||||
value: event.target.checked
|
||||
})
|
||||
options.set(option.key, {
|
||||
...option,
|
||||
value: event.target.checked,
|
||||
})
|
||||
|
||||
setOptions(new Map(options))
|
||||
}
|
||||
setOptions(new Map(options))
|
||||
}
|
||||
|
||||
|
||||
const onTextboxOptionChanged =
|
||||
(option: TransformTextboxOption) =>
|
||||
(event: ChangeEvent<HTMLInputElement>) => {
|
||||
|
||||
options.set(option.key, {
|
||||
...option,
|
||||
value: event.target.value
|
||||
})
|
||||
options.set(option.key, {
|
||||
...option,
|
||||
value: event.target.value,
|
||||
})
|
||||
|
||||
setOptions(new Map(options))
|
||||
}
|
||||
|
||||
setOptions(new Map(options))
|
||||
}
|
||||
|
||||
const onIntboxOptionChanged =
|
||||
(option: TransformIntboxOption) =>
|
||||
(event: ChangeEvent<HTMLInputElement>) => {
|
||||
|
||||
options.set(option.key, {
|
||||
...option,
|
||||
value: parseInt(event.target.value)
|
||||
})
|
||||
options.set(option.key, {
|
||||
...option,
|
||||
value: parseInt(event.target.value),
|
||||
})
|
||||
|
||||
setOptions(new Map(options))
|
||||
}
|
||||
|
||||
setOptions(new Map(options))
|
||||
}
|
||||
|
||||
const onRadioOptionChanged =
|
||||
(option: TransformRadioOption) =>
|
||||
(event: ChangeEvent<HTMLInputElement>) => {
|
||||
|
||||
options.set(option.key, {
|
||||
...option,
|
||||
value: event.target.value
|
||||
})
|
||||
options.set(option.key, {
|
||||
...option,
|
||||
value: event.target.value,
|
||||
})
|
||||
|
||||
setOptions(new Map(options))
|
||||
}
|
||||
setOptions(new Map(options))
|
||||
}
|
||||
|
||||
const onForwardButtonPressed = async () => {
|
||||
const result =
|
||||
await triggerTransform()
|
||||
const result = await triggerTransform()
|
||||
|
||||
if (result.error)
|
||||
return
|
||||
if (result.error) return
|
||||
|
||||
setValue(result.value)
|
||||
}
|
||||
|
||||
const onLabelClicked = async () => {
|
||||
if (previewDisabled)
|
||||
return
|
||||
|
||||
if (previewDisabled) return
|
||||
|
||||
setClosedToggle(!closed)
|
||||
}
|
||||
|
||||
@ -144,25 +150,26 @@ export const TransformGridItem: FC<TransformGridItemProp> = ({ transform }) => {
|
||||
<div className={clsx(style.item, closed && style.closed)}>
|
||||
<div className={style.toolbar}>
|
||||
<div data-tooltip-id={`${transform.name}-tooltip`}>
|
||||
<Button
|
||||
disabled={result.error}
|
||||
onClick={onForwardButtonPressed}>
|
||||
|
||||
<Button disabled={result.error} onClick={onForwardButtonPressed}>
|
||||
<<<
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<Tooltip className={style.error} id={`${transform.name}-tooltip`} place="bottom">
|
||||
<Tooltip
|
||||
className={style.error}
|
||||
id={`${transform.name}-tooltip`}
|
||||
place="bottom"
|
||||
>
|
||||
{previewDisabled && result.error && result.value}
|
||||
</Tooltip>
|
||||
|
||||
|
||||
<h2
|
||||
onClick={onLabelClicked}
|
||||
className={clsx(style.name, previewDisabled && style.previewDisabled)}>
|
||||
|
||||
className={clsx(style.name, previewDisabled && style.previewDisabled)}
|
||||
>
|
||||
{transform.name}
|
||||
</h2>
|
||||
|
||||
|
||||
<div className={style.options}>
|
||||
{[...options.values()]
|
||||
?.filter((v) => v.type === 'CHECKBOX')
|
||||
@ -173,9 +180,11 @@ export const TransformGridItem: FC<TransformGridItemProp> = ({ transform }) => {
|
||||
<Input
|
||||
checked={option.value}
|
||||
onChange={onCheckboxOptionChanged(option)}
|
||||
type="checkbox" />
|
||||
</label>))}
|
||||
|
||||
type="checkbox"
|
||||
/>
|
||||
</label>
|
||||
))}
|
||||
|
||||
{[...options.values()]
|
||||
?.filter((v) => v.type === 'TEXTBOX')
|
||||
.map((option, i) => (
|
||||
@ -185,10 +194,11 @@ export const TransformGridItem: FC<TransformGridItemProp> = ({ transform }) => {
|
||||
<Input
|
||||
value={option.value}
|
||||
onChange={onTextboxOptionChanged(option)}
|
||||
type="text" />
|
||||
</label>))}
|
||||
type="text"
|
||||
/>
|
||||
</label>
|
||||
))}
|
||||
|
||||
|
||||
{[...options.values()]
|
||||
?.filter((v) => v.type === 'INTBOX')
|
||||
.map((option, i) => (
|
||||
@ -199,17 +209,19 @@ export const TransformGridItem: FC<TransformGridItemProp> = ({ transform }) => {
|
||||
min={1}
|
||||
value={option.value}
|
||||
onChange={onIntboxOptionChanged(option)}
|
||||
type="number" />
|
||||
</label>))}
|
||||
type="number"
|
||||
/>
|
||||
</label>
|
||||
))}
|
||||
|
||||
|
||||
{[...options.values()]
|
||||
?.filter((v) => v.type === 'RADIO')
|
||||
.map((option, i) => (
|
||||
<div
|
||||
key={i}
|
||||
onChange={onRadioOptionChanged(option)}
|
||||
className={style.optionItem}>
|
||||
className={style.optionItem}
|
||||
>
|
||||
{option.radios.map((radio, i2) => (
|
||||
<label key={i2}>
|
||||
<p>{radio.label ?? radio.value}:</p>
|
||||
@ -219,28 +231,31 @@ export const TransformGridItem: FC<TransformGridItemProp> = ({ transform }) => {
|
||||
name={option.key}
|
||||
defaultChecked={radio.value === option.value}
|
||||
value={radio.value}
|
||||
type="radio" />
|
||||
type="radio"
|
||||
/>
|
||||
</label>
|
||||
))}
|
||||
|
||||
</div>))}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<AnimatePresence>
|
||||
{!closed &&
|
||||
{!closed && (
|
||||
<motion.div
|
||||
initial={{ height: 0 }}
|
||||
animate={{ height: 200 }}
|
||||
exit={{ height: 0 }}
|
||||
className={style.output}>
|
||||
className={style.output}
|
||||
>
|
||||
<TextArea
|
||||
readOnly
|
||||
value={result.value}
|
||||
placeholder="(empty)"
|
||||
className={clsx(result.error && style.error)} />
|
||||
className={clsx(result.error && style.error)}
|
||||
/>
|
||||
</motion.div>
|
||||
}
|
||||
)}
|
||||
</AnimatePresence>
|
||||
</div>
|
||||
)
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { Transform } from "./Transform";
|
||||
import { Transform } from './Transform'
|
||||
|
||||
export const Base64DecodeTransform: Transform = {
|
||||
name: 'base64d',
|
||||
fn: async (v) => atob(v)
|
||||
fn: async (v) => atob(v),
|
||||
}
|
||||
|
||||
export const Base64EncodeTransform: Transform = {
|
||||
name: 'base64e',
|
||||
fn: async (v) => btoa(v)
|
||||
fn: async (v) => btoa(v),
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { Transform } from "./Transform";
|
||||
import { Transform } from './Transform'
|
||||
import { strptime } from 'strtime'
|
||||
import moment from "moment";
|
||||
import moment from 'moment'
|
||||
|
||||
export const DatetimeTransform: Transform = {
|
||||
name: 'datetime',
|
||||
@ -17,34 +17,31 @@ export const DatetimeTransform: Transform = {
|
||||
|
||||
if (format === 'java')
|
||||
return moment(sample, expression.replace(/'/g, '')).toDate()
|
||||
|
||||
|
||||
throw new Error('Unknown Format')
|
||||
})
|
||||
.map((date) => JSON.stringify({
|
||||
year: date.getFullYear(),
|
||||
month: date.getMonth() + 1,
|
||||
date: date.getDate(),
|
||||
hour: date.getHours(),
|
||||
minute: date.getMinutes(),
|
||||
second: date.getSeconds(),
|
||||
milli: date.getMilliseconds()
|
||||
}))
|
||||
.map((date) =>
|
||||
JSON.stringify({
|
||||
year: date.getFullYear(),
|
||||
month: date.getMonth() + 1,
|
||||
date: date.getDate(),
|
||||
hour: date.getHours(),
|
||||
minute: date.getMinutes(),
|
||||
second: date.getSeconds(),
|
||||
milli: date.getMilliseconds(),
|
||||
}),
|
||||
)
|
||||
.join('\n')
|
||||
|
||||
return [
|
||||
expression,
|
||||
samples,
|
||||
parsedSamples
|
||||
].join('\n\n')
|
||||
return [expression, samples, parsedSamples].join('\n\n')
|
||||
},
|
||||
|
||||
options: [{
|
||||
type: 'RADIO',
|
||||
key: 'f',
|
||||
value: 'c',
|
||||
radios: [
|
||||
{ value: 'c' },
|
||||
{ value: 'java' }
|
||||
]
|
||||
}]
|
||||
options: [
|
||||
{
|
||||
type: 'RADIO',
|
||||
key: 'f',
|
||||
value: 'c',
|
||||
radios: [{ value: 'c' }, { value: 'java' }],
|
||||
},
|
||||
],
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
// GzipCompressTransform.ts
|
||||
import { Transform } from "./Transform"
|
||||
import { Transform } from './Transform'
|
||||
|
||||
/**
|
||||
* Compresses a string using Gzip and encodes the result in Base64.
|
||||
@ -8,8 +8,10 @@ import { Transform } from "./Transform"
|
||||
*/
|
||||
const compressGzip = async (input: string): Promise<string> => {
|
||||
// Check if CompressionStream is supported
|
||||
if (typeof CompressionStream === "undefined") {
|
||||
throw new Error("CompressionStream API is not supported in this environment.")
|
||||
if (typeof CompressionStream === 'undefined') {
|
||||
throw new Error(
|
||||
'CompressionStream API is not supported in this environment.',
|
||||
)
|
||||
}
|
||||
|
||||
// Encode the input string to a Uint8Array
|
||||
@ -21,11 +23,11 @@ const compressGzip = async (input: string): Promise<string> => {
|
||||
start(controller) {
|
||||
controller.enqueue(encoded)
|
||||
controller.close()
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
// Create a CompressionStream for Gzip
|
||||
const compressionStream = new CompressionStream("gzip")
|
||||
const compressionStream = new CompressionStream('gzip')
|
||||
|
||||
// Pipe the readable stream through the compression stream
|
||||
const compressedStream = readable.pipeThrough(compressionStream)
|
||||
@ -64,7 +66,7 @@ const compressGzip = async (input: string): Promise<string> => {
|
||||
* @returns The Base64-encoded string.
|
||||
*/
|
||||
const arrayBufferToBase64 = (buffer: Uint8Array): string => {
|
||||
let binary = ""
|
||||
let binary = ''
|
||||
for (let i = 0; i < buffer.length; i++) {
|
||||
binary += String.fromCharCode(buffer[i])
|
||||
}
|
||||
@ -76,5 +78,5 @@ export const GzipCompressTransform: Transform = {
|
||||
|
||||
fn: (v: string) => compressGzip(v),
|
||||
|
||||
options: [] // Add any options if needed
|
||||
options: [], // Add any options if needed
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Transform } from "./Transform"
|
||||
import { Transform } from './Transform'
|
||||
|
||||
const decompressGzip = async (base64: string) => {
|
||||
const byteCharacters = atob(base64)
|
||||
@ -7,17 +7,15 @@ const decompressGzip = async (base64: string) => {
|
||||
for (let i = 0; i < byteCharacters.length; i++)
|
||||
byteNumbers[i] = byteCharacters.charCodeAt(i)
|
||||
|
||||
const decompressedStream =
|
||||
new Blob([new Uint8Array(byteNumbers)])
|
||||
.stream()
|
||||
.pipeThrough(new DecompressionStream("gzip"))
|
||||
const decompressedStream = new Blob([new Uint8Array(byteNumbers)])
|
||||
.stream()
|
||||
.pipeThrough(new DecompressionStream('gzip'))
|
||||
|
||||
return await new Response(decompressedStream).text()
|
||||
}
|
||||
|
||||
export const GzipDecompressTransform: Transform = {
|
||||
name: 'gzipd',
|
||||
|
||||
fn: (v) => decompressGzip(v)
|
||||
}
|
||||
|
||||
fn: (v) => decompressGzip(v),
|
||||
}
|
||||
|
@ -1,50 +1,60 @@
|
||||
import JSON5 from 'json5'
|
||||
import { Transform } from "./Transform";
|
||||
import { Transform } from './Transform'
|
||||
|
||||
export const JSONBeautifyTransform: Transform = {
|
||||
name: 'jsonbtf',
|
||||
|
||||
fn: async (v, o) =>
|
||||
o.get('multiline')?.value === true
|
||||
? JSON.stringify(JSON5.parse(v), null, o.get('tab')?.value as number ?? 2)
|
||||
: v.split('\n').map((v2) => JSON.stringify(JSON5.parse(v2), null, o.get('tab')?.value as number ?? 2)).join('\n'),
|
||||
? JSON.stringify(
|
||||
JSON5.parse(v),
|
||||
null,
|
||||
(o.get('tab')?.value as number) ?? 2,
|
||||
)
|
||||
: v
|
||||
.split('\n')
|
||||
.map((v2) =>
|
||||
JSON.stringify(
|
||||
JSON5.parse(v2),
|
||||
null,
|
||||
(o.get('tab')?.value as number) ?? 2,
|
||||
),
|
||||
)
|
||||
.join('\n'),
|
||||
|
||||
options: [
|
||||
{
|
||||
type: 'CHECKBOX',
|
||||
key: 'multiline'
|
||||
key: 'multiline',
|
||||
},
|
||||
{
|
||||
type: 'INTBOX',
|
||||
key: 'tab',
|
||||
value: 2
|
||||
}
|
||||
]
|
||||
value: 2,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
export const JSONSimplifyTransform: Transform = {
|
||||
name: 'jsonsmp',
|
||||
|
||||
fn: async (v) =>
|
||||
JSON.stringify(JSON5.parse(v))
|
||||
|
||||
fn: async (v) => JSON.stringify(JSON5.parse(v)),
|
||||
}
|
||||
|
||||
export const JSONEscapeTransform: Transform = {
|
||||
name: 'jsonesc',
|
||||
|
||||
fn: async (v) =>
|
||||
JSON.stringify(v)
|
||||
fn: async (v) => JSON.stringify(v),
|
||||
}
|
||||
|
||||
export const JSONUnescapeTransform: Transform = {
|
||||
name: 'jsonunesc',
|
||||
|
||||
|
||||
fn: async (v) => {
|
||||
const result = JSON5.parse(v)
|
||||
|
||||
if (typeof result !== 'string')
|
||||
throw new Error('Not JSON escaped')
|
||||
if (typeof result !== 'string') throw new Error('Not JSON escaped')
|
||||
|
||||
return result
|
||||
}
|
||||
},
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Transform } from "./Transform";
|
||||
import { Transform } from './Transform'
|
||||
|
||||
export const RegexpTransform: Transform = {
|
||||
name: 'regexp',
|
||||
@ -8,14 +8,9 @@ export const RegexpTransform: Transform = {
|
||||
|
||||
const parsedSamples = samples
|
||||
.split('\n')
|
||||
.map((sample) =>
|
||||
JSON.stringify(regexp.exec(sample)?.groups))
|
||||
.map((sample) => JSON.stringify(regexp.exec(sample)?.groups))
|
||||
.join('\n')
|
||||
|
||||
return [
|
||||
expression,
|
||||
samples,
|
||||
parsedSamples
|
||||
].join('\n\n')
|
||||
}
|
||||
return [expression, samples, parsedSamples].join('\n\n')
|
||||
},
|
||||
}
|
||||
|
@ -1,48 +1,57 @@
|
||||
import { Base64DecodeTransform, Base64EncodeTransform } from "./Base64Transforms"
|
||||
import { DatetimeTransform } from "./DatetimeTransforms"
|
||||
import { GzipCompressTransform } from "./GzipCompressTransform"
|
||||
import { GzipDecompressTransform } from "./GzipTransform"
|
||||
import { JSONBeautifyTransform, JSONEscapeTransform, JSONSimplifyTransform, JSONUnescapeTransform } from "./JSONTransforms"
|
||||
import { RegexpTransform } from "./RegexpTransform"
|
||||
import { URIDecodeTransform, URIEncodeTransform } from "./URITransforms"
|
||||
import { JSON2YAMLTransform, YAML2JSONTransform } from "./YAMLTransforms"
|
||||
import {
|
||||
Base64DecodeTransform,
|
||||
Base64EncodeTransform,
|
||||
} from './Base64Transforms'
|
||||
import { DatetimeTransform } from './DatetimeTransforms'
|
||||
import { GzipCompressTransform } from './GzipCompressTransform'
|
||||
import { GzipDecompressTransform } from './GzipTransform'
|
||||
import {
|
||||
JSONBeautifyTransform,
|
||||
JSONEscapeTransform,
|
||||
JSONSimplifyTransform,
|
||||
JSONUnescapeTransform,
|
||||
} from './JSONTransforms'
|
||||
import { RegexpTransform } from './RegexpTransform'
|
||||
import { URIDecodeTransform, URIEncodeTransform } from './URITransforms'
|
||||
import { JSON2YAMLTransform, YAML2JSONTransform } from './YAMLTransforms'
|
||||
|
||||
export interface TransformCheckboxOption {
|
||||
type: 'CHECKBOX',
|
||||
key: string,
|
||||
label?: string,
|
||||
type: 'CHECKBOX'
|
||||
key: string
|
||||
label?: string
|
||||
value?: boolean
|
||||
}
|
||||
|
||||
|
||||
export interface TransformTextboxOption {
|
||||
type: 'TEXTBOX',
|
||||
key: string,
|
||||
label?: string,
|
||||
type: 'TEXTBOX'
|
||||
key: string
|
||||
label?: string
|
||||
value?: string
|
||||
}
|
||||
|
||||
export interface TransformIntboxOption {
|
||||
type: 'INTBOX',
|
||||
key: string,
|
||||
label?: string,
|
||||
type: 'INTBOX'
|
||||
key: string
|
||||
label?: string
|
||||
value?: number
|
||||
}
|
||||
|
||||
export interface TransformRadioOption {
|
||||
type: 'RADIO',
|
||||
key: string,
|
||||
label?: string,
|
||||
value?: string,
|
||||
type: 'RADIO'
|
||||
key: string
|
||||
label?: string
|
||||
value?: string
|
||||
radios: {
|
||||
label?: string
|
||||
value: string
|
||||
}[]
|
||||
}
|
||||
|
||||
export type TransformOption =
|
||||
TransformCheckboxOption | TransformTextboxOption |
|
||||
TransformIntboxOption | TransformRadioOption
|
||||
export type TransformOption =
|
||||
| TransformCheckboxOption
|
||||
| TransformTextboxOption
|
||||
| TransformIntboxOption
|
||||
| TransformRadioOption
|
||||
|
||||
export interface Transform {
|
||||
name: string
|
||||
@ -56,10 +65,12 @@ export interface WrappedTransformResult {
|
||||
}
|
||||
|
||||
export interface WrappedTransform extends Omit<Transform, 'fn' | 'options'> {
|
||||
wrapped: true,
|
||||
wrapped: true
|
||||
|
||||
fn: (value: string, options: Map<string, TransformOption>) =>
|
||||
Promise<WrappedTransformResult>,
|
||||
fn: (
|
||||
value: string,
|
||||
options: Map<string, TransformOption>,
|
||||
) => Promise<WrappedTransformResult>
|
||||
|
||||
options: Map<string, TransformOption>
|
||||
}
|
||||
@ -68,16 +79,15 @@ export const wrapTransform = (transform: Transform): WrappedTransform => ({
|
||||
...transform,
|
||||
|
||||
fn: async (...args) =>
|
||||
await transform.fn(...args)
|
||||
.then((value) =>
|
||||
({ error: false, value: value.toString() }))
|
||||
.catch((error) =>
|
||||
({ error: true, value: error.toString() })),
|
||||
await transform
|
||||
.fn(...args)
|
||||
.then((value) => ({ error: false, value: value.toString() }))
|
||||
.catch((error) => ({ error: true, value: error.toString() })),
|
||||
|
||||
options: new Map<string, TransformOption>(
|
||||
(transform.options ?? []).map((v) => [v.key, v])
|
||||
(transform.options ?? []).map((v) => [v.key, v]),
|
||||
),
|
||||
wrapped: true
|
||||
wrapped: true,
|
||||
})
|
||||
|
||||
export const transforms: Transform[] = [
|
||||
@ -94,5 +104,5 @@ export const transforms: Transform[] = [
|
||||
JSON2YAMLTransform,
|
||||
YAML2JSONTransform,
|
||||
GzipCompressTransform,
|
||||
GzipDecompressTransform
|
||||
GzipDecompressTransform,
|
||||
]
|
||||
|
@ -1,29 +1,29 @@
|
||||
import { Transform } from "./Transform";
|
||||
import { Transform } from './Transform'
|
||||
|
||||
export const URIDecodeTransform: Transform = {
|
||||
name: 'urid',
|
||||
|
||||
fn: async (v, o) =>
|
||||
o.get('cmp')?.value === true
|
||||
? decodeURIComponent(v)
|
||||
: decodeURI(v),
|
||||
o.get('cmp')?.value === true ? decodeURIComponent(v) : decodeURI(v),
|
||||
|
||||
options: [{
|
||||
type: 'CHECKBOX',
|
||||
key: 'cmp'
|
||||
}]
|
||||
options: [
|
||||
{
|
||||
type: 'CHECKBOX',
|
||||
key: 'cmp',
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
export const URIEncodeTransform: Transform = {
|
||||
name: 'urie',
|
||||
|
||||
fn: async (v, o) =>
|
||||
o.get('cmp')?.value === true
|
||||
? encodeURIComponent(v)
|
||||
: encodeURI(v),
|
||||
|
||||
options: [{
|
||||
type: 'CHECKBOX',
|
||||
key: 'cmp'
|
||||
}]
|
||||
fn: async (v, o) =>
|
||||
o.get('cmp')?.value === true ? encodeURIComponent(v) : encodeURI(v),
|
||||
|
||||
options: [
|
||||
{
|
||||
type: 'CHECKBOX',
|
||||
key: 'cmp',
|
||||
},
|
||||
],
|
||||
}
|
||||
|
@ -1,17 +1,15 @@
|
||||
import { Transform } from "./Transform";
|
||||
import { Transform } from './Transform'
|
||||
import YAML from 'yaml'
|
||||
import JSON5 from 'json5'
|
||||
|
||||
export const YAML2JSONTransform: Transform = {
|
||||
name: 'yaml2json',
|
||||
|
||||
fn: async (v) =>
|
||||
JSON.stringify(YAML.parse(v))
|
||||
fn: async (v) => JSON.stringify(YAML.parse(v)),
|
||||
}
|
||||
|
||||
export const JSON2YAMLTransform: Transform = {
|
||||
name: 'json2yaml',
|
||||
|
||||
fn: async (v) =>
|
||||
YAML.stringify(JSON5.parse(v))
|
||||
fn: async (v) => YAML.stringify(JSON5.parse(v)),
|
||||
}
|
||||
|
@ -21,3 +21,8 @@ input[type=number] {
|
||||
appearance: textfield;
|
||||
-moz-appearance: textfield;
|
||||
}
|
||||
|
||||
*::selection {
|
||||
color: #212121;
|
||||
background-color: #ff1696;
|
||||
}
|
||||
|
3
src/vite-env.d.ts
vendored
3
src/vite-env.d.ts
vendored
@ -1,5 +1,6 @@
|
||||
/// <reference types="vite/client" />
|
||||
|
||||
module 'strtime' {
|
||||
function strptime (string, string): Date
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
function strptime(string, string): Date
|
||||
}
|
||||
|
Reference in New Issue
Block a user