Skip to content

Repository files navigation

js-immutable-fs-trees

github action status

Зачем это нужно

Дерево файловой системы из неизменяемых узлов: любая правка возвращает новое дерево, старое остаётся прежним.

Нужна курсам, где сравнивают этот подход с изменяемыми деревьями из @hexlet/trees. На таком сравнении видно, что неизменяемость даёт (безопасное разделение данных) и чего стоит (пересборка пути до корня на каждое изменение).

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


Hexlet Ltd. logo

This repository is created and maintained by the team and the community of Hexlet, an educational project. Read more about Hexlet.

See most active contributors on hexlet-friends.

Releases

Packages

Used by

Contributors

Languages