1.0.11 • Published 3 years ago

test-file-generator v1.0.11

Weekly downloads
1
License
MIT
Repository
github
Last release
3 years ago

Test file generator

This is a simple module to generate many different random files, which could be used for testing other algorithms that work with files.

Currently supported formats (jpeg, gif, cvs and txt).

ImageGif
alt textalt text

For other examples on random cvs / txt check the exampleOutput folder.

How to use from command line:

npm install -g test-file-generator    

generate --help

generate 

If you want to generate more than one file

generate --number 10

How to use from your project:

  • Install npm install test-file-generator or yarn install test-file-generator
  • Include in your project

import { TestFileGenerator } from 'test-file-generator';
let generator = new TestFileGenerator('txt');
generator.generateFile();
  1. To generate one txt file and random name, at the default path "./".
  let generator = new TestFileGenerator('txt');
  generator.generateFile();
  1. This will generate a gif file with the specified parameters.
  let generator = new TestFileGenerator('gif');
  generator.setLocation('my_path/');
  generator.setImageSize(100, 100);
  generator.setName('my_file_name');
  generator.generateFile();
  1. This will generate a cvs file of 3000 KB.
  let generator = new TestFileGenerator('csv');
  generator.setLocation('output/');
  generator.setSize(3000);
  generator.setName('my_file_name');
  generator.generateFile();

API:

#MethodInput / TypeOutput / TypeDescription
1new TestFileGenerator(type: string, clean?: boolean)required type : string optional name: string optional location: string optional size: number optional clean: booleanTestFileGenerator objectThe constructor of the object. The default values for the optional parameters are: (name = 'random', location = ''./'', size = 20, clean = false), and even though not passed in the constructor for the images is (100, 100). If you want to modify any parameter just use setter methods.
2generateFile()Noneboolean (true if created, false otherwise)This method generates the file with the specified parameters.
3setLocation(location: string)stringNoneThis method sets the location on which the file is going to be written.
4setName(location: string)stringNoneThis method sets the name of the file. If not specified the file will have a random name which you can get with getName().
5setType(type: string)stringNoneThis method sets the file type, currently supported (jpeg, gif, cvs and txt), lowercased.
6setSize(size: number)numberNoneThis method sets the size that the file should have, currently only works for txt and cvs file types.
6setImageSize((x: number, y: number)number, numberNoneThis method sets the size of the jpeg or gif to be generated.
7setClean(location: string)stringNoneThis method deletes the created file after creation (just for writing unit tests).
8getLocation()NonestringThis method gets the file path.
9getName()NonestringThis method gets the file name.
10getSize()NonestringThis method gets the file generation setted size (only for cvs/txt).
11getFileType()NonestringThis method gets the file type.

License

MIT

Issues, errors, requests or contributions

Open an issue here

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago