This simple lib checks whether the path is inside the directory or not.
npm i --save is-inside
const isInside = require('is-inside');
console.log(isInside('folder/file', 'folder')); // true
console.log(isInside('file', '/')); // true
console.log(isInside('file', 'folder')); // false
How the library compares paths can be viewed in test.js file.
The library depends only on Node's path
module. There are no external dependencies.
You can use it with TypeScript thanks to the added d.ts file.