Skip to content

Commit fdb59e1

Browse files
authored
Merge branch 'dostonnabotov:main' into main
2 parents 151c71d + 1d08bb2 commit fdb59e1

File tree

3 files changed

+158
-1
lines changed

3 files changed

+158
-1
lines changed

.github/pull_request_template.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Description
2+
3+
<!-- Please include a summary of your changes. -->
4+
5+
## Type of Change
6+
7+
<!-- What kind of change does this pull request introduce? (Check all that apply) -->
8+
9+
- [ ] ✨ New snippet
10+
- [ ] 🛠 Improvement to an existing snippet
11+
- [ ] 🐞 Bug fix
12+
- [ ] 📖 Documentation update
13+
- [ ] 🔧 Other (please describe):
14+
15+
## Checklist
16+
17+
<!-- Before submitting, ensure your pull request meets these requirements: -->
18+
19+
- [ ] I have tested my code and verified it works as expected.
20+
- [ ] My code follows the style and contribution guidelines of this project.
21+
- [ ] Comments are added where necessary for clarity.
22+
- [ ] Documentation has been updated (if applicable).
23+
- [ ] There are no new warnings or errors from my changes.
24+
25+
## Related Issues
26+
27+
<!-- Link any relevant issues (use #issue-number syntax). If not, leave it empty -->
28+
29+
Closes #
30+
31+
## Additional Context
32+
33+
<!-- Add any extra details, questions, or considerations here. -->
34+
35+
## Screenshots (Optional)
36+
37+
<!-- If your changes affect visuals, please include screenshots. -->
38+
39+
<details>
40+
<summary>Click to view screenshots</summary>
41+
42+
<!-- Add your screenshots here -->
43+
44+
</details>

public/consolidated/all_snippets.json

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,62 @@
563563
"utility"
564564
],
565565
"author": "realvishalrana"
566+
},
567+
{
568+
"title": "Check if String is a Palindrome",
569+
"description": "Checks whether a given string is a palindrome.",
570+
"code": [
571+
"function isPalindrome(str) {",
572+
" const cleanStr = str.replace(/[^a-zA-Z0-9]/g, '').toLowerCase();",
573+
" return cleanStr === cleanStr.split('').reverse().join('');",
574+
"}",
575+
"",
576+
"// Example usage:",
577+
"console.log(isPalindrome('A man, a plan, a canal, Panama')); // Output: true"
578+
],
579+
"tags": [
580+
"javascript",
581+
"check",
582+
"palindrome",
583+
"string"
584+
],
585+
"author": "axorax"
586+
},
587+
{
588+
"title": "Count Words in a String",
589+
"description": "Counts the number of words in a string.",
590+
"code": [
591+
"function countWords(str) {",
592+
" return str.trim().split(/\\s+/).length;",
593+
"}",
594+
"",
595+
"// Example usage:",
596+
"console.log(countWords('Hello world! This is a test.')); // Output: 6"
597+
],
598+
"tags": [
599+
"string",
600+
"manipulation",
601+
"word count",
602+
"count"
603+
],
604+
"author": "axorax"
605+
},
606+
{
607+
"title": "Remove All Whitespace",
608+
"description": "Removes all whitespace from a string.",
609+
"code": [
610+
"function removeWhitespace(str) {",
611+
" return str.replace(/\\s+/g, '');",
612+
"}",
613+
"",
614+
"// Example usage:",
615+
"console.log(removeWhitespace('Hello world!')); // Output: 'Helloworld!'"
616+
],
617+
"tags": [
618+
"string",
619+
"whitespace"
620+
],
621+
"author": "axorax"
566622
}
567623
]
568624
},
@@ -820,6 +876,37 @@
820876
"performance"
821877
],
822878
"author": "dostonnabotov"
879+
},
880+
{
881+
"title": "Get Contrast Color",
882+
"description": "Returns either black or white text color based on the brightness of the provided hex color.",
883+
"code": [
884+
"const getContrastColor = (hexColor) => {",
885+
" // Expand short hex color to full format",
886+
" if (hexColor.length === 4) {",
887+
" hexColor = `#${hexColor[1]}${hexColor[1]}${hexColor[2]}${hexColor[2]}${hexColor[3]}${hexColor[3]}`;",
888+
" }",
889+
" const r = parseInt(hexColor.slice(1, 3), 16);",
890+
" const g = parseInt(hexColor.slice(3, 5), 16);",
891+
" const b = parseInt(hexColor.slice(5, 7), 16);",
892+
" const brightness = (r * 299 + g * 587 + b * 114) / 1000;",
893+
" return brightness >= 128 ? \"#000000\" : \"#FFFFFF\";",
894+
"};",
895+
"",
896+
"// Usage:",
897+
"console.log(getContrastColor('#fff')); // Output: #000000 (black)",
898+
"console.log(getContrastColor('#123456')); // Output: #FFFFFF (white)",
899+
"console.log(getContrastColor('#ff6347')); // Output: #000000 (black)",
900+
"console.log(getContrastColor('#f4f')); // Output: #000000 (black)"
901+
],
902+
"tags": [
903+
"color",
904+
"hex",
905+
"contrast",
906+
"brightness",
907+
"utility"
908+
],
909+
"author": "yaya12085"
823910
}
824911
]
825912
},

public/data/javascript.json

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,33 @@
488488
],
489489
"tags": ["javascript", "utility", "throttle", "performance"],
490490
"author": "dostonnabotov"
491-
}
491+
},
492+
{
493+
"title": "Get Contrast Color",
494+
"description": "Returns either black or white text color based on the brightness of the provided hex color.",
495+
"code": [
496+
"const getContrastColor = (hexColor) => {",
497+
" // Expand short hex color to full format",
498+
" if (hexColor.length === 4) {",
499+
" hexColor = `#${hexColor[1]}${hexColor[1]}${hexColor[2]}${hexColor[2]}${hexColor[3]}${hexColor[3]}`;",
500+
" }",
501+
" const r = parseInt(hexColor.slice(1, 3), 16);",
502+
" const g = parseInt(hexColor.slice(3, 5), 16);",
503+
" const b = parseInt(hexColor.slice(5, 7), 16);",
504+
" const brightness = (r * 299 + g * 587 + b * 114) / 1000;",
505+
" return brightness >= 128 ? \"#000000\" : \"#FFFFFF\";",
506+
"};",
507+
"",
508+
"// Usage:",
509+
"console.log(getContrastColor('#fff')); // Output: #000000 (black)",
510+
"console.log(getContrastColor('#123456')); // Output: #FFFFFF (white)",
511+
"console.log(getContrastColor('#ff6347')); // Output: #000000 (black)",
512+
"console.log(getContrastColor('#f4f')); // Output: #000000 (black)"
513+
],
514+
"tags": ["color", "hex", "contrast", "brightness", "utility"],
515+
"author": "yaya12085"
516+
}
517+
492518
]
493519
},
494520
{

0 commit comments

Comments
 (0)