0.6.12 • Published 2 years ago

@zguillez/z-file v0.6.12

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

z-file

npm version Build Status Installs Gitter

Zguillez | Guillermo de la Iglesia

Nodejs tools for file streams

Getting Started

Install

npm i @zguillez/z-file
yarn add @zguillez/z-file

Usage

const zfile = require('z-file');

Read file

zfile.read('./src/data.csv').then((data) => {
  console.log(data);
});

Write file

Will create the path folders if not exits.

zfile.write('./src/data.csv', data).then((data) => {
  console.log(data);
});

Replace string in file

Will create the path folders if not exits.

file.replace('./package.json', '0.4.2', '0.4.3');

Check if folder exists

console.log( zfile.folder('./src/data') ); //true or false

Create folder if not exists

console.log( zfile.folder('./src/data', true) ); //true

Check if file exists

console.log( zfile.file('./src/data.txt') ); //true or false

Create file if not exists

console.log( zfile.file('./src/data.txt', true) ); //true

Remove all files in a folder

console.log( zfile.clean('./src/data') );
console.log( zfile.clean(['./src/data', './src/assets']) );

Remove a folder

console.log( zfile.remove('./src/data') );
console.log( zfile.remove(['./src/data', './src/assets']) );

Use as object

let f1 = zfile.create('./data/file.txt');
f1.data = 'Hello world!;
f1.save();

let f2 = zfile.create();
f2.load(f1.path).then(() => {
  f2.data = 'Bye wold!';
  f2.save()
});

Creating new file and load content from existing file

let f = zfile.create('./src/newfile.csv');
f.load('./src/oldfile.csv').then(() => {
  f.save().then(() => {
    console.log(f.path); //file is saved on './src/newfile.csv'
  });
});

Saving as a new file

let f = zfile.create();
f.load('./src/file.csv').then(() => {
  f.save('./src/newfile.csv').then(() => {
    console.log(f.path); //file is saved on './src/newfile.csv'
  });
});

Tools

Read files on folder

zfile.files('./data').forEach((file) => {
    console.log(file);
  });

Read folders on folder

zfile.folders('./data').forEach((folder) => {
    console.log(folder);
  });

Create a PNG image from a PSD file

zfile.psdToPng('300x250.psd', '300x250.png')
  .then(() => console.log('Done!'))
  .catch((err) => console.log(err));

Create a JPEG image from a PSD file

zfile.psdToJpg('300x250.psd', '300x250.jpg', 80)
  .then(() => console.log('Done!'))
  .catch((err) => console.log(err));

Create a dummy JPEG or GIF image

zfile.dummy(300, 250, '#FF2200', 'dummy.jpg');
zfile.dummy(300, 250, '#FF2200', 'dummy.gif');

Contributing and issues

Contributors are welcome, please fork and send pull requests! If you have any ideas on how to make this project better then please submit an issue or send me an email.

License

©2018 Zguillez.io

Original code licensed under MIT Open Source projects used within this project retain their original licenses.

Changelog

v0.5.0 (November 25, 2018)

  • Create PNG and JPEG images from PSD file
  • Create dummy JPEG and GIF images

v0.4.0 (November 20, 2018)

  • Replace string on files function

v0.3.0 (January 27, 2017)

  • Read files and folders functions

v0.2.0 (January 21, 2017)

  • Core update with ES6 classes

v0.1.0 (January 12, 2017)

  • Basic implementation for file