Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Snippets] Added 20 new JavaScript snippets across multiple categories #229

Closed
wants to merge 9 commits into from

Conversation

JanluOfficial
Copy link
Contributor

Description

Added 20 new code snippets for JavaScript across 6 categories.

Validation

  • Email Validation
  • Phone Number Validation (US)
  • Phone Number Validation (International)
  • URL Validation
  • Credit card number validation

Color Manipulation

  • Hex to HSL Color
  • HSL to Hex Color
  • Random Hex Color
  • Random HSL Color
  • Random RGB Color

Local Storage

  • Clear all items from localStorage
  • Get all keys from localStorage
  • Update item in localStorage

DOM Manipulation

  • Add CSS Class to an Element
  • Remove CSS Class from an Element
  • Toggle a CSS Class on an Element
  • Get computed style from an Element

Array Manipulation

  • Combine Arrays
  • Union Arrays

Object Manipulation

  • Combine Objects

Type of Change

  • ✨ New snippet
  • 🛠 Improvement to an existing snippet
  • 🐞 Bug fix
  • 📖 Documentation update
  • 🔧 Other (please describe):

Checklist

  • I have tested my code and verified it works as expected.
  • My code follows the style and contribution guidelines of this project.
  • Comments are added where necessary for clarity.
  • Documentation has been updated (if applicable).
  • There are no new warnings or errors from my changes.

Related Issues

None

Additional Context

I tried to cram a lot into this one because I want to help out a lot. I will probably make something for different languages soon though, so be on the look out.


```js
function combineArrays(array1, array2) {
return array1.concat(array2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This snippet does not quite align with QuickSnip guidelines, as is simply a wrapper for a standard library of JS

Copy link
Contributor Author

@JanluOfficial JanluOfficial Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove this one if requested by a reviewer with write access

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ACR1209 i right, this doesn't align at all with quicksnip guidelines, Please read them it's something that's written in them

```js
function addClass(element, className) {
if (element && className) {
element.classList.add(className);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The classList.add() method already does the intended functionality you're presenting

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typing element.classList.add() is longer than addClass() which is why I'm including it this way

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get it! 💯

This is the same as my response on .remove(), so we could just keep the thread there if you'll like as is an interesting boundary to comment on 😀

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Snippet shouldn't wrap around an std functionality, even if the function name is 10x longer, Also valid for the .remove() one too

```js
function removeClass(element, className) {
if (element && className) {
element.classList.remove(className);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The classList.remove() method already does the intended functionality you're presenting

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typing element.classList.remove() is longer than removeClass() which is why I'm including it this way

Copy link
Contributor

@ACR1209 ACR1209 Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand your point 💯

But at the end of the day, is a difference of 4 characters and removes the option of multi argument class removal. Plus adds a bit more bloat to the code base.

This was common with IE10 as it did throw errors

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as for add-a-css-class-to-an-element.

---

```js
localStorage.clear();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is simply a usage of a language standard function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I included this considering that C:\xampp\htdocs\quicksnip\snippets\javascript\basics\hello-world.md is essentially also just a standard language function

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you're definitely right on that, hello worlds are a kinda of the exception to the rule I think.

But for the rest of snippets we do consider the contributing guidelines "Does the standard library of my language provide an easy way of doing this ?" boundary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If requested by a reviewer with write access, I will remove this

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACR is right, Btw I've noticed you are not taking feedback from the community Even when it's backed by the guidelines, The community has an important role into the reviewing process, please take them a bit more into account.

Hello world, is infact a specific snippet, and it should be (in most cases) the only one of it's "type", so no, as per the guidelines, this doesn't qualify as a snippet

@Mcbencrafter
Copy link
Contributor

I think the validation snippets would be better placed under the regex category

Copy link
Collaborator

@Mathys-Gasnier Mathys-Gasnier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution, please take a look at my feedbacks bellow.

I've noticed some other issues:

  • all of the stuff in the validation category doesn't really belong here, and fits more the scope of the regex language.
  • You've created lots of snippets that just wrap over something an std function, your argument of length of call isn't really something we take into account.

Please take into account feedback of the community, and avoid responding "Waiting for a write access reviewer to confirm". Yes we have the "final" say in what to do or not do, but when the feedback is backed by the guidelines take it into account


```js
function combineArrays(array1, array2) {
return array1.concat(array2);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ACR1209 i right, this doesn't align at all with quicksnip guidelines, Please read them it's something that's written in them

```js
function addClass(element, className) {
if (element && className) {
element.classList.add(className);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Snippet shouldn't wrap around an std functionality, even if the function name is 10x longer, Also valid for the .remove() one too

```js
function removeClass(element, className) {
if (element && className) {
element.classList.remove(className);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as for add-a-css-class-to-an-element.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as add-a-css-class-to-an-element

---

```js
localStorage.clear();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACR is right, Btw I've noticed you are not taking feedback from the community Even when it's backed by the guidelines, The community has an important role into the reviewing process, please take them a bit more into account.

Hello world, is infact a specific snippet, and it should be (in most cases) the only one of it's "type", so no, as per the guidelines, this doesn't qualify as a snippet

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as for the others, it just wraps over an std function, it adds a little bit of functionnality over it... But this functionnality isn't the main goal of the snippet, so in it's current state it's not valid

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already exists as merge-objects-deeply

@JanluOfficial
Copy link
Contributor Author

Closed, will make a different pr at a later date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants