1.
You can check if the string is equal path.basename(string). Then it does not contain path separators and is definitely not a file in another directory. This funtion does not affect the file system and only checks the string for the directory separator for specific directories and therefore matches your performance needs.
string === path.basename(string)
2.
Another idea: if the identifiers match a specific format, create a regular expression for the format and check each line for consistency and act accordingly.
/identifierregex/.test(string)
source
share