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

gzipper

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

gzipper - npm Package Compare versions

Comparing version 2.6.0 to 2.7.0

3

index.js

@@ -9,2 +9,3 @@ #!/usr/bin/env node

GZIPPER_VERBOSE,
GZIPPER_EXCLUDE,
GZIPPER_GZIP_LEVEL,

@@ -24,2 +25,3 @@ GZIPPER_GZIP_MEMORY_LEVEL,

.option('-v, --verbose', 'detailed level of logs')
.option('-e, --exclude [exclude]', 'exclude file extensions from compression')
.option(

@@ -68,2 +70,3 @@ '-gl, --gzip-level [level]',

verbose: Boolean(GZIPPER_VERBOSE) || program.verbose,
exclude: GZIPPER_EXCLUDE || program.exclude,
gzipLevel: +GZIPPER_GZIP_LEVEL || +program.gzipLevel,

@@ -70,0 +73,0 @@ gzipMemoryLevel: +GZIPPER_GZIP_MEMORY_LEVEL || +program.gzipMemoryLevel,

10

package.json
{
"name": "gzipper",
"version": "2.6.0",
"version": "2.7.0",
"description": "CLI for compressing files.",

@@ -38,6 +38,6 @@ "main": "index.js",

"@types/commander": "^2.12.2",
"@types/mocha": "^5.2.6",
"@types/node": "^11.13.11",
"@types/mocha": "^5.2.7",
"@types/node": "^11.13.13",
"@types/semver": "^6.0.0",
"@types/sinon": "^7.0.11",
"@types/sinon": "^7.0.12",
"@types/uuid": "^3.4.4",

@@ -50,3 +50,3 @@ "eslint": "^5.16.0",

"prettier": "^1.17.1",
"semver": "^6.0.0",
"semver": "^6.1.1",
"sinon": "^7.3.2"

@@ -53,0 +53,0 @@ },

@@ -59,2 +59,3 @@ # Gzipper

| `-v, --verbose` | `GZIPPER_VERBOSE` | detailed level of logs |
| `-e, --exclude` | `GZIPPER_EXCLUDE` | exclude file extensions from compression |
| `-gl, --gzip-level [level]` | `GZIPPER_GZIP_LEVEL` | gzip compression level -1 (default), 0 (no compression) - 9 (best compression) |

@@ -61,0 +62,0 @@ | `-gm, --gzip-memory-level [memoryLevel]` | `GZIPPER_GZIP_MEMORY_LEVEL` | amount of memory which will be allocated for compression 8 (default), 1 (minimum memory) - 9 (maximum memory) |

@@ -18,2 +18,3 @@ const fs = require('fs')

const getOutputPath = Symbol('getOutputPath')
const getValidExtensions = Symbol('getValidExtensions')

@@ -54,2 +55,3 @@ const stat = util.promisify(fs.stat)

this.createCompression = this.compressionInstance.getCompression()
this.validExtensions = this[getValidExtensions]()
}

@@ -79,3 +81,3 @@

try {
if (VALID_EXTENSIONS.includes(path.extname(filePath))) {
if (this.validExtensions.includes(path.extname(filePath))) {
const hrtimeStart = process.hrtime()

@@ -286,4 +288,23 @@ compressedFiles.push(filePath)

}
/**
* Returns the filtered list of extensions from `options.exclude`.
*
* @returns{string[]} - filtered list of extensions
* @memberof Gzipper
*/
[getValidExtensions]() {
const excludeExtensions =
this.options.exclude &&
this.options.exclude.split(',').map(item => `.${item.trim()}`)
if (excludeExtensions) {
return VALID_EXTENSIONS.filter(
extension => !excludeExtensions.includes(extension)
)
}
return VALID_EXTENSIONS
}
}
module.exports = Gzipper

@@ -7,2 +7,3 @@ const assert = require('assert')

const Gzipper = require('../src/Gzipper')
const { VALID_EXTENSIONS } = require('../src/constants')
const {

@@ -62,3 +63,5 @@ EMPTY_FOLDER_PATH,

await gzipper.compress()
const responseMessage = `we couldn't find any appropriate files. valid extensions are: .js, .css, .html, .png, .jpg, .jpeg, .webp, .svg, .json, .csv`
const responseMessage = `we couldn't find any appropriate files. valid extensions are: ${VALID_EXTENSIONS.join(
', '
)}`

@@ -79,3 +82,5 @@ assert.ok(noFilesWarnSpy.calledWithExactly(responseMessage, true))

await gzipper.compress()
const responseMessage = `we couldn't find any appropriate files. valid extensions are: .js, .css, .html, .png, .jpg, .jpeg, .webp, .svg, .json, .csv`
const responseMessage = `we couldn't find any appropriate files. valid extensions are: ${VALID_EXTENSIONS.join(
', '
)}`

@@ -337,2 +342,34 @@ assert.ok(noFilesWarnSpy.calledWithExactly(responseMessage, true))

it('should exclude file extensions from compression jpeg,jpg', async () => {
const options = {
exclude: 'jpeg,jpg',
verbose: true,
}
const EXCLUDED_FILES_COUNT = 2
const beforeFiles = await getFiles(COMPRESS_PATH)
const gzipper = new Gzipper(COMPRESS_PATH, null, options)
const loggerSuccessSpy = sinon.spy(gzipper.logger, 'success')
const loggerInfoSpy = sinon.spy(gzipper.logger, 'info')
await gzipper.compress()
const files = await getFiles(COMPRESS_PATH, ['.gz'])
assert.ok(
loggerSuccessSpy.calledOnceWithExactly(
`${files.length} files have been compressed.`,
true
)
)
assert.strictEqual(
loggerInfoSpy.callCount,
beforeFiles.length - EXCLUDED_FILES_COUNT + 1
)
assert.ok(gzipper.createCompression() instanceof zlib.Gzip)
assert.strictEqual(gzipper.compressionInstance.ext, 'gz')
assert.strictEqual(
Object.keys(gzipper.compressionInstance.compressionOptions).length,
0
)
assert.strictEqual(Object.keys(gzipper.options).length, 2)
})
afterEach(async () => {

@@ -339,0 +376,0 @@ await clear(EMPTY_FOLDER_PATH, true)

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