generate-glob-patterns.ts 761 B

12345678910111213141516171819202122232425262728
  1. import { pathUtils } from '@growi/core/dist/utils';
  2. /**
  3. * @example
  4. * // Input: '/Sandbox/Bootstrap5/'
  5. * // Output: ['/Sandbox/*', '/Sandbox/Bootstrap5/*']
  6. *
  7. * // Input: '/user/admin/memo/'
  8. * // Output: ['/user/*', '/user/admin/*', '/user/admin/memo/*']
  9. */
  10. export const generateGlobPatterns = (path: string): string[] => {
  11. // Remove trailing slash if exists
  12. const normalizedPath = pathUtils.removeTrailingSlash(path);
  13. // Split path into segments
  14. const segments = normalizedPath.split('/').filter(Boolean);
  15. // Generate patterns
  16. const patterns: string[] = [];
  17. let currentPath = '';
  18. for (let i = 0; i < segments.length; i++) {
  19. currentPath += `/${segments[i]}`;
  20. patterns.push(`${currentPath}/*`);
  21. }
  22. return patterns;
  23. };