Skip to content

Commit 0e252c6

Browse files
committed
222: add contributors field on snippet
1 parent a50a47e commit 0e252c6

File tree

4 files changed

+44
-18
lines changed

4 files changed

+44
-18
lines changed

public/consolidated/javascript.json

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,18 @@
109109
"description": "Converts RGB color values to hexadecimal color code.",
110110
"author": "jjcantu",
111111
"tags": [
112-
"javascript",
113112
"color",
114-
"conversion",
115-
"utility"
113+
"conversion"
116114
],
117-
"contributors": [],
118-
"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"
115+
"contributors": [
116+
"jjcantu",
117+
"jjcantu",
118+
"jjcantu",
119+
"jjcantu",
120+
"jjcantu",
121+
"jjcantu"
122+
],
123+
"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"
119124
}
120125
]
121126
},
@@ -570,10 +575,8 @@
570575
"description": "Converts bytes into human-readable file size format.",
571576
"author": "jjcantu",
572577
"tags": [
573-
"javascript",
574578
"format",
575-
"size",
576-
"utility"
579+
"size"
577580
],
578581
"contributors": [],
579582
"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 @@
692695
"description": "Creates a deep copy of an object or array without reference.",
693696
"author": "jjcantu",
694697
"tags": [
695-
"javascript",
696698
"object",
697-
"clone",
698-
"utility"
699+
"clone"
699700
],
700701
"contributors": [],
701-
"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"
702+
"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"
702703
},
703704
{
704705
"title": "Filter Object",
@@ -979,9 +980,9 @@
979980
"description": "Generates a UUID (v4) string.",
980981
"author": "jjcantu",
981982
"tags": [
982-
"javascript",
983983
"uuid",
984-
"utility"
984+
"generate",
985+
"string"
985986
],
986987
"contributors": [],
987988
"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"

snippets/javascript/color-manipulation/rgb-to-hex.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ tags: javascript,color,conversion,utility
99
function rgbToHex(r, g, b) {
1010
const toHex = (n) => {
1111
const hex = n.toString(16);
12-
return hex.length === 1 ? '0' + hex : hex;
12+
return hex.length === 1 ? "0" + hex : hex;
1313
};
14-
15-
return '#' + toHex(r) + toHex(g) + toHex(b);
14+
15+
return "#" + toHex(r) + toHex(g) + toHex(b);
1616
}
1717

1818
// Usage:

src/components/SnippetModal.tsx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const SnippetModal: React.FC<Props> = ({
6464
{snippet.description}
6565
</p>
6666
<p>
67-
Contributed by{" "}
67+
Created by{" "}
6868
<a
6969
href={`https://github.com/${snippet.author}`}
7070
target="_blank"
@@ -74,6 +74,30 @@ const SnippetModal: React.FC<Props> = ({
7474
@{snippet.author}
7575
</a>
7676
</p>
77+
{(snippet.contributors ?? []).length > 0 && (
78+
<div className="contributors">
79+
<span>Contributors: </span>
80+
{snippet.contributors
81+
?.slice(0, 3)
82+
.map((contributor, index, slicedArray) => (
83+
<>
84+
<a
85+
key={contributor}
86+
href={`https://github.com/${contributor}`}
87+
target="_blank"
88+
rel="noopener noreferrer"
89+
className="styled-link"
90+
>
91+
@{contributor}
92+
</a>
93+
{index < slicedArray.length - 1 && ", "}
94+
</>
95+
))}
96+
{(snippet.contributors?.length ?? 0) > 3 && (
97+
<span> & {snippet.contributors!.length - 3} more</span>
98+
)}
99+
</div>
100+
)}
77101
<ul role="list" className="modal__tags">
78102
{snippet.tags.map((tag) => (
79103
<li key={tag} className="modal__tag">

src/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export type SnippetType = {
1414
code: string;
1515
tags: string[];
1616
author: string;
17+
contributors?: string[];
1718
};
1819

1920
export type AppState = {

0 commit comments

Comments
 (0)