Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

utilsac

Package Overview
Dependencies
Maintainers
1
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

utilsac - npm Package Compare versions

Comparing version 5.5.0 to 6.0.0

tests/files-test.js

44

files.js
/*files.js*/
"use strict";
const fs = require("fs");
const path = require("path");
const textFileContentPromiseFromPath = function (path) {
const createNecessaryDirectories = function (filePath) {
const directoryname = path.dirname(filePath);
if (fs.existsSync(directoryname)) {
return;
}
createNecessaryDirectories(directoryname);
fs.mkdirSync(directoryname);
};
const textFileContentPromiseFromPath = function (filePath) {
return new Promise(function (resolve, reject) {
fs.readFile(path, "utf-8", function (error, data) {
fs.readFile(filePath, "utf-8", function (error, data) {
if (error) {

@@ -16,5 +26,6 @@ reject(error);

const writeTextInFilePromiseFromPathAndString = function (path, string) {
const writeTextInFilePromiseFromPathAndString = function (filePath, string) {
return new Promise(function (resolve, reject) {
fs.writeFile(path, string, "utf-8", function (error, notUsed) {
createNecessaryDirectories(filePath);
fs.writeFile(filePath, string, "utf-8", function (error, notUsed) {
if (error) {

@@ -28,24 +39,29 @@ reject(error);

const concatenateFiles = function (files, destination, separator=``) {
return Promise.all(files.map(textFileContentPromiseFromPath)).then(
function (contents) {
return writeTextInFilePromiseFromPathAndString(destination, contents.join(separator))
return writeTextInFilePromiseFromPathAndString(
destination,
contents.join(separator)
);
});
};
};
const copyFile = function (sourcePath, destination) {
/* fs.copyFile exists in Node 9+
const copyFile = function (filePath, filePathDestination) {
/* fs.copyFile exists in Node 9+
todo if dest cannot be reached created folders until it is*/
return new Promise(function (resolve, reject) {
if (!fs.existsSync(sourcePath)) {
reject(`${sourcePath} does not exist`);
if (!fs.existsSync(filePath)) {
reject(`${filePath} does not exist`);
return;
}
fs.copyFile(sourcePath, destination, (err) => {
if (err) {
reject(err);
createNecessaryDirectories(filePathDestination);
fs.copyFile(filePath, filePathDestination, (error) => {
if (error) {
reject(error);
return;
}
resolve(`${sourcePath} was copied to ${destination}`);
resolve(`${filePath} was copied to ${filePathDestination}`);
});

@@ -52,0 +68,0 @@ });

{
"name": "utilsac",
"version": "5.5.0",
"description": "tools mostly",
"version": "6.0.0",
"description": "JavaScript General Purpose utility functions",
"main": "files.js",

@@ -6,0 +6,0 @@ "scripts": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc