Why I replaced 70 hand-rolled tools with open source (and what I kept)
There's a particular kind of developer confidence that makes you think writing everything yourself is a good idea. Sometimes it is. Other times, you're spending an afternoon implementing something that an established open-source library has already handled for years. I recently went through an open-source audit of Pocket PDF, my browser-based file tools project. The goal wasn't to replace…
Developers often believe writing everything themselves is a good idea, but sometimes utilizing established open-source libraries can save time and effort. In Pocket PDF, a browser-based file tools project, a developer recently conducted an open-source audit to identify areas where custom implementations were unnecessary. After the audit, several hand-rolled implementations were replaced while maintaining browser-native functionality that already worked efficiently.
Password strength estimation, for instance, was replaced with zxcvbn, a well-established password-strength estimator. This change provided a more accurate approach to identifying predictable password patterns compared to the custom logic previously used. The distinction here is that password strength estimation doesn't guarantee password security; it's merely a tool to help users create stronger passwords.
CSV processing was transitioned to Papa Parse, which handles parsing CSV files more effectively than a homemade string-processing solution. CSV files can contain various edge cases, such as commas inside quoted fields, escaped quotes, and inconsistent records. By using a dedicated library, developers can avoid maintaining custom logic for these complexities.
ZIP handling was moved to fflate, which addressed additional security concerns, such as archive bomb protection. Before inflating entries in a ZIP file, the application now inspects archive metadata and enforces size limits, ensuring that archives exceeding configured limits are rejected before extraction. Additionally, encrypted-entry detection was added to prevent ordinary files from being treated as decrypted entries without the required password or decryption support.
HTML entity handling was also replaced with he, a dedicated library that handles entity encoding and decoding more reliably than a custom implementation. This change ensures that developers don't have to maintain a collection of replacements and special cases, as the library takes care of the small details involved in entity handling.
However, not everything needs to be replaced with a library. In some cases, browser-native implementations like Canvas-based image operations, Web Crypto functionality, and DOM-based tools are sufficient and should be kept. This approach reduces the maintenance surface without necessarily improving the result.
The audit also revealed an unrelated issue in five tools, where the preview-resolution export behavior was broken. Despite the preview looking correct, the exported result didn't consistently respect the intended resolution. This issue was fixed during the cleanup process, highlighting that dependency audits should involve testing the complete operation, including the final output.
In conclusion, while open-source libraries can be beneficial, developers should carefully evaluate their necessity and potential security or performance implications before adding them to a project. Proper evaluation ensures that the chosen libraries enhance the project's functionality and security rather than introducing new issues.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.