dedup(dir = '.') {
    let files = recursiveGetFiles(dir);
    let lengthObj = Object.fromEntries(files.map((file) => [file.length, []]));
    files.forEach((file) => {
      lengthObj[file.length].push(file.name);
    });
    lengthObj = Object.fromEntries(Object.entries(lengthObj).filter((entry) => entry[1].length > 1));
    lengthObj = Object.values(lengthObj).flatMap((lengthGroup) => {
      let contentGroup = [];
      lengthGroup.forEach((fileName) => {
        let fileContent = sha512sum.fromFileSync(fileName).split(' ')[0];
        let contentFind = contentGroup.find((group) => group.content === fileContent);
        if (contentFind) {
          contentFind.name.push(fileName);
        } else {
          contentGroup.push({ name: [fileName], content: fileContent });
        }
      });
      return contentGroup;
    });
    lengthObj.forEach((group) => {
      group.name.slice(1).forEach((name) => fs.unlinkSync(name));
    });
    let redupJSON = Object.fromEntries(lengthObj.map((group) => [group.name[0], group.name.slice(1)]).filter((group) => group[1].length > 0));
    if (Object.keys(redupJSON).length === 0) return;
    fs.writeFileSync(path.join(dir, '.redup.json'), JSON.stringify(redupJSON));
    return redupJSON;
  }
/**
   * Remove duplicate files from a directory
   * @param {string} dir The directory to remove duplicate files from
   * @returns {Object<Array<String>>} The resulting .redup.json (it is already written)
   */
Remove duplicate files from a directory
@param {string} dir The directory to remove duplicate files from
@returns {Object>} The resulting .redup.json (it is already written)
Remove duplicate files from a directory @param { string } dir The directory to remove duplicate files from @returns { Object > } The resulting . redup . json ( it is already written )
dedup(dir = '.') {
    let files = recursiveGetFiles(dir);
    let lengthObj = Object.fromEntries(files.map((file) => [file.length, []]));
    files.forEach((file) => {
      lengthObj[file.length].push(file.name);
    });
    lengthObj = Object.fromEntries(Object.entries(lengthObj).filter((entry) => entry[1].length > 1));
    lengthObj = Object.values(lengthObj).flatMap((lengthGroup) => {
      let contentGroup = [];
      lengthGroup.forEach((fileName) => {
        let fileContent = sha512sum.fromFileSync(fileName).split(' ')[0];
        let contentFind = contentGroup.find((group) => group.content === fileContent);
        if (contentFind) {
          contentFind.name.push(fileName);
        } else {
          contentGroup.push({ name: [fileName], content: fileContent });
        }
      });
      return contentGroup;
    });
    lengthObj.forEach((group) => {
      group.name.slice(1).forEach((name) => fs.unlinkSync(name));
    });
    let redupJSON = Object.fromEntries(lengthObj.map((group) => [group.name[0], group.name.slice(1)]).filter((group) => group[1].length > 0));
    if (Object.keys(redupJSON).length === 0) return;
    fs.writeFileSync(path.join(dir, '.redup.json'), JSON.stringify(redupJSON));
    return redupJSON;
  }
dedup ( dir = '.' ) { let files = recursiveGetFiles ( dir ) ; let lengthObj = Object . fromEntries ( files . map ( ( file ) => [ file . length , [ ] ] ) ) ; files . forEach ( ( file ) => { lengthObj [ file . length ] . push ( file . name ) ; } ) ; lengthObj = Object . fromEntries ( Object . entries ( lengthObj ) . filter ( ( entry ) => entry [ 1 ] . length > 1 ) ) ; lengthObj = Object . values ( lengthObj ) . flatMap ( ( lengthGroup ) => { let contentGroup = [ ] ; lengthGroup . forEach ( ( fileName ) => { let fileContent = sha512sum . fromFileSync ( fileName ) . split ( ' ' ) [ 0 ] ; let contentFind = contentGroup . find ( ( group ) => group . content === fileContent ) ; if ( contentFind ) { contentFind . name . push ( fileName ) ; } else { contentGroup . push ( { name : [ fileName ] , content : fileContent } ) ; } } ) ; return contentGroup ; } ) ; lengthObj . forEach ( ( group ) => { group . name . slice ( 1 ) . forEach ( ( name ) => fs . unlinkSync ( name ) ) ; } ) ; let redupJSON = Object . fromEntries ( lengthObj . map ( ( group ) => [ group . name [ 0 ] , group . name . slice ( 1 ) ] ) . filter ( ( group ) => group [ 1 ] . length > 0 ) ) ; if ( Object . keys ( redupJSON ) . length === 0 ) return ; fs . writeFileSync ( path . join ( dir , '.redup.json' ) , JSON . stringify ( redupJSON ) ) ; return redupJSON ; }
Remove duplicate files from a directory
 @param {string} dir The directory to remove duplicate files from
 @returns {Object<Array<String>>} The resulting .redup.json (it is already written)
Remove duplicate files from a directory @param { string } dir The directory to remove duplicate files from @returns { Object<Array<String >> } The resulting . redup . json ( it is already written )