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

saveit.cjs

v1.0.8

Published

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)

Downloads

38

Readme

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 install | command | version| | :-------------: |:-------------:| :-----:| | NPM | npm i saveit.cjs | commonJS| | NPM | npm i saveit.mjs | ecmaJS|

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

  import { saveFile } from "saveit.mjs";
  saveFile({file: yourFile, filePath: yourFile, options: yourOptions}); // will return the file ID on success
    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
  const {saveFile} = require("saveit.cjs");
  saveFile({file: yourFile, filePath: yourFile, options: yourOptions}); // will return the file ID on success
    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

  import { deleteFile } from "saveit.mjs";
  deleteFile({fileID: nameOfFile, filePath: yourPath, options: yourOptions}); // will return true on success
    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
  const {deleteFile} = require("saveit.cjs");
  deleteFile({fileID: yourFile, filePath: yourFile, options: yourOptions}); // will return true on success
  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.