1.0.6 • Published 10 months ago

saveit.mjs v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

SaveIt

SaveIt is a package that allows you to save files in a static folder (or anywhere else). Many Node.js frameworks have their own way of handling files (fastify, multer). SaveIt has the ability to consider it. The package has two functions (save and delete). TypeScript support and small file size will help you get started very quickly.

Usage

import { saveFile } from "saveit.mjs"; // or .cjs

// yourFile is a file or a buffer/binary data
saveFile({file: yourFile});

Instalation

Way to installcommandversion
NPMnpm i saveit.cjscommonJS
NPMnpm i saveit.mjsecmaJS

Why?

This will help you save time and also serve as a great refactoring tool.

All functions

saveFile

Will return the file ID on success

How to use

Parameters

  • file
    • reqired
    • Buffer / Binary data OR Object from the framework file processing. If it is an object, you must use fileType property of the otpions object. If it is raw binary data, you must use isBinaryData property of the otpions object.
  • filePath
    • not reqired
    • String that will point SaveIt to the location where you want to save the file.
    • The string will be passed to the path.resolve method of Node.js. So if you will pass /a, it will probably ( If you did not specify the src property in the options parameter of the saveFile function) go in C:\a.
    • Will create the path if it does not exist.
  • options
    • not reqired
    • Object that can make your life a little easier (read about the properties of the options in the "Options" section).

Options

  • isBinaryData
    • default is false
    • Boolean value that tells SaveIt whether the value in the function parameter (file parameter) is binary data.
    • Will ignore fileType propertie of the options object.
  • type
    • default is BuffData / BinData (if options.isBinaryData equals true then BinData).
    • String that tells SaveIt what the file is, it is optional and will only create a folder with the name of the value, where will be the file.
  • folderGenerate
    • default is true
    • Boolean value indicating whether SaveIt should generate the folder based on the type propertie from options object.
  • fileExtention
    • default is .bin or .txt (if options.isBinaryData equals true then .bin).
    • String that tells SaveIt which extension the file should have when saved. The original file extension will be ignored.
    • Do not include the dot (.)
  • fileType

    • default is buffer
    • String that tells SaveIt how to process the file. Each framework has its own object when it works with a file.

    list of patterns:

    • buffer
    • multer
    • fastify
  • src

    • default is your working root
    • String pointing SaveIt to the root folder. (will work in this folder) and is combined with filePath if it exists.
    • it will pass the string to path.resolve() so if you will pass "/a", then it will set C:\a as a root folder.

deleteFile

Will return true on success

How to use

Parameters

  • fileID
    • reqired
    • String that tells SaveIt the name of the file.
  • filePath
    • not reqired
    • String that pointig SaveIt file path.
    • If it is not passed, then SaveIt will look in the root working folder by default or src property will look for static folder (if it is not there, it will give an error) will look in all files (including folders) and delete the file with name that was specified in fileID, if not, it will return false otherwise it will delete and return true.
    • The string will be passed to the path.resolve method of Node.js. So if you will pass /a, it will probably ( If you did not specify the src property in the options parameter of the saveFile function) go in C:\a.
  • options
    • not reqired
    • Object that can make your life a little easier (read about the properties of the options in the "Options" section).

Options

  • src
    • default is your working root
    • String pointing SaveIt to the root folder. (will work in this folder) and is combined with filePath if it exists.
    • it will pass the string to path.resolve() so if you will pass "/a", then it will set C:\a as a root folder.
    • WITHOUT FILEPATH WILL ALSO ADD STATIC FOLDER IN THE END OF THE STRING
  • ignoreExtension
    • default is false
    • Boolean value that tells SaveIt whether fileID is a name/id with extension (.jpeg,.exe,.txt,..etc) or not. If not, the first file with the name that matched will be deleted.

Dangerous, do not use this if you are not a professional, it can delete everything in your personal computer

  • deleteAll
    • default is false
    • Boolean. true - means that all files on this path should be deleted.

Support

SaveIt support Ecma js and Common js and Typescript.

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago