npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

file-manipulator

v1.2.13

Published

## Easy File operations library

Downloads

7

Readme

FILE-MANIPULATOR

Easy File operations library

1. ways of using

  • for file system operation 🤖
  • node js fs wrapper for CRUD to files and folders ✅
  • create your custom CLI 🎉 ( fs / nodejs / react-native / flutter / ember/eth... )
  • easy and readable documentation 🍗
  • high-level wrapper for every-level projects 🍎
  • good supporting 🥽
  • except error handling and using boolean operations methods result ✅
  • UPD: support js and ts already ✅ ✅ ✅

install

yarn add file-manipulator

or

npm i file-manipulator

2. one`s principe for each method

every operation need to:

  • file
    • file name
    • file extension
    • file folder path
    • operation (CRUD)
  • folder
    • folder name
    • folder path
    • operation (CRUD)

3. example of using

import fileManipulator from 'file-manipulator'


const start = async () => {
  //create file
  const isCreatedFile = await fileManipulator.create.file({
    name: 'example-file',
    ext: 'txt',
    path: './',
    content: 'Hello wold 🎉',
    replaceExisting: true
  })
  console.log({isCreatedFile})

  //create folder
  const isCreatedFolder = await fileManipulator.create.folder({
    name: 'example-folder',
    path: './',
    replaceExisting: true
  })
  console.log({isCreatedFolder})

  //copy file to folder
  const isCopiedFile = await fileManipulator.copy.file({
    name: 'example-file',
    ext: 'txt',
    from: './',
    to: './example-folder',
    replaceExisting: true
  })
  console.log({isCopiedFile})

  //move example file to example folder
  const isMovedFile = await fileManipulator.move.file({
    name: 'example-file',
    ext: 'txt',
    from: './',
    to: './example-folder',
    renameTo: 'example-file-1',
  })
  console.log({isMovedFile})

  //delete excess file
  const isDeletedFile = await fileManipulator.delete.file({
    name: 'example-file',
    ext: 'txt',
    path: './example-folder',
  })
  console.log({isDeletedFile})

  //edit file name
  const isRenamedFile = await fileManipulator.update.file({
    name: 'example-file-1',
    ext: 'txt',
    renameTo: 'example-file',
    path: './example-folder'
  })
  console.log({isRenamedFile})

  //replace file inner
  const isReplacedInnerText = await fileManipulator.update.file({
    name: 'example-file',
    ext: 'txt',
    path: './example-folder',
    stringFrom: 'Hello ', //string or regexp
    stringTo: 'Wow 🎉',
  })
  console.log({isReplacedInnerText})

  //replace file inner text by coordinates
  const isEditedInnerText = await fileManipulator.update.file({
    name: 'example-file',
    ext: 'txt',
    path: './example-folder',
    lineParams: {line: 0, space: 6, len: 7}, //replace from row 0, col 6, to row 0, col 13, to  "stringTo" value
    stringTo: 'Wow 🎉',
  })
  console.log({isEditedInnerText})
}

start()

4. types and API docs


//main defult types

class FileManipulator {
  copy: Copper
  move: Mover
  delete: Deleter
  create: Creator
  update: Updater
  read: Reader
}

export default new FileManipulator()

//Copper types

type CopperFileConfig = {
  name: string //file name without ext
  ext?: string //name without ext
  from: string //folder path from copy
  to: string //folder path to paste
  renameTo?: string //new optional name for once file
  replaceExisting?: boolean //replace if there is exist the same file ? (default false)
}

type CopperFolderConfig = {
  renameTo?: string //new optional name for once file
  from: string //folder path from copy
  to: string //folder path to paste
  name: string //name folder
  replaceExisting?: boolean //replace if there is exist the same file (default false) (for files only)
}

fileManipulator.copy.file(config: CopperFileConfig): Promise<boolean>
fileManipulator.copy.folder(config: CopperFolderConfig): Promise<boolean>
        
//Mover types

type MoverFileConfig = {
  name: string //file name without ext
  ext: string //name without ext
  from: string //folder path from copy
  to: string //folder path to paste
  renameTo?: string //new optional name for once file
  replaceExisting?: boolean //replace if there is exist the same file ? (default false)
}
type MoverFolderOutConfig = {
  from: string //folder path from copy
  to: string //folder path to paste
  name: string //name folder
  renameTo?: string //new optional name for once folder
  replaceExisting?: boolean //replace if there is exist the same file ? (default false)
}

fileManipulator.move.file(config: MoverFileConfig): Promise<boolean>
fileManipulator.move.folder(config: MoverFolderOutConfig): Promise<boolean>


//Deleter types

type DeleterFileConfig = {
  name: string //name without ext
  ext: string //name without ext
  path: string //path file locate
}
type DeleterFolderOutConfig = {
  path: string //path file locate
  name: string //name folder
}

fileManipulator.delete.file(config: DeleterFileConfig): Promise<boolean>
fileManipulator.delete.folder(config: DeleterFolderOutConfig): Promise<boolean>
        
//Creator types

type CreatorFileConfig = {
  path: string //path without name
  name: string //name without ext
  ext: string //name without ext
  content?: string //default empty string (inside)
  replaceExisting?: boolean //replace if there is exist the same file ? (default false)
  encoding?: BufferEncoding //default "utf8"
}
type CreatorFolderOutConfig = {
  path: string //path without name
  name: string //name folder
  replaceExisting?: boolean //replace if there is exist the same file (default false)
}

fileManipulator.create.file(config: CreatorFileConfig): Promise<boolean>
fileManipulator.create.folder(config: CreatorFolderOutConfig): Promise<boolean>

//Updater types 

type UpdateFileInnerConfig = {
  //together params
  lineParams?: {
    line: number //row number for replace string
    space: number //space number for replace string (from 0)
    len: number //length for replace string to "stringTo" params (iclude first char)
  }
  stringFrom?: string | RegExp //replace match string = string / regexp to find
  stringTo?: string
}
type UpdateFileOutConfig = {
  path: string //path without name
  name: string //name without ext
  ext: string //name without ext
  renameTo?: string //new name
  replaceExisting?: boolean //replace if there is exist the same file ? (default false)
}
type UpdateFolderOutConfig = {
  path: string //path without name
  name: string //current name without ext (before rename)
  renameTo: string //new name
  replaceExisting?: boolean //replace if there is exist the same file ? (default false)
}

fileManipulator.update.file(config: UpdateFileInnerConfig & UpdateFileOutConfig): Promise<boolean>
fileManipulator.update.folder(config: UpdateFolderOutConfig): Promise<boolean>


//Reader types

type ReaderFileConfig = {
  name: string //name without ext
  ext: string //name without ext
  path: string //path file locate folder parent
  encoding?: BufferEncoding //result file code (default urf8)
}
type ReaderFolderOutConfig = {
  path: string //path folder locate parent
  name: string //name folder
}

export type ReturnReadFileType = { 
    readed: boolean, //is readed file or no 
    result: string  // file content
}
export type ReturnReadFolderType = { 
    readed: boolean, //is readed folder or no 
    result: string[] // folder content array (with extensions) (ex: [f1.txt] )
}

fileManipulator.read.file(config: ReaderFileConfig): Promise<ReturnReadFileType>
fileManipulator.read.folder(config: ReaderFolderOutConfig): Promise<ReturnReadFolderType>

#Contact

✨Lib going to grow up, and you can send your questions and offers to my telegram Stepan_Turchenko 🛬