Code Monkey home page Code Monkey logo

jsome's People

Contributors

astanciu avatar drewsonne avatar javascipt avatar kiyanwang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

jsome's Issues

Display long array one item per line

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"
]

lintable doesn't fix newlines

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"
}

Consider separating CLI.

It would significantly reduce the size of the package for projects that do not use the CLI, such as danger-js.

Display array items in lines

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.

jsome.level.show=true displaying "undefined" instead of level.char

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.

RegExp not printed

Only object brackets are visible.

Example

jsome( new RegExp('ab+c') )

Outputs

{
}

Jsome including uncolored output

I'm trying to use Jsome in my project, and it works well colorizing the JSON. However, it also includes the uncolored output after the colored output.

Here's the code I'm using:
let colorizedJson = jsome.parse(json);

where json is just a JSON string. See screenshot to see the behavior.
screen shot 2016-10-23 at 7 10 30 pm

jsome-cli

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']; doesn't work

      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)

jsome.color has no effect for me

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]```

Doesn't work for me

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.

env: node\r: No such file or directory

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"
}
$

TypeScript typings

I tried to use it in TypeScript project with no luck (with strict=true). Can you add typings please?

Output is not valid JSON

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.