Detalhes do pacote

mktemp

sasaplus12.1mMIT1.0.1

mktemp command for node.js

readme (leia-me)

mktemp

Build Status npm version Try mktemp on RunKit renovate

mktemp command for node.js

Installation

$ npm install mktemp

Usage

var mktemp = require('mktemp');

mktemp.createFile('XXXXX.txt', function(err, path) {
  if (err) throw err;

  // path match a /^[\da-zA-Z]{5}\.txt$/
  console.log(path);
});

// return value match a /^[\da-zA-Z]{5}\.tmp$/
mktemp.createFileSync('XXXXX.tmp');

mktemp.createDir('XXXXXXX', function(err, path) {
  if (err) throw err;

  // path match a /^[\da-zA-Z]{7}$/
  console.log(path);
});

// return value match a /^XXX-[\da-zA-Z]{3}$/
mktemp.createDirSync('XXX-XXX');

if support Promise, can use Promise style.

var mktemp = require('mktemp');

mktemp
  .createFile('XXXXX.txt')
  .then(function(path) {
    // path match a /^[\da-zA-Z]{5}\.txt$/
    console.log(path);
  })
  .catch(function(err) {
    console.error(err);
  });

mktemp
  .createDir('XXXXX')
  .then(function(path) {
    // path match a /^[\da-zA-Z]{5}$/
    console.log(path);
  })
  .catch(function(err) {
    console.error(err);
  });

mktemp functions are replace to random string from placeholder "X" in template. see example:

mktemp.createFileSync('XXXXXXX');  // match a /^[\da-zA-Z]{7}$/
mktemp.createFileSync('XXX.tmp');  // match a /^[\da-zA-Z]{3}\.tmp$/
mktemp.createFileSync('XXX-XXX');  // match a /^XXX-[\da-zA-Z]{3}$/

Functions

createFile(template[, callback])

  • template
    • String - filename template
  • callback
    • function(err, path) - callback function
      • err : Error|Null - error object
      • path : String - path

create blank file of unique filename. permission is 0600.

it throws TypeError if node.js unsupported Promise and callback is not a function.

createFileSync(template)

  • template
    • String - filename template
  • return
    • String - path

sync version createFile.

createDir(template[, callback])

  • template
    • String - dirname template
  • callback
    • function(err, path) - callback function
      • err : Error|Null - error object
      • path : String - path

create directory of unique dirname. permission is 0700.

it throws TypeError if node.js unsupported Promise and callback is not a function.

createDirSync(template)

  • template
    • String - dirname template
  • return
    • String - path

sync version createDir.

Contributors

License

The MIT license.

changelog (log de mudanças)

1.0.1 / 2023-05-03

  • add missing type files

1.0.0 / 2019-05-27

  • modernize

0.4.0 / 2015-02-16

  • supported Promise
  • changed to use power-assert from expect.js

0.3.5 / 2014-06-25

  • changed to use setImmediate in async functions
  • refactored

0.3.4 / 2013-11-23

  • changed to throw error if error code is not EEXIST

0.3.3 / 2013-11-14

  • changed from fs.exists to fs.open/fs.close/fs.mkdir

0.3.2 / 2013-09-08

  • changed from chai to expect.js

0.3.1 / 2013-06-19

  • changed to fast mkrand

0.3.0 / 2013-04-06

  • changed to create random name again if file exists
  • deleted mode parameter

0.2.1 / 2013-02-29

  • added support for node.js 0.10

0.2.0 / 2013-02-05

  • changed to replace placeholder near end of line

0.1.0 / 2013-01-16

  • initial release