Skip to content

Commit 8d85053

Browse files
author
Simon Mellberg
committed
Updated typedefs to hopefully be clearer.
Signed-off-by: Simon Mellberg <[email protected]>
1 parent 0f5d7ba commit 8d85053

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

plugins/caspar/app/utils/library.cjs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,28 @@ const FILE_PATH_DELIMITER = /[\/\\]+/ // eslint-disable-line
1010
*/
1111
const ENDS_WITH_DELIMITER = /[\/\\]$/ // eslint-disable-line
1212

13+
/**
14+
* @typedef {{
15+
* file: boolean
16+
* name: string
17+
* id: string
18+
* path?: Object // Original path object that may contain properties like caspar, data, etc.
19+
* }} File
20+
*
21+
* @typedef {{
22+
* file: boolean
23+
* name: string
24+
* id: string
25+
* files?: Folder[] // Nested files or folders
26+
* }} Folder
27+
*/
28+
1329
/**
1430
* Converts a list of file paths into a nested folder structure.
1531
* The function assumes that paths are strings with folders and files separated by '/' or '\'.
16-
*
17-
* @typedef {Object} File
18-
* @property {boolean} file - A flag indicating whether the object is a file (true) or a folder (false).
19-
* @property {string} name - The full path as a string (e.g., 'folder1/folder2/item').
20-
* @property {string} id - A unique identifier.
21-
* @property {Object} [path] - The original path object that contains additional properties such as caspar, data etc.
22-
*
23-
* @typedef {Object} Folder
24-
* @property {boolean} file - A flag indicating whether the object is a file (true) or a folder (false).
25-
* @property {string} name - The name of the file/folder.
26-
* @property {string} id - A unique identifier.
27-
* @property {Array[]} [files] - An array of nested files/folders.
2832
*
29-
* @param {Array[]} paths - An array of path objects, where each object contains at least a `name` property with the full path.
30-
* @returns {Folder[]} - A nested folder structure represented as an array of folder objects.
33+
* @param {{ name: string, [key: string]: any }[]} paths - An array of path objects with at least a `name` string.
34+
* @returns {Folder[Folder|File]} - A nested folder structure represented as an array of folder objects.
3135
* @example
3236
* Input: [{ path.name: 'folder1/item' }]
3337
* Output: [

0 commit comments

Comments
 (0)