inlinable-runtime
Version:
JavaScript code inlining runtime utilities
22 lines (21 loc) • 716 B
JavaScript
/**
* Returns the deepest root containing the first argument, if any. A root is
* defined as a parent folder of one of the folders passed in as second argument
* (defaulting to `defaultRootFolders`).
*/
export function enclosingRoot(args) {
const sep = args.separator;
const sentinels = args.rootFolders ?? defaultRootFolders;
const pat = new RegExp(`${sep}(${sentinels.join('|')})(${sep}|$)`, 'g');
const matches = [...args.path.matchAll(pat)];
return matches.length
? args.path.slice(0, matches[matches.length - 1]?.index)
: undefined;
}
export const defaultRootFolders = [
'src',
'lib',
'test',
'.next',
];
export const defaultResourceFolder = 'resources';