From d8899ba33aea85024e4f7c9396294e425a4234a9 Mon Sep 17 00:00:00 2001 From: Ayoub-Mabrouk Date: Thu, 7 Nov 2024 21:17:31 +0100 Subject: [PATCH] refactor: improve toClassName function readability and JSDoc completeness - Replaced substr with slice for better readability and consistency. - Updated JSDoc to include @param and @returns tags for clarity on function inputs and outputs. - Simplified the conditional logic by using slice(-5) === 'Error' for a concise and clear check. --- HISTORY.md | 5 +++++ index.js | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 7228684..f39d711 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,8 @@ +Unreleased changes +================== + + * improve toClassName function readability and JSDoc completeness + 2.0.0 / 2021-12-17 ================== diff --git a/index.js b/index.js index c425f1e..82271f6 100644 --- a/index.js +++ b/index.js @@ -279,11 +279,12 @@ function populateConstructorExports (exports, codes, HttpError) { /** * Get a class name from a name identifier. + * + * @param {string} name + * @returns {string} * @private */ function toClassName (name) { - return name.substr(-5) !== 'Error' - ? name + 'Error' - : name + return name.slice(-5) === 'Error' ? name : name + 'Error' }