Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Prefer URL.href over URL.toString()
Read the serialized string from a URL object via .href instead of calling .toString(); it is shorter and reads as a property, not a conversion.
Bad example
| 1 | const href = new URL(pathOrUrl, baseUrl).toString(); |
Explanation (EN)
Calling .toString() is a verbose conversion when the URL object already exposes the serialized value as a property.
Objašnjenje (HR)
Pozivanje .toString() je nepotrebno opsiran nacin kad URL objekt vec nudi serijaliziranu vrijednost kao svojstvo.
Good example
| 1 | const href = new URL(pathOrUrl, baseUrl).href; |
Explanation (EN)
The .href property returns the same serialized string and reads more directly.
Objašnjenje (HR)
Svojstvo .href vraca istu serijaliziranu vrijednost i citljivije je.