( path: string, fileTree: FileTree, value: string, )
| 8 | }; |
| 9 | |
| 10 | export const createFile = ( |
| 11 | path: string, |
| 12 | fileTree: FileTree, |
| 13 | value: string, |
| 14 | ): FileTree => { |
| 15 | if (existsFile(path, fileTree)) { |
| 16 | throw new Error(`File ${path} already exists`); |
| 17 | } |
| 18 | const pathError = validatePath(path, fileTree); |
| 19 | if (pathError) { |
| 20 | throw new Error(pathError); |
| 21 | } |
| 22 | |
| 23 | const updatedFileTree = structuredClone(fileTree); |
| 24 | return set(updatedFileTree, path.split("/"), value); |
| 25 | }; |
| 26 | |
| 27 | export const validatePath = ( |
| 28 | path: string, |
no test coverage detected