From 0e252c6615fa38b63c03cf666b808dcb8745bcf8 Mon Sep 17 00:00:00 2001
From: Jose Cantu
Date: Sun, 12 Jan 2025 00:23:45 -0600
Subject: [PATCH 1/2] 222: add contributors field on snippet
---
public/consolidated/javascript.json | 29 ++++++++++---------
.../color-manipulation/rgb-to-hex.md | 6 ++--
src/components/SnippetModal.tsx | 26 ++++++++++++++++-
src/types/index.ts | 1 +
4 files changed, 44 insertions(+), 18 deletions(-)
diff --git a/public/consolidated/javascript.json b/public/consolidated/javascript.json
index e800f749..2bb47089 100644
--- a/public/consolidated/javascript.json
+++ b/public/consolidated/javascript.json
@@ -109,13 +109,18 @@
"description": "Converts RGB color values to hexadecimal color code.",
"author": "jjcantu",
"tags": [
- "javascript",
"color",
- "conversion",
- "utility"
+ "conversion"
],
- "contributors": [],
- "code": "function rgbToHex(r, g, b) {\n const toHex = (n) => {\n const hex = n.toString(16);\n return hex.length === 1 ? '0' + hex : hex;\n };\n \n return '#' + toHex(r) + toHex(g) + toHex(b);\n}\n\n// Usage:\nconsole.log(rgbToHex(255, 128, 0)); // Output: \"#ff8000\"\nconsole.log(rgbToHex(0, 255, 0)); // Output: \"#00ff00\"\n"
+ "contributors": [
+ "jjcantu",
+ "jjcantu",
+ "jjcantu",
+ "jjcantu",
+ "jjcantu",
+ "jjcantu"
+ ],
+ "code": "function rgbToHex(r, g, b) {\n const toHex = (n) => {\n const hex = n.toString(16);\n return hex.length === 1 ? \"0\" + hex : hex;\n };\n\n return \"#\" + toHex(r) + toHex(g) + toHex(b);\n}\n\n// Usage:\nconsole.log(rgbToHex(255, 128, 0)); // Output: \"#ff8000\"\nconsole.log(rgbToHex(0, 255, 0)); // Output: \"#00ff00\"\n"
}
]
},
@@ -570,10 +575,8 @@
"description": "Converts bytes into human-readable file size format.",
"author": "jjcantu",
"tags": [
- "javascript",
"format",
- "size",
- "utility"
+ "size"
],
"contributors": [],
"code": "function formatFileSize(bytes) {\n if (bytes === 0) return '0 Bytes';\n \n const k = 1024;\n const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];\n const i = Math.floor(Math.log(bytes) / Math.log(k));\n \n return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];\n}\n\n// Usage:\nconsole.log(formatFileSize(1234)); // Output: \"1.21 KB\"\nconsole.log(formatFileSize(1234567)); // Output: \"1.18 MB\"\n"
@@ -692,13 +695,11 @@
"description": "Creates a deep copy of an object or array without reference.",
"author": "jjcantu",
"tags": [
- "javascript",
"object",
- "clone",
- "utility"
+ "clone"
],
"contributors": [],
- "code": "function deepClone(obj) {\n if (obj === null || typeof obj !== 'object') return obj;\n \n const clone = Array.isArray(obj) ? [] : {};\n \n for (let key in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n clone[key] = deepClone(obj[key]);\n }\n }\n \n return clone;\n}\n\n// Usage:\nconst original = { a: 1, b: { c: 2 }, d: [1, 2, 3] };\nconst cloned = deepClone(original);\nconsole.log(cloned); // Output: { a: 1, b: { c: 2 }, d: [1, 2, 3] }\n"
+ "code": "function deepClone(obj) {\n if (obj === null || typeof obj !== 'object') return obj;\n \n const clone = Array.isArray(obj) ? [] : {};\n \n for (let key in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n clone[key] = deepClone(obj[key]);\n }\n }\n \n return clone;\n}\n\n// Usage:\nconst original = { a: 1, b: { c: 2 }, d: [1, 2, 3] };\nconst cloned = deepClone(original);\nconsole.log(cloned); // Output: 'original' but cloned\n"
},
{
"title": "Filter Object",
@@ -979,9 +980,9 @@
"description": "Generates a UUID (v4) string.",
"author": "jjcantu",
"tags": [
- "javascript",
"uuid",
- "utility"
+ "generate",
+ "string"
],
"contributors": [],
"code": "function generateUUID() {\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {\n const r = Math.random() * 16 | 0;\n const v = c === 'x' ? r : (r & 0x3 | 0x8);\n return v.toString(16);\n });\n}\n\n// Usage:\nconsole.log(generateUUID()); // Output: \"a1b2c3d4-e5f6-4g7h-8i9j-k0l1m2n3o4p5\"\n"
diff --git a/snippets/javascript/color-manipulation/rgb-to-hex.md b/snippets/javascript/color-manipulation/rgb-to-hex.md
index c232727e..f17ba6cb 100644
--- a/snippets/javascript/color-manipulation/rgb-to-hex.md
+++ b/snippets/javascript/color-manipulation/rgb-to-hex.md
@@ -9,10 +9,10 @@ tags: javascript,color,conversion,utility
function rgbToHex(r, g, b) {
const toHex = (n) => {
const hex = n.toString(16);
- return hex.length === 1 ? '0' + hex : hex;
+ return hex.length === 1 ? "0" + hex : hex;
};
-
- return '#' + toHex(r) + toHex(g) + toHex(b);
+
+ return "#" + toHex(r) + toHex(g) + toHex(b);
}
// Usage:
diff --git a/src/components/SnippetModal.tsx b/src/components/SnippetModal.tsx
index b5e2379e..92183333 100644
--- a/src/components/SnippetModal.tsx
+++ b/src/components/SnippetModal.tsx
@@ -64,7 +64,7 @@ const SnippetModal: React.FC = ({
{snippet.description}
- Contributed by{" "}
+ Created by{" "}
= ({
@{snippet.author}
+ {(snippet.contributors ?? []).length > 0 && (
+
+
Contributors:
+ {snippet.contributors
+ ?.slice(0, 3)
+ .map((contributor, index, slicedArray) => (
+ <>
+
+ @{contributor}
+
+ {index < slicedArray.length - 1 && ", "}
+ >
+ ))}
+ {(snippet.contributors?.length ?? 0) > 3 && (
+
& {snippet.contributors!.length - 3} more
+ )}
+
+ )}
{snippet.tags.map((tag) => (
-
diff --git a/src/types/index.ts b/src/types/index.ts
index b4eac550..535dbfc2 100644
--- a/src/types/index.ts
+++ b/src/types/index.ts
@@ -14,6 +14,7 @@ export type SnippetType = {
code: string;
tags: string[];
author: string;
+ contributors?: string[];
};
export type AppState = {
From c4829744103016450f57f544cc4be32825fbb03e Mon Sep 17 00:00:00 2001
From: Jose Cantu
Date: Sun, 12 Jan 2025 00:40:41 -0600
Subject: [PATCH 2/2] revert overwritten changes
---
src/components/SnippetModal.tsx | 96 +++++++++++++++++----------------
1 file changed, 49 insertions(+), 47 deletions(-)
diff --git a/src/components/SnippetModal.tsx b/src/components/SnippetModal.tsx
index 43fc4cb4..ee5133a1 100644
--- a/src/components/SnippetModal.tsx
+++ b/src/components/SnippetModal.tsx
@@ -61,53 +61,55 @@ const SnippetModal: React.FC = ({
-
-
- Description:
- {snippet.description}
-
-
- Created by{" "}
-
- @{snippet.author}
-
-
- {(snippet.contributors ?? []).length > 0 && (
-
-
Contributors:
- {snippet.contributors
- ?.slice(0, 3)
- .map((contributor, index, slicedArray) => (
- <>
-
- @{contributor}
-
- {index < slicedArray.length - 1 && ", "}
- >
- ))}
- {(snippet.contributors?.length ?? 0) > 3 && (
-
& {snippet.contributors!.length - 3} more
- )}
-
- )}
-
- {snippet.tags.map((tag) => (
- -
- {tag}
-
- ))}
-
+
+
+
+ Description:
+ {snippet.description}
+
+
+ Created by{" "}
+
+ @{snippet.author}
+
+
+ {(snippet.contributors ?? []).length > 0 && (
+
+
Contributors:
+ {snippet.contributors
+ ?.slice(0, 3)
+ .map((contributor, index, slicedArray) => (
+ <>
+
+ @{contributor}
+
+ {index < slicedArray.length - 1 && ", "}
+ >
+ ))}
+ {(snippet.contributors?.length ?? 0) > 3 && (
+
& {snippet.contributors!.length - 3} more
+ )}
+
+ )}
+
+ {snippet.tags.map((tag) => (
+ -
+ {tag}
+
+ ))}
+
+
,
modalRoot