cloudinary-community / cloudinary-community/cloudinary-util
[Feature] Move duplicate prop check to a test instead of runtime
- Dominant language
- TypeScript
- Stars
- 14
- Forks
- 23
- PR merge metrics
- No merged PRs in 30d
Description
# **Feature Request**
From Josh Goldberg (thanks)
> There is logic right now to assert that no two plugins declare the same prop:
```tsx
const propsCheck: string[] = [];
transformationPlugins.forEach(({ props = [] }) => {
props.forEach((prop) => {
if (propsCheck.includes(prop)) {
throw new Error(`Option ${prop} already exists!`);
}
propsCheck.push(prop);
});
});
```
> This seems reasonable. I’d suggest doing this at test time so that runtime users don’t need to run that code.
> I’d also personally lean towards a `Set` for an ever so slightly faster check (not urgent at all):
```tsx
const propsCheck = new Set()
transformationPlugins.forEach(({ props = [] }) => {
props.forEach(prop => {
if ( propsCheck.has(prop) ) {
throw new Error(`Option ${prop} already exists!`);
}
propsCheck.add(prop);
});
});
```
## Solution
Create a new test that checks all of the plugins for duplicate props. It can use the logic above to perform the check.
Then remove this check from the `constructCloudinaryUrl` function
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.