Giter Site home page Giter Site logo

b4dnewz / node-temp Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 672 KB

A node utility to handle temporary files and folders

Home Page: https://b4dnewz.github.io/node-temp/

License: Other

TypeScript 97.89% JavaScript 0.41% Shell 1.70%
testing temporary temporary-files temporary-directory testing-utils testing-utilities testing-tools random buffer mock

node-temp's Introduction

temp

A node utility to handle temporary files and folders

NPM version Build Status Coverage percentage


Getting started

Install the project using your favourite package manager.

npm install @b4dnewz/temp

Load inside your project all together or separate functions.

import * as temp from "@b4dnewz/temp";
// or
import {file, fileSync, dir, dirSync} from "@b4dnewz/temp";

Then create any temporary file you need in your application or your tests.

// create a temporary file
// es: /tmp/e6ba9fff240bde04897f/5fb6aa4e9ac8ccf10e2f
temp.file()

// create a temporary file in sync way
temp.fileSync()

// create a temporary directory
// es: /tmp/3c34454971179fc20e99/29d72d3cb2386b904afe
temp.dir()

// create a temporary directory in sync way
temp.dirSync()
it("should create a temporary file", async () => {
    const tmpFile = await temp.file()
    // do whatever you need with the file
    await tmpFile.remove()
})

Later on, when you have done with it, just release it.

// will remove the temporary file
tmpFile.remove()

// will remove the temporary directory
// even if has content in it
// such as other temporary files
tmpDir.remove()

Documentation

This project provide an online documentation automatically generated with TypeDoc, but a very deep documentation with real world usage examples is coming soon, stay tuned.


Contributing

  1. Create an issue and describe your idea
  2. Fork the project (https://github.com/b4dnewz/node-temp/fork)
  3. Create your feature branch (git checkout -b my-new-feature)
  4. Commit your changes with logic (git commit -am 'Add some feature')
  5. Publish the branch (git push origin my-new-feature)
  6. Add some test for your new feature
  7. Create a new Pull Request

License

MIT © Filippo Conti

node-temp's People

Watchers

 avatar  avatar

node-temp's Issues

Quick uses signature overloads

When creating temp files, right now you optionally pass it as first argument the file content, since the purpose of the module is to create temporary files the second argument can be skipped and the file would be created with a random filename, basically is good for most of the cases, since the actual generated filename and filepath can be retrieved on the temp file object, but in certain cases you might want to use a custom filename.

The current signature is:

function fileSync(content: any = "", options: FileWriteOptions = {})

If a custom filename is needed the way is the following:

temp.fileSync({foo: "bar"}, { name: "config.json" })

Since the FileWriteOptions are currently mostly related to the filename customization, the proposal is to implicitly assume that if the second function argument is a string, it will be the filename, such as this:

temp.fileSync({foo: "bar"}, "config.json")

It's easier to read and less verbose, also the filename can be checked if is a relative or absolute file name/path and its sections (if any) used as the remaining FileWriteOptions keys.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.