There are full paths to files like
libs/shared/util/something/tsconfig.spec.json
apps/project/backend/subfolder/project.json
this/has/no/match.json
root-file.json
and I need to check if the file is inside of a path in the given projects object:
const projects = {
"just-a-library": "libs/shared/util/something",
"project-backend": "apps/project/backend"
}
My problem is, that it will never fully match, but only the beginning of the string - as there are optional subfolders and of course filenames. If there is a match, it should return the object key.
So for libs/shared/util/something/tsconfig.spec.json
it should return just-a-library
and this/has/no/match.json
there should be no result.
I can't use string.includes(substring)
or string.indexOf(substring)
as this is the other way round: The full string is the filepath input and I'm searching for a possible substring element.
Comments
Post a Comment