0.3.1 • Published 6 years ago

hexlet-immutable-fs-trees v0.3.1

Weekly downloads
2
License
ISC
Repository
github
Last release
6 years ago

js-immutable-fs-trees

github action status

Install

npm install @hexlet/immutable-fs-trees

Usage example

import {
  mkfile, mkdir, isDirectory, isFile, map,
} from '@hexlet/immutable-fs-trees';

isFile(mkfile('config')); // true
isDirectory(mkdir('etc')); // true

const tree = mkdir('etc', [mkfile('config'), mkfile('hosts')]);

const callbackFn = (node) => {
  const { name } = node;
  const newName = name.toUpperCase();
  return { ...node, name: newName };
};

map(callbackFn, tree);
// {
//   name: 'ETC',
//   children: [
//     { name: 'CONFIG', meta: {}, type: 'file' },
//     { name: 'HOSTS', meta: {}, type: 'file' }
//   ],
//   meta: {},
//   type: 'directory',
// }

For more information, see the Full Documentation