New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

tinyjpg

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tinyjpg - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

bin/tinyjpg-compress.js

66

bin/tinyjpg.js

@@ -1,65 +0,5 @@

const tinify = require('tinify')
const program = require('commander')
const chalk = require('chalk').default
const path = require('path')
const isDir = require('is-directory')
const fs = require('fs')
const {key, extnames, skips} = require('../lib/config')
let totalCount = 0
let successCount = 0
let failCount = 0
program.version(require('../package').version)
.usage('<filename or directory> [output filename or directory]')
require('commander').version(require('../package').version)
.usage('<command> <options>')
.command('config', 'add or remove config')
function help () {
program.parse(process.argv)
if (program.args.length < 2) return program.help()
}
help()
// get path
let source = toPath(program.args[0])
let target = toPath(program.args[1])
if (key) {
tinify.key = key
findFiles(source)
} else {
console.log(chalk.redBright('Please set api key!'))
}
function findFiles(root) {
try {
if (!isDir.sync(root)) { // not directory
if (extnames.indexOf(path.extname(root)) >= 0) { // filter extnames
totalCount++;
const targetDir = target ? (isDir.sync(target) ? path.join(target, path.basename(root)) : root) : root
tinify.fromFile(root).toFile(targetDir).then(() => { // compress image
console.log(chalk.greenBright(`${path.basename(root)} Succeed`))
successCount++
console.log(`${chalk.blueBright(`Total ${totalCount}`)}, ${chalk.greenBright(`${successCount} Succeed`)}, ${chalk.redBright(`${failCount} Failed`)}`, )
}, (err) => {
console.log(chalk.redBright(`${path.basename(root)} Failed`), err.message) // failed
failCount++
console.log(`${chalk.blueBright(`Total ${totalCount}`)}, ${chalk.greenBright(`${successCount} Succeed`)}, ${chalk.redBright(`${failCount} Failed`)}`, )
})
}
} else {
let dirs = fs.readdirSync(root, 'utf8')
dirs.filter((dir) => skips.indexOf(dir) === -1).forEach((dir) => { // skip specify dir
findFiles(path.join(root, dir))
})
}
} catch (err) {
console.log(chalk.redBright(err))
}
}
function toPath (pathname) { // convert path to absolute path
pathname && isDir.sync(pathname) && !path.isAbsolute(pathname) && (pathname = path.join(process.cwd(), pathname))
return pathname
}
.command('compress', 'compress images')
{
"name": "tinyjpg",
"version": "1.0.0",
"version": "1.0.1",
"description": "compress images by tinypng api",

@@ -8,5 +8,9 @@ "main": "index.js",

"license": "MIT",
"repository": {
"url": "https://github.com/Kermit-Xuan/tinyjpg.git"
},
"bin": {
"tinyjpg": "bin/tinyjpg.js",
"tinyjpg-config": "bin/tinyjpg-config.js"
"tinyjpg-config": "bin/tinyjpg-config.js",
"tinyjpg-compress": "bin-tinyjpg-compress.js"
},

@@ -13,0 +17,0 @@ "dependencies": {

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