Skip to content

Commit

Permalink
Merge branch 'main' into feature/hash-generator
Browse files Browse the repository at this point in the history
  • Loading branch information
EduardoDePatta committed Sep 30, 2024
2 parents 55c1265 + 316e53c commit 6e264e2
Show file tree
Hide file tree
Showing 40 changed files with 2,757 additions and 605 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20.9.0
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ Here is the list of all utilities:
- [Number Base Changer](https://jam.dev/utilities/number-base-changer)
- [CSS Inliner for Email](https://jam.dev/utilities/css-inliner-for-email)
- [Regex Tester](https://jam.dev/utilities/regex-tester)
- [Image Resizer](https://jam.dev/utilities/image-resizer)
- [CSS Units Converter](https://jam.dev/utilities/css-units-converter)
- [JWT Parser](https://jam.dev/utilities/jwt-parser)

### Built With

Expand Down Expand Up @@ -78,6 +81,14 @@ Navigate to the project directory:
cd jam-dev-utilities
```

For macOS users with ARM architecture (M series processors), it's crucial to install these dependencies using `brew` to ensure full compatibility with the `node-canvas` library. This step is essential to prevent potential failures during the `npm install` process.

If you don't have Homebrew installed, you can find it at [brew.sh](https://brew.sh/)

```bash
brew install pkg-config cairo pango libpng jpeg giflib librsvg pixman python-setuptools
```

Install the dependencies:

```bash
Expand Down
14 changes: 14 additions & 0 deletions components/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Link from "next/link";
import { ThemeToggle } from "./ThemeToggle";
import { Button } from "./ds/ButtonComponent";
import { GitHubLogoIcon } from "@radix-ui/react-icons";

export default function Header() {
return (
Expand All @@ -13,6 +14,19 @@ export default function Header() {

<div className="flex gap-3">
<ThemeToggle />
<Button
className="min-h-10 flex px-2 sm:px-4 min-w-10 sm:min-w-auto"
variant="outline"
onClick={() =>
window.open(
"https://github.com/jamdotdev/jam-dev-utilities",
"_blank"
)
}
>
<span className="mr-2 hidden sm:inline">Contribute</span>
<GitHubLogoIcon />
</Button>
<Button
className="min-h-10 flex"
variant="outline"
Expand Down
16 changes: 8 additions & 8 deletions components/ds/ComboboxComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@ import {
interface ComboboxProps {
data: { value: string; label: string }[];
onSelect(value: string): void;
defaultValue?: string;
value?: string;
disabled?: boolean;
}

export function Combobox(props: ComboboxProps) {
const [open, setOpen] = useState(false);
const [value, setValue] = useState(props.defaultValue || "");
const selectedItem = props.data.find((item) => item.value === value);
const selectedItem = props.data.find((item) => item.value === props.value);

const setNewValue = (value: string) => {
setValue(value);
setOpen(false);
props.onSelect(value);
};
Expand All @@ -38,16 +37,17 @@ export function Combobox(props: ComboboxProps) {
role="combobox"
aria-expanded={open}
className="justify-between"
disabled={props.disabled}
>
{selectedItem ? selectedItem.label : "Select base..."}
{selectedItem ? selectedItem.label : "Select..."}
<CaretSortIcon className="ml-2 h-4 w-4 shrink-0 opacity-50" />
</Button>
</PopoverTrigger>
<PopoverContent className="p-0 h-auto">
<Command>
<CommandInput placeholder="Search base..." />
<CommandInput placeholder="Search..." />
<CommandList className="h-auto">
<CommandEmpty>Base not found.</CommandEmpty>
<CommandEmpty>Nothing to see here.</CommandEmpty>
<CommandGroup>
{props.data.map((item) => (
<CommandItem
Expand All @@ -59,7 +59,7 @@ export function Combobox(props: ComboboxProps) {
<CheckIcon
className={cn(
"ml-auto h-4 w-4",
value === item.value ? "opacity-100" : "opacity-0"
props.value === item.value ? "opacity-100" : "opacity-0"
)}
/>
</CommandItem>
Expand Down
133 changes: 133 additions & 0 deletions components/ds/ImageUploadComponent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
"use client";
import { DragEvent, useCallback, useMemo, useRef, useState } from "react";
import UploadIcon from "@/components/icons/UploadIcon";

type Status = "idle" | "loading" | "error" | "unsupported" | "hover";

const MAX_FILE_SIZE = 4 * 1024 * 1024;
interface ImageUploadProps {
onFileSelect: (file: File) => void;
maxFileSize?: number;
}

const ImageUploadComponent = ({
onFileSelect,
maxFileSize = MAX_FILE_SIZE,
}: ImageUploadProps) => {
const [status, setStatus] = useState<Status>("idle");
const inputRef = useRef<HTMLInputElement>(null);

const formattedMaxSize = useMemo((): string => {
const sizeInMB = maxFileSize / (1024 * 1024);
return Number.isInteger(sizeInMB)
? `${sizeInMB}MB`
: `${sizeInMB.toFixed(2)}MB`;
}, [maxFileSize]);

const handleDrop = useCallback(
(event: DragEvent<HTMLDivElement>) => {
event.preventDefault();

const file = event.dataTransfer.files[0];
if (!file || !file.type.startsWith("image/")) {
setStatus("unsupported");
return;
}

if (file.size > maxFileSize) {
setStatus("error");
return;
}

setStatus("loading");
onFileSelect(file);
setStatus("idle");
},
[onFileSelect, maxFileSize]
);

const handleDragOver = useCallback(
(event: React.DragEvent<HTMLDivElement>) => {
event.preventDefault();
setStatus("hover");
},
[]
);

const handleDragLeave = useCallback(() => {
setStatus("idle");
}, []);

const handleClick = () => {
inputRef.current?.click();
};

const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const file = event.target.files?.[0];
if (file) {
if (!file.type.startsWith("image/")) {
setStatus("unsupported");
return;
}

if (file.size > maxFileSize) {
setStatus("error");
return;
}

setStatus("loading");
onFileSelect(file);
setStatus("idle");
}
};

return (
<div
onDrop={handleDrop}
onDragOver={handleDragOver}
onDragLeave={handleDragLeave}
onClick={handleClick}
className="flex flex-col border border-dashed border-border p-6 text-center text-muted-foreground rounded-lg min-h-40 items-center justify-center bg-muted cursor-pointer mb-2"
>
<input
ref={inputRef}
type="file"
accept="image/*"
className="hidden"
onChange={handleFileChange}
/>
<UploadIcon />
{statusComponents[status](formattedMaxSize)}
</div>
);
};

const StatusComponent = ({
title,
message,
}: {
title: string;
message?: string;
}) => (
<div>
<p>{title}</p>
<p>{message || "\u00A0"}</p>
</div>
);

const statusComponents: Record<Status, (maxSize: string) => JSX.Element> = {
idle: (maxSize) => (
<StatusComponent
title="Drag and drop your image here, or click to select"
message={`Max size ${maxSize}`}
/>
),
loading: () => <StatusComponent title="Loading..." />,
error: (maxSize) => (
<StatusComponent title="Image is too big!" message={`${maxSize} max`} />
),
unsupported: () => <StatusComponent title="Please provide a valid image" />,
hover: () => <StatusComponent title="Drop it like it's hot! 🔥" />,
};

export { ImageUploadComponent };
85 changes: 45 additions & 40 deletions components/seo/Base64SEO.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,56 @@
import Link from "next/link";
import CodeExample from "../CodeExample";
import GetJamForFree from "./GetJamForFree";

export default function Base64SEO() {
return (
<div className="content-wrapper">
<section>
<h2>Free, Open Source & Ad-free</h2>
<p>
Effortlessly encode and decode text or files to and from Base64 format
with this free tool. Safe data transmission and storage in a
web-friendly text format. Made with 💜 by the developers building Jam.
Use this free Base64 encoder and decoder to easily convert between
plain text and Base64-encoded strings. This tool is perfect for
decoding API responses. No need to sign up — just paste your data and
convert instantly. Made with 💜 by the developers building Jam.
</p>
</section>

<section>
<h2>How to Use Jam's Base64 Decode Tool:</h2>
<h2>How to Use the Base64 Decode Tool:</h2>
<p>
Paste your text and copy the result. Works for Base64 to image, Base64
to text, encoded strings, and decoding text strings back to their
original binary string.
You can use this tool to decode Base64-encoded strings, or to convert
Base64 text strings back to their original binary string. Just paste
your data and copy the result. If you need to convert images to Base64
you can use this{" "}
<Link
href="/utilities/image-to-base64"
target="_blank"
rel="noopener noreferrer"
>
tool
</Link>
.
</p>

<p>Use Cases:</p>
<ul>
<li>
Data Conversion: Convert text strings to their original binary form,
useful for handling encoded text data.
</li>
<li>
Debugging: Decode Base64 data when troubleshooting or analyzing web
resources.
</li>
</ul>
</section>

<section>
<h2>Why Encode Data?</h2>
<h2>How Does the Base64 Tool Work?</h2>
<p>
Base64 encoding converts binary data, such as images or files, into a
text format that can be safely transmitted over text-based protocols
like HTTP, email, and more. This process ensures that the data remains
intact and prevents corruption during transmission.
Base64 encoding converts binary string into a text format that can be
safely transmitted over text-based protocols like HTTP, email, and
more. This process ensures that the data remains intact and prevents
corruption during transmission.
</p>
<ul>
<li>
Expand All @@ -46,10 +68,6 @@ export default function Base64SEO() {
exchange between different systems and platforms that handle
text-based data.
</li>
<li>
<b>Text to Binary Conversion:</b> <br /> Converts text strings to
their original binary form, useful for handling encoded text data.
</li>
<li>
<b>ASCII Decoding:</b> <br /> Converts ASCII strings back to their
original binary form, ensuring accurate data reconstruction.
Expand All @@ -72,7 +90,7 @@ export default function Base64SEO() {
</section>

<section>
<h2>Discover Jam: The Ultimate Tool for Web Developers</h2>
<h2>Meet Jam: The Ultimate Tool for Debugging Web Apps</h2>
<p>
While this tool helps you manage encoding and decoding efficiently,{" "}
<a href="https://jam.dev?ref=utils" target="_blank" rel="noreferrer">
Expand All @@ -81,23 +99,24 @@ export default function Base64SEO() {
takes your debugging process to the next level.
</p>
<p>
Meet{" "}
Jam is{" "}
<a
href="https://chromewebstore.google.com/detail/jam/iohjgamcilhbgmhbnllfolmkmmekfmci"
target="_blank"
rel="noreferrer"
>
Jam, the browser extension
the browser extension
</a>{" "}
helping over 130,000 users debug faster. Jam captures console logs,
helping over 140,000 users debug faster. It captures console logs,
network requests, and more with just one click. Now anyone can log
comprehensive bug reports and you can debug so much faster.
comprehensive bug reports and you can debug so much faster without
having to follow up.
</p>
<p>
No more guesswork—just clear, actionable data that helps you identify
and fix issues without having to follow up. Whether you're dealing
with Base64-encoded data, debugging JavaScript functions, or ensuring
data integrity in your web applications, Jam is here to help.
Whether you're dealing with Base64-encoded data or debugging
JavaScript functions in your web applications, you can use Jam to
capture your screen and it automatically includes all the debug
details developers need to fix issues in a shareable link.
</p>
</section>

Expand All @@ -108,11 +127,6 @@ export default function Base64SEO() {
<section>
<h2>FAQs:</h2>
<ul>
<li>
<b>What is a Base64 encoder and decoder?</b> <br /> It's a tool that
converts binary data into a text format, while a decoder converts
text back to its original binary format.
</li>
<li>
<b>Can you decode Base64?</b> <br /> Yes, you can. Use this tool to
decode online by pasting the text into the input box and copying the
Expand All @@ -133,21 +147,12 @@ export default function Base64SEO() {
In a few seconds, you'll be effectively converting the characters to
a web-safe format.
</li>
<li>
<b>How to decode Base64 text online?</b> <br /> Use our online tool
by pasting the Base64 encoded text into the input box and copying
the decoded output.
</li>
<li>
<b>What is Base64?</b> <br /> It's an encoding scheme used to
convert binary data into a text format that can be safely
transmitted over the internet, using a combination of ASCII
characters.
</li>
<li>
<b>Can I use this tool for files?</b> <br /> Yes, our tool works for
files and text making it useful for web applications and APIs.
</li>
<li>
<b>What is the difference between encoding and decoding?</b> <br />{" "}
Encoding converts binary data to Base64 text format, while decoding
Expand Down
Loading

0 comments on commit 6e264e2

Please sign in to comment.