From 011139d19177a86f6f4b0f0dedd357cbefeba85c Mon Sep 17 00:00:00 2001 From: KoloMl Date: Thu, 6 Feb 2025 23:40:25 +0400 Subject: [PATCH] Updating utils with type annotations from JSDoc --- src/lib/utils.ts | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/lib/utils.ts b/src/lib/utils.ts index c7a6531..251fd43 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -1,13 +1,13 @@ /** * Traverse and find the object using the key path. - * @param {Object} targetObject Target object to traverse into. - * @param {string[]} path Path of keys to traverse deep into the object. - * @return {Object|null} Resulting object or null if nothing found (or target entry is not an object. + * @param targetObject Target object to traverse into. + * @param path Path of keys to traverse deep into the object. + * @return Resulting object or null if nothing found (or target entry is not an object). */ -export function findDeepObject(targetObject, path) { +export function findDeepObject(targetObject: Record, path: string[]): Object|null { let result = targetObject; - for (let key of path) { + for (const key of path) { if (!result || typeof result !== 'object') { return null; } @@ -27,17 +27,15 @@ export function findDeepObject(targetObject, path) { * * Gathered from right here: https://stackoverflow.com/a/3561711/16048617. Because I don't want to introduce some * library for that. - * - * @type {RegExp} */ -const unsafeRegExpCharacters = /[/\-\\^$*+?.()|[\]{}]/g; +const unsafeRegExpCharacters: RegExp = /[/\-\\^$*+?.()|[\]{}]/g; /** * Escape all the RegExp syntax-related characters in the following value. - * @param {string} value Original value. - * @return {string} Resulting value with all needed characters escaped. + * @param value Original value. + * @return Resulting value with all needed characters escaped. */ -export function escapeRegExp(value) { +export function escapeRegExp(value: string): string { unsafeRegExpCharacters.lastIndex = 0; return value.replace(unsafeRegExpCharacters, "\\$&"); }