1
0
mirror of https://github.com/koloml/furbooru-tagging-assistant.git synced 2025-12-24 07:12:57 +00:00

Updating utils with type annotations from JSDoc

This commit is contained in:
2025-02-06 23:40:25 +04:00
parent 2eb824e54b
commit 011139d191

View File

@@ -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<string, any>, 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, "\\$&");
}