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

format-json-cli

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

format-json-cli - npm Package Compare versions

Comparing version 0.1.2 to 1.0.0

23

cli.js

@@ -33,2 +33,19 @@ #!/usr/bin/env node

function isObject(o) {
return o && typeof o === 'object'
}
function compare(a, b) {
return a < b ? -1 : a > b ? 1 : 0
}
function sortObject(object, key) {
let o = object[key]
if (!isObject(o)) {
return
}
o = Object.fromEntries(Object.entries(o).sort((a, b) => compare(a[0], b[0])))
object[key] = o
}
function scanFile(file) {

@@ -39,3 +56,7 @@ if (path.extname(file) !== '.json') return

try {
newText = JSON.stringify(JSON.parse(text), null, 2) + os.EOL
let json = JSON.parse(text)
sortObject(json, 'dependencies')
sortObject(json, 'devDependencies')
sortObject(json, 'peerDependencies')
newText = JSON.stringify(json, null, 2) + os.EOL
} catch (error) {

@@ -42,0 +63,0 @@ console.error('Failed to parse file:', file)

2

package.json
{
"name": "format-json-cli",
"version": "0.1.2",
"version": "1.0.0",
"description": "format json file as post-hook to fix prettier",

@@ -5,0 +5,0 @@ "keywords": [

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