🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

postcss-hash

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-hash - npm Package Compare versions

Comparing version

to
1.0.1

45

index.js

@@ -1,22 +0,27 @@

'use strict';
"use strict";
const { readFile, writeFile } = require('fs');
const postcss = require('postcss');
const utils = require('./utils');
const readFileAsync = (file, enc) => new Promise((res, rej) => {
readFile(file, enc, (err, val) => err ? rej(err) : res(val));
});
const writeFileAsync = (file, data, enc) => new Promise((res, rej) => {
writeFile(file, data, enc, (err, val) => err ? rej(err) : res(val));
});
const { readFile, writeFile } = require("fs");
const postcss = require("postcss");
const utils = require("./utils");
const readFileAsync = (file, enc) =>
new Promise((res, rej) => {
readFile(file, enc, (err, val) => (err ? rej(err) : res(val)));
});
const writeFileAsync = (file, data, enc) =>
new Promise((res, rej) => {
writeFile(file, data, enc, (err, val) => (err ? rej(err) : res(val)));
});
module.exports = postcss.plugin('postcss-hash', (opts) => {
opts = Object.assign({
algorithm: 'md5',
trim: 10,
manifest: './manifest.json',
name: utils.defaultName
}, opts);
module.exports = postcss.plugin("postcss-hash", opts => {
opts = Object.assign(
{
algorithm: "md5",
trim: 10,
manifest: "./manifest.json",
name: utils.defaultName
},
opts
);
return function (root, result) {
return function(root, result) {
// replace filename

@@ -28,8 +33,8 @@ const originalName = result.opts.to;

const newData = utils.data(originalName, result.opts.to);
return readFileAsync(opts.manifest, 'utf-8')
return readFileAsync(opts.manifest, "utf-8")
.then(JSON.parse, () => ({}))
.then(oldData => Object.assign(oldData, newData))
.then(obj => JSON.stringify(obj, null, 2))
.then(data => writeFileAsync(opts.manifest, data, 'utf-8'));
.then(data => writeFileAsync(opts.manifest, data, "utf-8"));
};
});
{
"name": "postcss-hash",
"version": "1.0.0",
"version": "1.0.1",
"description": "PostCSS plugin to replace output file names with HASH algorithms (md5, sha256, sha512, etc) and string length of your choice - for cache busting",

@@ -42,3 +42,3 @@ "keywords": [

"jest": "^23.6.0",
"mock-fs": "^4.7.0"
"prettier": "^1.14.2"
},

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

@@ -1,3 +0,3 @@

const crypto = require('crypto');
const path = require('path');
const crypto = require("crypto");
const path = require("path");

@@ -10,11 +10,10 @@ /*

return crypto
.createHash(algorithm)
.update(css)
.digest('hex')
.substr(0, trim);
.createHash(algorithm)
.update(css)
.digest("hex")
.substr(0, trim);
}
function defaultName(parts) {
return path.join(parts.dir, parts.name + '.' + parts.hash + parts.ext);
return path.join(parts.dir, parts.name + "." + parts.hash + parts.ext);
}

@@ -29,3 +28,3 @@

dir: path.dirname(file),
name : path.basename(file, path.extname(file)),
name: path.basename(file, path.extname(file)),
ext: path.extname(file),

@@ -32,0 +31,0 @@ hash: hash(css, opts.algorithm, opts.trim)