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

libnpmdiff

Package Overview
Dependencies
Maintainers
5
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

libnpmdiff - npm Package Compare versions

Comparing version 6.0.9 to 6.1.0

38

lib/format-diff.js

@@ -1,4 +0,1 @@

const EOL = '\n'
const colorizeDiff = require('@npmcli/disparity-colors')
const jsDiff = require('diff')

@@ -8,2 +5,19 @@

const colors = {
// red
removed: { open: '\x1B[31m', close: '\x1B[39m' },
// green
added: { open: '\x1B[32m', close: '\x1B[39m' },
// blue
header: { open: '\x1B[34m', close: '\x1B[39m' },
// cyan
section: { open: '\x1B[36m', close: '\x1B[39m' },
}
const color = (colorStr, colorId) => {
const { open, close } = colors[colorId]
// avoid highlighting the "\n" (would highlight till the end of the line)
return colorStr.replace(/[^\n\r]+/g, open + '$&' + close)
}
const formatDiff = ({ files, opts = {}, refs, versions }) => {

@@ -39,3 +53,3 @@ let res = ''

if (opts.diffNameOnly) {
res += `${filename}${EOL}`
res += `${filename}\n`
continue

@@ -48,3 +62,3 @@ }

headerLength++
patch += `${str}${EOL}`
patch += `${str}\n`
}

@@ -91,5 +105,13 @@

res += (opts.color
? colorizeDiff(patch, { headerLength })
: patch)
if (opts.color) {
// this RegExp will include all the `\n` chars into the lines, easier to join
const lines = patch.split(/^/m)
res += color(lines.slice(0, headerLength).join(''), 'header')
res += lines.slice(headerLength).join('')
.replace(/^-.*/gm, color('$&', 'removed'))
.replace(/^\+.*/gm, color('$&', 'added'))
.replace(/^@@.+@@/gm, color('$&', 'section'))
} else {
res += patch
}
}

@@ -96,0 +118,0 @@

{
"name": "libnpmdiff",
"version": "6.0.9",
"version": "6.1.0",
"description": "The registry diff",

@@ -50,9 +50,8 @@ "repository": {

"@npmcli/arborist": "^7.2.1",
"@npmcli/disparity-colors": "^3.0.0",
"@npmcli/installed-package-contents": "^2.0.2",
"@npmcli/installed-package-contents": "^2.1.0",
"binary-extensions": "^2.3.0",
"diff": "^5.1.0",
"minimatch": "^9.0.4",
"npm-package-arg": "^11.0.1",
"pacote": "^17.0.4",
"npm-package-arg": "^11.0.2",
"pacote": "^18.0.1",
"tar": "^6.2.1"

@@ -59,0 +58,0 @@ },

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