javascipt / jsome Goto Github PK
View Code? Open in Web Editor NEW:sparkles: Make your JSON look AWESOME
License: MIT License
:sparkles: Make your JSON look AWESOME
License: MIT License
For long arrays:
Bad:
["jetradar_mobile_search", "credit_deeplink_preparation", "credit_deeplink", "airline_deeplink", "mobile_search_native_format", "search", "special_offer_click_builder", "travelpayouts_api_authenticator", "kiwi_assisted_confirm", "pixel_booking", "jetradar_mobile_rt_search_native_format", "jetradar_mobile_search_native_format", "tickets_assisted_deeplink", "stub_chain", "amadeus_chain", "mobile_rt_search", "jetradar_rt_search_native_format", "tickets_assisted_booking", "deeplink", "mobile_rt_search_native_format", "ndc_deeplink", "mobile_search", "special_offer", "ndc_booking", "kiwi_assisted_deeplink", "rt_search_native_format", "non_persisted_deeplink", "travelpayouts_api_request_signer", "kiwi_assisted_booking", "ndc_retrieve", "jetradar_mobile_rt_search"]
Better:
[
"jetradar_mobile_search",
"credit_deeplink_preparation",
"credit_deeplink",
"airline_deeplink",
"mobile_search_native_format",
"search",
"special_offer_click_builder",
"travelpayouts_api_authenticator",
"kiwi_assisted_confirm",
"pixel_booking",
"jetradar_mobile_rt_search_native_format",
"jetradar_mobile_search_native_format",
"tickets_assisted_deeplink",
"stub_chain",
"amadeus_chain",
"mobile_rt_search",
"jetradar_rt_search_native_format",
"tickets_assisted_booking",
"deeplink",
"mobile_rt_search_native_format",
"ndc_deeplink",
"mobile_search",
"special_offer",
"ndc_booking",
"kiwi_assisted_deeplink",
"rt_search_native_format",
"non_persisted_deeplink",
"travelpayouts_api_request_signer",
"kiwi_assisted_booking",
"ndc_retrieve",
"jetradar_mobile_rt_search"
]
If I have a stringfield with \n
, it's not replaced (actual newlines are outputted which is invalid JSON), so makes invalid JSON, even with jsome.params.lintable = true
Here is an example:
{
"title": "A New Hope",
"episode_id": 4,
"opening_crawl": "It is a period of civil war.\r\nRebel spaceships, striking\r\nfrom a hidden base, have won\r\ntheir first victory against\r\nthe evil Galactic Empire.\r\n\r\nDuring the battle, Rebel\r\nspies managed to steal secret\r\nplans to the Empire's\r\nultimate weapon, the DEATH\r\nSTAR, an armored space\r\nstation with enough power\r\nto destroy an entire planet.\r\n\r\nPursued by the Empire's\r\nsinister agents, Princess\r\nLeia races home aboard her\r\nstarship, custodian of the\r\nstolen plans that can save her\r\npeople and restore\r\nfreedom to the galaxy....",
"director": "George Lucas",
"producer": "Gary Kurtz, Rick McCallum",
"release_date": "1977-05-25"
}
outputs this (invalid json):
{
"title": "A New Hope",
"episode_id": 4,
"opening_crawl": "It is a period of civil war.
Rebel spaceships, striking
from a hidden base, have won
their first victory against
the evil Galactic Empire.
During the battle, Rebel
spies managed to steal secret
plans to the Empire's
ultimate weapon, the DEATH
STAR, an armored space
station with enough power
to destroy an entire planet.
Pursued by the Empire's
sinister agents, Princess
Leia races home aboard her
starship, custodian of the
stolen plans that can save her
people and restore
freedom to the galaxy....",
"director": "George Lucas",
"producer": "Gary Kurtz, Rick McCallum",
"release_date": "1977-05-25"
}
It would significantly reduce the size of the package for projects that do not use the CLI, such as danger-js
.
Example: [1, '313233343536373839303132333435367b94679e5264bf84069c68643307ef80c1ebf343565158', 3]
Output is:
[1, "313233343536373839303132333435367b94679e5264bf84069c68643307ef80c1ebf343565158", 3]
Output for better readability should be (like object output):
[
1,
"313233343536373839303132333435367b94679e5264bf84069c68643307ef80c1ebf343565158",
3
]
If you had an array of objects it is displayed in lines.
First of all, AWESOME work here!!! ๐ Love your code and style. I am that
guy who duplicated this precious gem with json-colorz. I hope you take that as an honor.
In testing this latest version, came across a situation with the following setup:
var obj = {
a: 1,
b: 2,
c: {
d: {
e: 3
}
}
}
jsome.level.show = true
jsome.level.spaces = 2
jsome.level.start = 2
jsome(obj)
which displays:
undefined undefined {
undefined undefined undefined a: 1,
undefined undefined undefined b: 2,
undefined undefined undefined c: {
undefined undefined undefined undefined d: {
undefined undefined undefined undefined undefined e: 3
undefined undefined undefined undefined }
undefined undefined undefined }
undefined undefined }
I think the problem originates from this line
maybe you wish to do something like the following...
levelStr = levelStr.replace(' ', useColorProvider(opts.char, opts.color))
or, maybe you have other plans yet to be implemented. just wanted you to be aware if you were not.
Only object brackets are visible.
Example
jsome( new RegExp('ab+c') )
Outputs
{
}
I have tried to make a cli to this package to allow the user to print json files directly on the console using a command line, example :
$ jsome /path/to/file.json
I have added the bin property on the package.json here, it points to this file
The issue I have is that after installing the package globally it works on Windows, but not on Linux, I haven't tried it on a Mac OS though. can someone help me with this issue ?
jsome.colors.attr = ['blue' , 'bold'];
causes this error:
/Users/edasque/project/jsome_test/node_modules/jsome/lib/generator.js:92
return chalk[isArray(color) ? color[0] : color](str);
^
TypeError: chalk[(intermediate value)(intermediate value)(intermediate value)] is not a function
at useColorProvider (/Users/edasque/project/jsome_test/node_modules/jsome/lib/generator.js:92:58)
at useColorProvider (/Users/edasque/project/jsome_test/node_modules/jsome/lib/generator.js:90:18)
at useColorProvider (/Users/edasque/project/jsome_test/node_modules/jsome/lib/generator.js:90:18)
at colorifySpec (/Users/edasque/project/jsome_test/node_modules/jsome/lib/generator.js:76:35)
at Object.module.exports.color.gen (/Users/edasque/project/jsome_test/node_modules/jsome/lib/generator.js:112:24)
at Function.module.exports.jsome.parse (/Users/edasque/project/jsome_test/node_modules/jsome/script.js:45:30)
at jsome (/Users/edasque/project/jsome_test/node_modules/jsome/script.js:31:18)
at Request._callback (/Users/edasque/project/jsome_test/us_dotd.js:548:4)
at Request.self.callback (/Users/edasque/project/jsome_test/node_modules/request/request.js:198:22)
while
var jsome = require('jsome');
jsome.level.show = true;
jsome.level.color = 'green';
works. I cannot get the following to have any effect:
jsome.colors = {
'num' : 'blue' // stands for numbers
, 'str' : 'blue' // stands for strings
, 'bool' : 'blue' // stands for booleans
, 'regex' : 'blue' // stands for regular expressions
, 'undef' : 'grey' // stands for undefined
, 'null' : 'blue' // stands for null
, 'attr' : 'blue' // objects attributes -> { attr : value }
, 'quot' : 'blue' // strings quotes -> "..."
, 'punc' : 'blue' // commas seperating arrays and objects values -> [ , , , ]
, 'brack' : 'blue' // for both {} and []
}
jsome.colors.attr = ['blue' , 'bold']
Is there a unit test I can run that could help diagnose? node 4.2.1.
โโโฌ [email protected]
โ โโโฌ [email protected]
โ โ โโโ [email protected]
โ โ โโโ [email protected]
โ โ โโโฌ [email protected]
โ โ โ โโโ [email protected]
โ โ โโโฌ [email protected]
โ โ โ โโโ [email protected]
โ โ โโโ [email protected]
โ โโโ [email protected]
โ โโโฌ [email protected]
โ โโโ [email protected]
โ โโโฌ [email protected]
โ โ โโโฌ [email protected]
โ โ โ โโโฌ [email protected]
โ โ โ โ โโโ [email protected]
โ โ โ โโโฌ [email protected]
โ โ โ โโโ [email protected]
โ โ โโโฌ [email protected]
โ โ โ โโโ [email protected]
โ โ โโโ [email protected]
โ โโโ [email protected]
โ โโโฌ [email protected]
โ โ โโโฌ [email protected]
โ โ โโโ [email protected]
โ โโโ [email protected]
โ โโโ [email protected]```
I'm on node 8.9 and using iterm2 on OSX. I can print colors with the chalk package fine.
If I do this:
const testObject = {
someData: 'testing'
};
console.log(jsome.getColoredString(testObject));
I get this in the console:
[ '%c{\n %ctest%c: %c"%cblah%c"\n%c}',
'color: #FFFF00',
'color: #00FF00',
'color: #FFFF00',
'color: #FFFF00',
'color: #FF00FF',
'color: #FFFF00',
'color: #FFFF00' ]
Tried just jsome(testObject)
too and it gives the same.
jsome 2.3.25
OS X 10.12.1
$ jsome
env: node\r: No such file or directory
$ which jsome |xargs dos2unix -F
dos2unix: converting file /Users/chris/.nvm/versions/node/v6.2.2/bin/jsome to Unix format...
$ jsome
{
error: "EISDIR: illegal operation on a directory, read"
}
$
jsome.getColoredString(undefined)
I tried to use it in TypeScript project with no luck (with strict=true
). Can you add typings please?
A vulnerability in mem
< 4.0 sindresorhus/memoize#14 was fixed in yargs/yargs#1209 and released in 12.0.2 or later.
I'm seeing an alert in Shields via Danger via jsome.
It would be great to upgrade!
const jsome = require('jsome')
const obj = {
a: 1,
b: "str",
c: undefined,
d: null
}
console.log( jsome.getColoredString(obj) )
Output is:
{
a: 1,
b: "str",
d: null
}
When passing the output of jsom(...)
into a utility which expects validate JSON (for example, jq
) or a JSON linter, errors are thrown as keys are expected to bring wrapped in double quotes as per the JSON spec (members have pairs; pairs have strings on the left size of :
and strings have "
around them).
Examples:
$ echo '{"key":"value"}' > test.json && jsome -c false test.json | jq '.'
> parse error: Invalid numeric literal at line 2, column 6
or if you take the output of
$ echo '{"key":"value"}' > test.json && jsome -c false test.json
and put it into https://jsonlint.com/ you get an error:
Error: Parse error on line 1:
{ key: "value"}
--^
Expecting 'STRING', '}', got 'undefined'
A flag to enable lint friendly JSON whether colours on or not would be beneficial.
Right now, I check if a user is using TTY (in case they're piping) and I can't just turn colours off (see above), I have to use:
if (process.stdout.isTTY) {
process.stdout.write(
JSON.stringify(jResponse, null, 2)
)
} else {
jsome(jResponse)
}
whereas I feel a better answer would be
jsome.params.colored = !process.stdout.isTTY;
jsome.params.linted = true // Or something like that...
jsome(jResponse)
Also, is something like this suppoed to work?
...
, 'quot' : 'color: #FFFF00'
...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.