feat: Add lightweight Node.js document shim and enhance type checking guards #186
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR makes two primary improvements to the CookieStore polyfill:
1. Node.js Compatibility:
• Introduces a lightweight shim for the document object to support environments (like Node.js) where a native document is missing.
• The shim creates a minimal document with a mutable cookie property, allowing the polyfill to operate outside of browser contexts without breaking existing behavior.
2. Enhanced Type Checking:
• Improves type checking guards across the codebase by using helper functions (e.g., isString, isNumber, isNullish, etc.).
• These changes ensure more robust input validation and better error handling without affecting the current API.
Motivation and Benefits:
• Cross-Environment Support:
Developers can now use the CookieStore polyfill seamlessly in both browser and Node.js environments.
• Code Reliability:
The enhanced type guards reduce the risk of runtime errors, making the polyfill more resilient and easier to maintain.
Testing and Backwards Compatibility:
• All changes have been tested to ensure that the polyfill works as expected in environments with a native document as well as in Node.js.
• Existing functionality remains unchanged, preserving backward compatibility.
Please let me know if there are any questions or further adjustments needed.