All files / src/fs/util file-util.js

100% Statements 12/12
100% Branches 10/10
100% Functions 4/4
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 431x             1x 280x               1x 303x               10x 10x                     148x 148x        
import { fromJS } from 'immutable';
 
/**
 * Checks if a JavaScript object is a file object
 * @param  {object}  json potential file
 * @return {boolean}      whether the object conforms to the file schema
 */
export const isFile = (map) => {
  return map.has('content');
};
 
/**
 * Checks if a JavaScript object is a directory object
 * @param  {object}  json potential directory
 * @return {boolean}      whether the object conforms to the directory schema
 */
export const isDirectory = (map) => {
  return !map.has('content');
};
 
/**
 * Makes an file conforming to the file schema
 * @param  {object} content  content of the file
 * @return {object}          new file
 */
export const makeFile = (content = '', metadata = {}) => {
  return fromJS({
    content,
    ...metadata
  });
};
 
/**
 * Makes an directory conforming to the directory schema
 * @param  {object} children child directories or files
 * @return {object}          new directory
 */
export const makeDirectory = (metadata = {}) => {
  return fromJS({
    ...metadata
  });
};