glob-tree-list

glob result list to tree

Usage no npm install needed!

<script type="module">
  import globTreeList from 'https://cdn.skypack.dev/glob-tree-list';
</script>

README

glob-tree-list

glob result list to tree

demo

import { globToTree, treeToGlob } from 'glob-tree-list';

let data = `00020_1章.txt
00020_2章/
00020_3章/
00020_3章/3章 8話.txt
00020_3章/3章 9話/3章 9話file.txt
00020_3章/3章 10話.txt
00020_3章/3章 11話.txt
00020_3章/3章 12話.txt
00020_3章/3章 13話.txt
00020_3章/3章 14話.txt
00020_3章/3章 15話.txt
00020_3章/3章 15.5話 特別閑話.txt
00020_3章/3章 16話.txt
00020_3章/3章 17話.txt`.split("\n");

let t = globToTree(data);

console.log(t);

console.log(treeToGlob(t));
{ '00020_1章.txt': '00020_1章.txt',
  '00020_2章/': null,
  '00020_3章/': 
   { '3章 8話.txt': '3章 8話.txt',
     '3章 9話/': { '3章 9話file.txt': '3章 9話file.txt' },
     '3章 10話.txt': '3章 10話.txt',
     '3章 11話.txt': '3章 11話.txt',
     '3章 12話.txt': '3章 12話.txt',
     '3章 13話.txt': '3章 13話.txt',
     '3章 14話.txt': '3章 14話.txt',
     '3章 15話.txt': '3章 15話.txt',
     '3章 15.5話 特別閑話.txt': '3章 15.5話 特別閑話.txt',
     '3章 16話.txt': '3章 16話.txt',
     '3章 17話.txt': '3章 17話.txt' } }
[ '00020_1章.txt',
  '00020_2章/',
  '00020_3章/3章 8話.txt',
  '00020_3章/3章 9話/3章 9話file.txt',
  '00020_3章/3章 10話.txt',
  '00020_3章/3章 11話.txt',
  '00020_3章/3章 12話.txt',
  '00020_3章/3章 13話.txt',
  '00020_3章/3章 14話.txt',
  '00020_3章/3章 15話.txt',
  '00020_3章/3章 15.5話 特別閑話.txt',
  '00020_3章/3章 16話.txt',
  '00020_3章/3章 17話.txt' ]