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

@buzuli/json

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@buzuli/json - npm Package Compare versions

Comparing version 2.0.2 to 2.1.0

bin/json.js

5

package.json
{
"name": "@buzuli/json",
"version": "2.0.2",
"version": "2.1.0",
"description": "",
"main": "lib/json.js",
"bin": {
"json": "bin/json.js"
},
"scripts": {

@@ -7,0 +10,0 @@ "lint": "standard",

@@ -35,1 +35,25 @@ # json

- You can supply a string to replace the default indentation text (two space).
## CLI
There is a CLI utility paired with this module that is exposed as the command `json`.
This command has the same configuration options as the utility function.
Just pipe some data to it to format it with friendly colors.
```shell
cat package.json | json
```
Want a flat structure indented?
```shell
cat flat.json | json -C
```
Want an indented structure flattend?
```shell
cat indented.json | json -CI
```

65

test/json.test.js
const tap = require('tap')
const json = require('../lib/json')
const obj = {
A: [
{
a: 1,
b: 2
},
{
c: '3',
d: '4'
}
],
B: [
{
e: true,
f: false
},
{
g: null
}
],
C: [],
D: {},
'"E"': '"quoted"',
'\\F\\': '\\escaped\\',
'\\G\\': '\nnewlines\n',
'\\H\\': '"',
'\\I\\': '',
'some-thing': 'hyphenated'
}
tap.test('Should format an object', async assert => {
const obj = {
A: [
{
a: 1,
b: 2
},
{
c: '3',
d: '4'
}
],
B: [
{
e: true,
f: false
},
{
g: null,
h: undefined
}
]
}
assert.ok(typeof json(obj) === 'string')
assert.same(json({}), '{}')
assert.same(json({ id: 'jason' }, { indent: false, color: false }), '{"id":"jason"}')
})
tap.test('Should parse a string then format', async assert => {
tap.test('Should parse a json string then format', async assert => {
assert.ok(typeof json('{}') === 'string')
assert.same(json('{}'), '{}')
assert.same(obj, JSON.parse(json(JSON.stringify(obj), { color: false })))
})
tap.test('Should generate valid JSON in non-colorized mode', async assert => {
assert.same(obj, JSON.parse(json(obj, { color: false })))
assert.same(obj, JSON.parse(json(obj, { color: false, indent: false })))
assert.same(obj, JSON.parse(json(obj, { color: false, indent: 4 })))
})
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