Chore: extract string literals into constants for better code quality
Closed this issue · 3 comments
gatsby-remark-embedder
version: 1.3.3node
version: latestnpm
(oryarn
) version: latest
Relevant code or config
export const shouldTransform = url => {
const { host, pathname, searchParams } = new URL(url);
return (
host === 'youtu.be' ||
((host === 'youtube.com' || host === 'www.youtube.com') &&
pathname.includes('/watch') &&
Boolean(searchParams.get('v')))
);
};
What you did: I want to extract the string literals to reusable constants for better maintenability.
What happened: this is a chore, not a bug.
Reproduction repository:
Problem description: Currently, if one of the supported embeds have a change in url or part of the url, the plugin may break. To mitigate this, we can have such high severity strings into constants that can be updated in a single place.
Suggested solution: Create a src/utils/constants.js
file to have all the string literals and all other files should refer to this file for those constant literals.
Hi @ChaituKNag!
Thanks for your suggestion, but I'm not really seeing any benefit of pulling out every string variable into a new constants.js
file tbh.
If there needs to be a change, we can just change it in the corresponding transformer, no? 🤔
Please explain what I'm missing in your opinion.
Yeah, for a finite bunch of transformers, I believe that should not be a problem.
@ChaituKNag The purpose is to support as much services as possible.
So if you think your idea would make that easier in the future, I'm glad to hear more about your idea. 🙂