pax_global_header00006660000000000000000000000064136571042540014521gustar00rootroot0000000000000052 comment=48948f9da604b295a22daf12a377801e250dacaa temporary-1.1.0/000077500000000000000000000000001365710425400135425ustar00rootroot00000000000000temporary-1.1.0/.gitignore000066400000000000000000000002411365710425400155270ustar00rootroot00000000000000tmp node_modules *._ *.tmp .monitor *.diff *.err *.orig *.log *.rej *.swo *.swp *.vi *~ .DS_Store Thumbs.db .cache .project .settings .tmproj *.esproj nbproject temporary-1.1.0/.travis.yml000066400000000000000000000000641365710425400156530ustar00rootroot00000000000000language: node_js node_js: - 6.0 - 8.0 - 10.0 temporary-1.1.0/History.md000066400000000000000000000013061365710425400155250ustar00rootroot000000000000001.1.0 / 2020-05-13 * More strict default permissions. 1.0.1 / 2019-05-24 ================== * Fix bug in default arguments to writeFile. 1.0.0 / 2019-01-24 ================== * Updated to modern node. 0.0.8 / 2014-01-05 ================== * Fix Node 0.11 error when path is frozen. 0.0.7 / 2013-09-25 ================== * Normalize windows paths correctly * On Windows lib/detector.js not adding trailing slash when needed. 0.0.6 / 2013-09-13 ================== * Export Dir and File in index * Test on Node 0.10 as well * Get tests passing on OSX * Update Readme.md 0.0.5 / 2012-11-12 ================== * Solved process.env issue in detector on certain version so linux. temporary-1.1.0/LICENSE000066400000000000000000000020601365710425400145450ustar00rootroot00000000000000MIT License Copyright (C) 2012 Veselin Todorov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. temporary-1.1.0/Readme.md000066400000000000000000000046731365710425400152730ustar00rootroot00000000000000[![Build Status](https://secure.travis-ci.org/vesln/temporary.png)](http://travis-ci.org/vesln/temporary) # temporary - The lord of tmp. ## Intro Temporary provides an easy way to create temporary files and directories. It will create a temporary file/directory with a unique name. ## Features - Generates unique name. - Auto-discovers tmp dir. ## Installation $ npm install temporary ## Usage var tmp = require('temporary'); var file = new tmp.File(); var dir = new tmp.Dir(); console.log(file.path); // path. console.log(dir.path); // path. file.unlink(); dir.rmdir(); ### Custom path If you want to manually specify the directory name, you can do so by setting the `generator` option to `false`. ```js var tmp = require('temporary'); var dir = new tmp.Dir('foobar', { generator: false }); console.log(dir.path) // prints 'foobar' ``` ### Custom generator Generators allow you to specify how the directory or file names get generated. ```js var tmp = require('temporary'); var dir = new tmp.Dir('foobar', { generator: function() {} }); ``` ## Methods ### File - File.readFile - File.readFileSync - File.writeFile - File.writeFileSync - File.open - File.openSync - File.close - File.closeSync - File.unlink - File.unlinkSync ### Dir - Dir.rmdir - Dir.rmdirSync ## Tests $ make test ## Contribution Bug fixes and features are welcomed. Current maintainer: @willscott ## License MIT License Copyright (C) 2012 Veselin Todorov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. temporary-1.1.0/examples/000077500000000000000000000000001365710425400153605ustar00rootroot00000000000000temporary-1.1.0/examples/dir.js000066400000000000000000000004571365710425400165020ustar00rootroot00000000000000/** * Temporary - The lord of tmp. * * Author: Veselin Todorov * Licensed under the MIT License. */ var Tempdir = require('../lib/dir'); var dir = new Tempdir('foo') // name - optional console.log(dir.path); // path. /** * You can also use: * * dir.rmdir * dir.rmdirSync */temporary-1.1.0/examples/file.js000066400000000000000000000007111365710425400166340ustar00rootroot00000000000000/** * Temporary - The lord of tmp. * * Author: Veselin Todorov * Licensed under the MIT License. */ var Tempfile = require('../lib/file'); var file = new Tempfile('foo') // name - optional console.log(file.path); // file path. /** * You can also use: * * file.readFile * file.readFileSync * file.writeFile * file.writeFileSync * file.open * file.openSync * file.close * file.closeSync * file.unlink * file.unlinkSync */temporary-1.1.0/index.js000066400000000000000000000006401365710425400152070ustar00rootroot00000000000000/** * Temporary - The lord of tmp. * * Author: Veselin Todorov * Licensed under the MIT License. */ /** * Dependencies. */ var package = require('./package.json'); /** * Version. */ module.exports.version = package.version; /** * Exporting the temp file */ module.exports.File = require('./lib/file'); /** * Exporting the temp directory. */ module.exports.Dir = require('./lib/dir'); temporary-1.1.0/lib/000077500000000000000000000000001365710425400143105ustar00rootroot00000000000000temporary-1.1.0/lib/base.js000066400000000000000000000035561365710425400155710ustar00rootroot00000000000000/** * Temporary - The lord of tmp. * * Author: Veselin Todorov * Licensed under the MIT License. */ /** * Dependencies. */ var fs = require('fs'); var path = require('path'); var generator = require('./generator'); var detector = require('./detector'); /** * Base constructor. * * @param {String|null} name */ function Base(name) { this.init(name); } /** * Initializes the class. * * @param {String|null} name * @param {Object} [options] Overrides * @param {Boolean} [options.generator] - Custom filename generator */ Base.prototype.init = function(name, options) { options = options || {}; var filename; if (options.generator) { filename = options.generator(name); } else if (options.generator === false) { filename = name; } else { filename = generator.build(name); } this.create(filename); this.path = filename; }; /** * Converts the arguments object to array and * append `this.path` as first element. * * @returns {Array} */ Base.prototype.prepareArgs = function(args, defaults) { args = Array.prototype.slice.call(args); if (defaults) { args = args.concat(defaults.splice(args.length)); } args.unshift(this.path); return args; }; /** * Renames the dir/file. * * @param {String} name * @param {Function} cb Callback. */ Base.prototype.rename = function(name, cb) { var self = this; var args = arguments; var tmp = path.normalize(path.dirname(self.path) + '/' + name); fs.rename(this.path, tmp, function(err) { self.path = tmp; if (args.length === 2) cb(err); }); }; /** * Renames the dir/file sync. * * @param {String} name */ Base.prototype.renameSync = function(name) { var tmp = path.normalize(path.dirname(this.path) + '/' + name); var result = fs.renameSync(this.path, tmp); this.path = tmp; return result; }; /** * Exporting the lib. */ module.exports = Base; temporary-1.1.0/lib/detector.js000066400000000000000000000027211365710425400164610ustar00rootroot00000000000000/** * Temporary - The lord of tmp. * * Author: Veselin Todorov * Licensed under the MIT License. */ /** * Detection stolen from NPM (https://github.com/isaacs/npm/) * * Copyright 2009, 2010, 2011 Isaac Z. Schlueter (the "Author") * MIT License (https://github.com/isaacs/npm/blob/master/LICENSE) */ /** * Detector namespace. * * @type {Object} */ var detector = module.exports; var normalize = function(path) { var last = path[path.length - 1]; if (detector.platform() !== "win32") { if (last !== '/') { path += '/'; } } else { //This is fine b/c Windows will //correctly resolve filepaths with additional slashes //and it is not correct to assume that on Windows the value //of path will be a string that terminates in '\'. // //See: http://stackoverflow.com/questions/4158597/extra-slashes-in-path-variable-of-file-copy-or-directory-createdirectory-met // path += '/'; } return path; } /** * Returns tmp dir. Thank you npm. * * @returns {String} tmp dir. */ detector.tmp = function() { var temp = process.env.TMPDIR || process.env.TMP || process.env.TEMP || (detector.platform() === "win32" ? "c:\\windows\\temp\\" : "/tmp/") return normalize(temp); }; /** * Returns the platform. Allows Tests to verify all behaviors. * * @returns {String} platform. */ detector.platform = function() { return process.platform; }; detector._normalize = normalize; temporary-1.1.0/lib/dir.js000066400000000000000000000021171365710425400154250ustar00rootroot00000000000000/** * Temporary - The lord of tmp. * * Author: Veselin Todorov * Licensed under the MIT License. */ /** * Dependencies. */ var fs = require('fs'); var path = require('path'); var generator = require('./generator'); var detector = require('./detector'); var Base = require('./base'); /** * Dir constructor. * * @param {String|null} name * @param {Object} [options] Overrides for directory naming */ function Dir(name, options) { this.init(name, options); } /** * Dir extends from tmp. */ Dir.prototype.__proto__ = Base.prototype; /** * Creates new file. * * @param {String} dirname */ Dir.prototype.create = function(dirname) { return fs.mkdirSync(path.normalize(dirname), 0700); //0700 we can read,write and execute }; /** * Asynchronous dir. */ Dir.prototype.rmdir = function() { fs.rmdir.apply(fs, this.prepareArgs(arguments, [function(err) {throw Error(err)}])); }; /** * Synchronous rmdir. */ Dir.prototype.rmdirSync = function() { return fs.rmdirSync.apply(fs, this.prepareArgs(arguments)); }; /** * Exporting the lib. */ module.exports = Dir; temporary-1.1.0/lib/file.js000066400000000000000000000045351365710425400155740ustar00rootroot00000000000000/** * Temporary - The lord of tmp. * * Author: Veselin Todorov * Licensed under the MIT License. */ /** * Dependencies. */ var fs = require('fs'); var path = require('path'); var generator = require('./generator'); var detector = require('./detector'); var Base = require('./base'); /** * File constructor. * * @param {String|null} name */ function File(name) { this.init(name); }; /** * File extends from tmp. */ File.prototype.__proto__ = Base.prototype; /** * Creates new file. * * @param {String} filename */ File.prototype.create = function(filename) { return fs.writeFileSync(path.normalize(filename), '',{mode:0600}); //Go use 0600 mode for file, see ref: https://golang.org/src/io/ioutil/tempfile.go }; /** * Asynchronously reads the entire contents of a file. */ File.prototype.readFile = function() { fs.readFile.apply(fs, this.prepareArgs(arguments, [function(err) {throw Error(err)}])); }; /** * Synchronous read. */ File.prototype.readFileSync = function() { return fs.readFileSync.apply(fs, this.prepareArgs(arguments)); }; /** * Asynchronously writes data to a file. */ File.prototype.writeFile = function() { fs.writeFile.apply(fs, this.prepareArgs(arguments, [{}, function(err) {throw Error(err)}])); }; /** * Synchronous writes data to a file. */ File.prototype.writeFileSync = function() { return fs.writeFileSync.apply(fs, this.prepareArgs(arguments)); }; /** * Asynchronous file open. */ File.prototype.open = function() { fs.open.apply(fs, this.prepareArgs(arguments, [function(err) {throw Error(err)}])); }; /** * Synchronous open. */ File.prototype.openSync = function() { return fs.openSync.apply(fs, this.prepareArgs(arguments)); }; /** * Asynchronous close. */ File.prototype.close = function() { fs.close.apply(fs, Array.prototype.slice.call(arguments, [function(err) {throw Error(err)}])); }; /** * Synchronous close. */ File.prototype.closeSync = function() { return fs.closeSync.apply(fs, Array.prototype.slice.call(arguments)); }; /** * Asynchronous unlink. */ File.prototype.unlink = function() { fs.unlink.apply(fs, this.prepareArgs(arguments, [function(err) {throw Error(err)}])); }; /** * Synchronous unlink. */ File.prototype.unlinkSync = function() { return fs.unlinkSync.apply(fs, this.prepareArgs(arguments)); }; /** * Exporting the lib. */ module.exports = File; temporary-1.1.0/lib/generator.js000066400000000000000000000015201365710425400166320ustar00rootroot00000000000000/** * Temporary - The lord of tmp. * * Author: Veselin Todorov * Licensed under the MIT License. */ /** * Dependencies. */ var fs = require('fs'); var path = require('path'); var detector = require('./detector'); var existsSync = fs.existsSync || path.existsSync; /** * Generator namespace. * * @type {Object} */ var generator = module.exports; /** * Generates random name. * * @returns {String} */ generator.name = function() { var id = null; var tmp = detector.tmp(); do { id = Date.now() + Math.random(); } while(existsSync(tmp + '/' + id)); return id + ''; }; /** * Buld a full name. (tmp dir + name). * * @param {String} name * @returns {String} */ generator.build = function(name) { var filename = detector.tmp(); if (name) filename += name + '.'; return filename + this.name(); }; temporary-1.1.0/package-lock.json000066400000000000000000000314501365710425400167610ustar00rootroot00000000000000{ "name": "temporary", "version": "1.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { "@sinonjs/commons": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.3.0.tgz", "integrity": "sha512-j4ZwhaHmwsCb4DlDOIWnI5YyKDNMoNThsmwEpfHx6a1EpsGZ9qYLxP++LMlmBRjtGptGHFsGItJ768snllFWpA==", "dev": true, "requires": { "type-detect": "4.0.8" } }, "@sinonjs/formatio": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/@sinonjs/formatio/-/formatio-3.1.0.tgz", "integrity": "sha512-ZAR2bPHOl4Xg6eklUGpsdiIJ4+J1SNag1DHHrG/73Uz/nVwXqjgUtRPLoS+aVyieN9cSbc0E4LsU984tWcDyNg==", "dev": true, "requires": { "@sinonjs/samsam": "^2 || ^3" } }, "@sinonjs/samsam": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-3.0.2.tgz", "integrity": "sha512-m08g4CS3J6lwRQk1pj1EO+KEVWbrbXsmi9Pw0ySmrIbcVxVaedoFgLvFsV8wHLwh01EpROVz3KvVcD1Jmks9FQ==", "dev": true, "requires": { "@sinonjs/commons": "^1.0.2", "array-from": "^2.1.1", "lodash.get": "^4.4.2" } }, "array-from": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/array-from/-/array-from-2.1.1.tgz", "integrity": "sha1-z+nYwmYoudxa7MYqn12PHzUsEZU=", "dev": true }, "assertion-error": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", "dev": true }, "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", "dev": true }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", "dev": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" } }, "browser-stdout": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz", "integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==", "dev": true }, "chai": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/chai/-/chai-4.2.0.tgz", "integrity": "sha512-XQU3bhBukrOsQCuwZndwGcCVQHyZi53fQ6Ys1Fym7E4olpIqqZZhhoFJoaKVvV17lWQoXYwgWN2nF5crA8J2jw==", "dev": true, "requires": { "assertion-error": "^1.1.0", "check-error": "^1.0.2", "deep-eql": "^3.0.1", "get-func-name": "^2.0.0", "pathval": "^1.1.0", "type-detect": "^4.0.5" } }, "check-error": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz", "integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=", "dev": true }, "commander": { "version": "2.15.1", "resolved": "https://registry.npmjs.org/commander/-/commander-2.15.1.tgz", "integrity": "sha512-VlfT9F3V0v+jr4yxPc5gg9s62/fIVWsd2Bk2iD435um1NlGMYdVCq+MjcXnhYq2icNOizHr1kK+5TI6H0Hy0ag==", "dev": true }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", "dev": true }, "debug": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", "dev": true, "requires": { "ms": "2.0.0" } }, "deep-eql": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-3.0.1.tgz", "integrity": "sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==", "dev": true, "requires": { "type-detect": "^4.0.0" } }, "diff": { "version": "3.5.0", "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==", "dev": true }, "escape-string-regexp": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", "dev": true }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", "dev": true }, "get-func-name": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz", "integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=", "dev": true }, "glob": { "version": "7.1.2", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", "dev": true, "requires": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", "inherits": "2", "minimatch": "^3.0.4", "once": "^1.3.0", "path-is-absolute": "^1.0.0" } }, "growl": { "version": "1.10.5", "resolved": "https://registry.npmjs.org/growl/-/growl-1.10.5.tgz", "integrity": "sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA==", "dev": true }, "has-flag": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", "dev": true }, "he": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz", "integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=", "dev": true }, "inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", "dev": true, "requires": { "once": "^1.3.0", "wrappy": "1" } }, "inherits": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", "dev": true }, "isarray": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=", "dev": true }, "just-extend": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-4.0.2.tgz", "integrity": "sha512-FrLwOgm+iXrPV+5zDU6Jqu4gCRXbWEQg2O3SKONsWE4w7AXFRkryS53bpWdaL9cNol+AmR3AEYz6kn+o0fCPnw==", "dev": true }, "lodash.get": { "version": "4.4.2", "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", "integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=", "dev": true }, "lolex": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/lolex/-/lolex-3.0.0.tgz", "integrity": "sha512-hcnW80h3j2lbUfFdMArd5UPA/vxZJ+G8vobd+wg3nVEQA0EigStbYcrG030FJxL6xiDDPEkoMatV9xIh5OecQQ==", "dev": true }, "minimatch": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", "dev": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "0.0.8", "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", "dev": true }, "mkdirp": { "version": "0.5.1", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", "dev": true, "requires": { "minimist": "0.0.8" } }, "mocha": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/mocha/-/mocha-5.2.0.tgz", "integrity": "sha512-2IUgKDhc3J7Uug+FxMXuqIyYzH7gJjXECKe/w43IGgQHTSj3InJi+yAA7T24L9bQMRKiUEHxEX37G5JpVUGLcQ==", "dev": true, "requires": { "browser-stdout": "1.3.1", "commander": "2.15.1", "debug": "3.1.0", "diff": "3.5.0", "escape-string-regexp": "1.0.5", "glob": "7.1.2", "growl": "1.10.5", "he": "1.1.1", "minimatch": "3.0.4", "mkdirp": "0.5.1", "supports-color": "5.4.0" } }, "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", "dev": true }, "nise": { "version": "1.4.8", "resolved": "https://registry.npmjs.org/nise/-/nise-1.4.8.tgz", "integrity": "sha512-kGASVhuL4tlAV0tvA34yJYZIVihrUt/5bDwpp4tTluigxUr2bBlJeDXmivb6NuEdFkqvdv/Ybb9dm16PSKUhtw==", "dev": true, "requires": { "@sinonjs/formatio": "^3.1.0", "just-extend": "^4.0.2", "lolex": "^2.3.2", "path-to-regexp": "^1.7.0", "text-encoding": "^0.6.4" }, "dependencies": { "lolex": { "version": "2.7.5", "resolved": "https://registry.npmjs.org/lolex/-/lolex-2.7.5.tgz", "integrity": "sha512-l9x0+1offnKKIzYVjyXU2SiwhXDLekRzKyhnbyldPHvC7BvLPVpdNUNR2KeMAiCN2D/kLNttZgQD5WjSxuBx3Q==", "dev": true } } }, "once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", "dev": true, "requires": { "wrappy": "1" } }, "path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", "dev": true }, "path-to-regexp": { "version": "1.7.0", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.7.0.tgz", "integrity": "sha1-Wf3g9DW62suhA6hOnTvGTpa5k30=", "dev": true, "requires": { "isarray": "0.0.1" } }, "pathval": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz", "integrity": "sha1-uULm1L3mUwBe9rcTYd74cn0GReA=", "dev": true }, "sinon": { "version": "7.2.3", "resolved": "https://registry.npmjs.org/sinon/-/sinon-7.2.3.tgz", "integrity": "sha512-i6j7sqcLEqTYqUcMV327waI745VASvYuSuQMCjbAwlpAeuCgKZ3LtrjDxAbu+GjNQR0FEDpywtwGCIh8GicNyg==", "dev": true, "requires": { "@sinonjs/commons": "^1.3.0", "@sinonjs/formatio": "^3.1.0", "@sinonjs/samsam": "^3.0.2", "diff": "^3.5.0", "lolex": "^3.0.0", "nise": "^1.4.8", "supports-color": "^5.5.0" }, "dependencies": { "supports-color": { "version": "5.5.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", "dev": true, "requires": { "has-flag": "^3.0.0" } } } }, "supports-color": { "version": "5.4.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.4.0.tgz", "integrity": "sha512-zjaXglF5nnWpsq470jSv6P9DwPvgLkuapYmfDm3JWOm0vkNTVF2tI4UrN2r6jH1qM/uc/WtxYY1hYoA2dOKj5w==", "dev": true, "requires": { "has-flag": "^3.0.0" } }, "text-encoding": { "version": "0.6.4", "resolved": "https://registry.npmjs.org/text-encoding/-/text-encoding-0.6.4.tgz", "integrity": "sha1-45mpgiV6J22uQou5KEXLcb3CbRk=", "dev": true }, "type-detect": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", "dev": true }, "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", "dev": true } } } temporary-1.1.0/package.json000066400000000000000000000011431365710425400160270ustar00rootroot00000000000000{ "name": "temporary", "version": "1.1.0", "description": "The lord of tmp.", "keywords": [ "tmp", "temp", "tempfile", "tempdirectory" ], "contrubutors": [ "Veselin Todorov ", "Will Soctt " ], "license": "MIT", "devDependencies": { "mocha": "5.2.0", "chai": "*", "sinon": "7.2.3" }, "repository": { "type": "git", "url": "https://github.com/vesln/temporary.git" }, "homepage": "https://github.com/vesln/temporary", "scripts": { "test": "mocha --reporter spec test/*.test.js" }, "main": "index" } temporary-1.1.0/test/000077500000000000000000000000001365710425400145215ustar00rootroot00000000000000temporary-1.1.0/test/base.test.js000066400000000000000000000030011365710425400167410ustar00rootroot00000000000000/** * Temporary - The lord of tmp. * * Author: Veselin Todorov * Licensed under the MIT License. */ /** * Dependencies. */ var path = require('path'); var fs = require('fs'); var existsSync = fs.existsSync || path.existsSync; var Base = require('../lib/base'); var generator = require('../lib/generator'); var should = require('chai').should(); Base.prototype.create = function() {}; describe('Base', function() { describe('rename', function() { it('should rename the directory', function(done) { var tmp = new Base; tmp.path = generator.build(); fs.mkdirSync(path.normalize(tmp.path), 0777); existsSync(tmp.path).should.be.ok; tmp.rename('foo', function(err) { existsSync(tmp.path).should.be.ok; done(); }); }); }); describe('renameSync', function() { it('should rename the directory', function() { var tmp = new Base('foo'); tmp.path = generator.build(); fs.mkdirSync(path.normalize(tmp.path), 0777); var oldPath = tmp.path; existsSync(tmp.path).should.be.ok; tmp.renameSync('foo3'); existsSync(tmp.path).should.be.ok; path.should.not.eql(oldPath); }); }); describe('prepareArgs', function() { it('should convert object to array and append path as first element', function() { var tmp = new Base('foo'); var args = { 0: 'foo' }; args.length = 1; tmp.path = generator.build(); tmp.prepareArgs(args).should.eql([tmp.path, 'foo']); }); }); }); temporary-1.1.0/test/detector.test.js000066400000000000000000000023161365710425400176500ustar00rootroot00000000000000/** * Temporary - The lord of tmp. * * Author: Veselin Todorov * Licensed under the MIT License. */ /** * Dependencies. */ var detector = require('../lib/detector'); var should = require('chai').should(); describe('detector', function() { describe('tmp', function() { it('should return the tmp dir of the system', function() { var tmp = process.env.TMPDIR || process.env.TMP || process.env.TEMP || (process.platform === "win32" ? "c:\\windows\\temp\\" : "/tmp/"); detector.tmp().should.eql(tmp); }); it('should normalize windows paths correctly', function () { var platform_noConflict = detector.platform; detector.platform = function() { return 'win32'; }; detector._normalize('c:\\windows\\foo\\bar\\') .should.eql('c:\\windows\\foo\\bar\\/'); detector._normalize('c:/windows/foo/bar/') .should.eql('c:/windows/foo/bar//'); detector._normalize('c:/windows/foo/bar') .should.eql('c:/windows/foo/bar/'); detector._normalize('c:\\windows\\foo\\bar') .should.eql('c:\\windows\\foo\\bar/'); detector.platform = platform_noConflict; }); }); }); temporary-1.1.0/test/dir.test.js000066400000000000000000000030631365710425400166150ustar00rootroot00000000000000/** * Temporary - The lord of tmp. * * Author: Veselin Todorov * Licensed under the MIT License. */ /** * Dependencies. */ var fs = require('fs'); var path = require('path'); var existsSync = fs.existsSync || path.existsSync; var Tempdir = require('../lib/dir'); var sinon = require('sinon'); require('chai').should(); describe('Tempdir', function() { it('should create file', function() { var tmp = new Tempdir('foo'); existsSync(tmp.path).should.be.ok; }); it('should use the directory name as the path when generator option equals false', function () { var tmp = new Tempdir('foo', { generator: false }); existsSync(tmp.path).should.be.ok; (tmp.path).should.be.equal('foo'); tmp.rmdirSync(); }); it('should use the custom generator if supplied', function() { var spy = sinon.spy(function(name) { return name; }); var tmp = new Tempdir('foo', { generator: spy }); (spy.called).should.be.ok; tmp.rmdirSync(); }); describe('rmdir', function() { it('should remove the directory', function() { var tmp = new Tempdir('foo'); sinon.spy(fs, 'rmdir'); tmp.rmdir(function() {}); fs.rmdir.getCall(0).args[0].should.eql(tmp.path); fs.rmdir.restore(); }); }); describe('rmdirSync', function() { it('should remove the directory', function() { var tmp = new Tempdir('foo'); sinon.spy(fs, 'rmdirSync'); tmp.rmdirSync(); fs.rmdirSync.getCall(0).args[0].should.eql(tmp.path); fs.rmdirSync.restore(); }); }); }); temporary-1.1.0/test/file.test.js000066400000000000000000000064771365710425400167720ustar00rootroot00000000000000/** * Temporary - The lord of tmp. * * Author: Veselin Todorov * Licensed under the MIT License. */ /** * Dependencies. */ var path = require('path'); var fs = require('fs'); var existsSync = fs.existsSync || path.existsSync; var Tempfile = require('../lib/file'); var sinon = require('sinon'); var should = require('chai').should(); describe('Tempfile', function() { it('should create file', function() { var tmp = new Tempfile('foo'); existsSync(tmp.path).should.be.ok; }); describe('readFile', function() { it('should call fs.readfile', function() { sinon.spy(fs, 'readFile'); var tmp = new Tempfile; tmp.readFile(function() {}); fs.readFile.getCall(0).args[0].should.eql(tmp.path); fs.readFile.restore(); }); }); describe('readFileSync', function() { it('should call fs.readfileSync', function() { sinon.spy(fs, 'readFileSync'); var tmp = new Tempfile; tmp.readFileSync(); fs.readFileSync.getCall(0).args[0].should.eql(tmp.path); fs.readFileSync.restore(); }); }); describe('writeFile', function() { it('should call fs.readfile', function() { sinon.spy(fs, 'writeFile'); var tmp = new Tempfile; tmp.writeFile({}, function() {}); fs.writeFile.getCall(0).args[0].should.eql(tmp.path); fs.writeFile.restore(); }); }); describe('writeFileSync', function() { it('should call fs.writeFileSync', function() { sinon.spy(fs, 'writeFileSync'); var tmp = new Tempfile; tmp.writeFileSync(); fs.writeFileSync.getCall(0).args[0].should.eql(tmp.path); fs.writeFileSync.restore(); }); }); describe('open', function() { it('should call fs.open', function() { sinon.spy(fs, 'open'); var tmp = new Tempfile; tmp.open('r', function() {}); fs.open.getCall(0).args[0].should.eql(tmp.path); fs.open.restore(); }); }); describe('openSync', function() { it('should call fs.openSync', function() { sinon.spy(fs, 'openSync'); var tmp = new Tempfile; tmp.openSync('r'); fs.openSync.getCall(0).args[0].should.eql(tmp.path); fs.openSync.restore(); }); }); describe('close', function() { it('should call fs.close', function() { sinon.spy(fs, 'close'); var tmp = new Tempfile; var fd = tmp.openSync('r'); tmp.close(fd, function() {}); fs.close.getCall(0).args[0].should.eql(fd); fs.close.restore(); }); }); describe('closeSync', function() { it('should call fs.closeSync', function() { sinon.spy(fs, 'closeSync'); var tmp = new Tempfile; var fd = tmp.openSync('r'); tmp.closeSync(fd); fs.closeSync.getCall(0).args[0].should.eql(fd); fs.closeSync.restore(); }); }); describe('unlink', function() { it('should call fs.unlink', function() { sinon.spy(fs, 'unlink'); var tmp = new Tempfile; tmp.unlink(function() {}); fs.unlink.getCall(0).args[0].should.eql(tmp.path); fs.unlink.restore(); }); }); describe('unlinkSync', function() { it('should call fs.readfileSync', function() { sinon.spy(fs, 'unlinkSync'); var tmp = new Tempfile; tmp.unlinkSync(); fs.unlinkSync.getCall(0).args[0].should.eql(tmp.path); fs.unlinkSync.restore(); }); }); }); temporary-1.1.0/test/generator.test.js000066400000000000000000000012701365710425400200230ustar00rootroot00000000000000/** * Temporary - The lord of tmp. * * Author: Veselin Todorov * Licensed under the MIT License. */ /** * Dependencies. */ var generator = require('../lib/generator'); var detector = require('../lib/detector'); var should = require('chai').should(); describe('generator', function() { describe('name', function() { it('should unique generate name', function() { generator.name().should.be.ok; }); }); describe('build', function() { it('should build full names', function() { var tmp = detector.tmp(); generator.build().indexOf(tmp).should.equal(0); generator.build('foo').indexOf(tmp + 'foo.').should.equal(0); }); }); });