lib/extends/_filesToFile.js
function _filesToFile (files, target, separator, callback) {

			if ("undefined" === typeof files) {
				throw new ReferenceError("missing \"files\" argument");
			}
				else if ("object" !== typeof files || !(files instanceof Array)) {
					throw new TypeError("\"files\" argument is not an Array");
				}
			else if ("undefined" === typeof target) {
				throw new ReferenceError("missing \"target\" argument");
			}
				else if ("string" !== typeof target) {
					throw new TypeError("\"target\" argument is not a string");
				}
			else if ("undefined" === typeof callback && "undefined" === typeof separator) {
				throw new ReferenceError("missing \"callback\" argument");
			}
				else if ("function" !== typeof callback && "function" !== typeof separator) {
					throw new TypeError("\"callback\" argument is not a function");
				}
			else {

				const _target = target.trim();

				if ("" === _target) {
					throw new Error("\"target\" argument is empty");
				}
				else {

					const _callback = "undefined" === typeof callback ? separator : callback;

					Promise.resolve().then(() => {
						return isFileProm(_target);
					}).then((exists) => {

						return !exists ? Promise.resolve() : new Promise((resolve, reject) => {

							fs.unlink(_target, (err) => {
								return err ? reject(err) : resolve();
							});

						});

					}).then(() => {

						if (!files.length) {

							return new Promise((resolve, reject) => {

								fs.writeFile(_target, "", (err) => {
									return err ? reject(err) : resolve();
								});

							});

						}
						else {

							return filesToStreamProm(files, "string" === typeof separator ? separator : " ").then((readStream) => {

								return new Promise((resolve, reject) => {

									let error = false;
									readStream.once("error", (_err) => {
										error = true; reject(_err);
									}).pipe(fs.createWriteStream(_target, { "flags": "a" }).once("error", (_err) => {
										error = true; reject(_err);
									}).once("close", () => {

										if (!error) {
											resolve();
										}

									}));

								});

							});

						}

					}).then(() => {
						_callback(null);
					}).catch(_callback);

				}

			}

		}
function _filesToFile (files, target, separator, callback) {

			if ("undefined" === typeof files) {
				throw new ReferenceError("missing \"files\" argument");
			}
				else if ("object" !== typeof files || !(files instanceof Array)) {
					throw new TypeError("\"files\" argument is not an Array");
				}
			else if ("undefined" === typeof target) {
				throw new ReferenceError("missing \"target\" argument");
			}
				else if ("string" !== typeof target) {
					throw new TypeError("\"target\" argument is not a string");
				}
			else if ("undefined" === typeof callback && "undefined" === typeof separator) {
				throw new ReferenceError("missing \"callback\" argument");
			}
				else if ("function" !== typeof callback && "function" !== typeof separator) {
					throw new TypeError("\"callback\" argument is not a function");
				}
			else {

				const _target = target.trim();

				if ("" === _target) {
					throw new Error("\"target\" argument is empty");
				}
				else {

					const _callback = "undefined" === typeof callback ? separator : callback;

					Promise.resolve().then(() => {
						return isFileProm(_target);
					}).then((exists) => {

						return !exists ? Promise.resolve() : new Promise((resolve, reject) => {

							fs.unlink(_target, (err) => {
								return err ? reject(err) : resolve();
							});

						});

					}).then(() => {

						if (!files.length) {

							return new Promise((resolve, reject) => {

								fs.writeFile(_target, "", (err) => {
									return err ? reject(err) : resolve();
								});

							});

						}
						else {

							return filesToStreamProm(files, "string" === typeof separator ? separator : " ").then((readStream) => {

								return new Promise((resolve, reject) => {

									let error = false;
									readStream.once("error", (_err) => {
										error = true; reject(_err);
									}).pipe(fs.createWriteStream(_target, { "flags": "a" }).once("error", (_err) => {
										error = true; reject(_err);
									}).once("close", () => {

										if (!error) {
											resolve();
										}

									}));

								});

							});

						}

					}).then(() => {
						_callback(null);
					}).catch(_callback);

				}

			}

		}
function _filesToFile ( files , target , separator , callback ) { if ( "undefined" === typeof files ) { throw new ReferenceError ( "missing \"files\" argument" ) ; } else if ( "object" !== typeof files || ! ( files instanceof Array ) ) { throw new TypeError ( "\"files\" argument is not an Array" ) ; } else if ( "undefined" === typeof target ) { throw new ReferenceError ( "missing \"target\" argument" ) ; } else if ( "string" !== typeof target ) { throw new TypeError ( "\"target\" argument is not a string" ) ; } else if ( "undefined" === typeof callback && "undefined" === typeof separator ) { throw new ReferenceError ( "missing \"callback\" argument" ) ; } else if ( "function" !== typeof callback && "function" !== typeof separator ) { throw new TypeError ( "\"callback\" argument is not a function" ) ; } else { const _target = target . trim ( ) ; if ( "" === _target ) { throw new Error ( "\"target\" argument is empty" ) ; } else { const _callback = "undefined" === typeof callback ? separator : callback ; Promise . resolve ( ) . then ( ( ) => { return isFileProm ( _target ) ; } ) . then ( ( exists ) => { return ! exists ? Promise . resolve ( ) : new Promise ( ( resolve , reject ) => { fs . unlink ( _target , ( err ) => { return err ? reject ( err ) : resolve ( ) ; } ) ; } ) ; } ) . then ( ( ) => { if ( ! files . length ) { return new Promise ( ( resolve , reject ) => { fs . writeFile ( _target , "" , ( err ) => { return err ? reject ( err ) : resolve ( ) ; } ) ; } ) ; } else { return filesToStreamProm ( files , "string" === typeof separator ? separator : " " ) . then ( ( readStream ) => { return new Promise ( ( resolve , reject ) => { let error = false ; readStream . once ( "error" , ( _err ) => { error = true ; reject ( _err ) ; } ) . pipe ( fs . createWriteStream ( _target , { "flags" : "a" } ) . once ( "error" , ( _err ) => { error = true ; reject ( _err ) ; } ) . once ( "close" , ( ) => { if ( ! error ) { resolve ( ) ; } } ) ) ; } ) ; } ) ; } } ) . then ( ( ) => { _callback ( null ) ; } ) . catch ( _callback ) ; } } }
methods 
Async filesToFile
@param {Array} files : files to read
@param {string} target : file to write in
@param {string} separator : files separator
@param {function|null} callback : operation's result
@returns {void}
methods Async filesToFile