New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

saveit.cjs

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

saveit.cjs

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)

  • 1.0.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

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

Ecma JS
Simple example
  import { saveFile } from "saveit.mjs";
  saveFile({file: yourFile, filePath: yourFile, options: yourOptions}); // will return the file ID on success
Senior example
    import { saveFile } from "saveit.mjs";
    
    const yourOptions = {
    isBinaryData: yourBoolean,
    type: yourType,
    folderGenerate: yourFolderBoolean,
    fileExtention: yourFileExtension,
    fileType: yourFileType,
    src: yourSrc
    }
    saveFile({file: yourFile, filePath: yourFile, options: yourOptions}); // will return the file ID on success
Common JS
Simple example
  const {saveFile} = require("saveit.cjs");
  saveFile({file: yourFile, filePath: yourFile, options: yourOptions}); // will return the file ID on success
Senior example
    const {saveFile} = require("saveit.cjs");
    
    const yourOptions = {
    isBinaryData: yourBoolean,
    type: yourType,
    fileExtention: yourFileExtension,
    folderGenerate: yourFolderBoolean, 
    fileType: yourFileType,
    src: yourSrc
    }
    saveFile({file: yourFile, filePath: yourFile, options: yourOptions}); // will return the file ID on success

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

Ecma JS
Simple example
  import { deleteFile } from "saveit.mjs";
  deleteFile({fileID: nameOfFile, filePath: yourPath, options: yourOptions}); // will return true on success
Senior example
    import { deleteFile } from "saveit.mjs";
    
    const options = {
    deleteAll: yourBoolean,
    src: yourRootPath,
    ignoreExtension: yourIgnoreBoolean
    }
    saveFile({fileID: nameOfFile, filePath: yourPath, options: yourOptions}); // will return true on success
Common JS
Simple example
  const {deleteFile} = require("saveit.cjs");
  deleteFile({fileID: yourFile, filePath: yourFile, options: yourOptions}); // will return true on success
Senior example
  const {deleteFile} = require("saveit.cjs");
    
  const options = {
    deleteAll: yourBoolean,
    src: yourRootPath,
    ignoreExtension: yourIgnoreBoolean
  }
  deleteFile({fileID: yourFile, filePath: yourFile, options: yourOptions}); // will return true on success

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.

Keywords

FAQs

Package last updated on 09 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc