Giter VIP home page Giter VIP logo

angular2-prettyjson's Introduction

Angular 2 Pretty Json v3.0.0

A module for Angular 2 debug output of objects. Contains a pipe similar to JsonPipe but adds support for spacing and handling of circular structures.
Also contains a component that outputs any object with syntax highlight.
Warning: just as the JsonPipe, this is an impure pipe and should be used only for debugging purposes.

Breaking change in 3.0.0 The UMD bundle has moved to a "bundle" subdirectory. SymstemJS users should update their system.config. Should not affect AngularCLI and other webpack projects.

Install

npm install angular2-prettyjson

ES2015 / UMD

Two versions are available: ES2015 modules and UMD. If you are using a project based on the AngularCLI, everything should work from a simple npm install.
If you are using the Angular Quickstart template (or other SystemJS based compilation), please point to the bundle angular2-prettyjson.umd.min.js file e.g. systemjs.config.js:

    map: {
      ...
      // other libraries
      'rxjs':                      'npm:rxjs',
      'angular2-prettyjson': 'npm:angular2-prettyjson'
    },
    packages: {
      ...,
      'angular2-prettyjson': {
        defaultExtension: 'js',
        main: './bundles/angular2-prettyjson.umd.min.js'
      }

Usage

Import PrettyJsonModule to have access to the component and pipes

import {PrettyJsonModule} from 'angular2-prettyjson';

@NgModule({
    declarations: [
        AppComponent,
    ],
    imports: [
        PrettyJsonModule,
    ],
    providers: [
    ],
    bootstrap: [AppComponent]
})
export class AppModule {
}

Safe Pipe

The SafeJsonPipe aims to override the JsonPipe and so uses the same name "json". It also accepts an optional argument spaces=2 for the JSON stringify spacing.

@Component({
  ....
  template: `
    <pre>
    {{ circularObj | json }}
    {{ circularObj | json:4 }}
    </pre>
  ` // make sure to use a surrounding element with white-space: pre; for best results
  })
  ...

outputs

2 spaces (default):

2 spaces

4 spaces:

4 spaces

Pretty (and safe) Pipe

The PrettyJsonPipe stringifies the object and then adds spans around properties, null, arrays etc. You can bind it to the innerHtml of other elements.

@Component({
  ....
  template: `
    <pre [innerHtml]="circularObj | prettyjson:3"></pre>
  `
  })
  ...

A good set of styles to use is

   pre span {white-space: normal;}
   .string { color: green; }
   .number { color: darkorange; }
   .boolean { color: blue; }
   .null { color: magenta; }
   .key { color: red; }

If you wish to use the styles property of the parent component, please prefix each class selector with :host /deep/ e.g.

@Component({
 ....
 template: `
   <pre [innerHtml]="circularObj | prettyjson:3"></pre>
 `,
 styles: [`:host /deep/ .string {color:green} ...`]
 })
 ...

See output under component below.

Component

Creates a pre element into which the Pretty Json pipe'd object is dumped as HTML. Takes care of styling.

Takes an input [obj] that can be data bound to any object.

Make sure PrettyJsonModule is imported in your own module.

@Component({
  ....
  template: `
    <prettyjson [obj]="theForm.value"></prettyjson>
  `
  })
  export class MyComponent {
    ngOnInit() {
      this.theForm = this.formBuilder.group({
       ...

outputs

Pretty json with syntax highlight

angular2-prettyjson's People

Contributors

matiboy avatar sguiheux 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

Watchers

 avatar  avatar  avatar  avatar

angular2-prettyjson's Issues

Warning messages with webpack

Hi, we are using your package with webpack.
And while building, webpack source-map-loader is generating a lot of warning messages:

WARNING in C:/Projects/.../~/angular2-prettyjson/index.js
Cannot find source file 'index.ts': Error: Can't resolve './index.ts' in 'C:\Projects\settingsone\OneInc.SettingsOne.Web\node_
r2-prettyjson'
 @ ../vendor.ts 22:0-30
 @ multi ../vendor.ts

WARNING in C:/Projects/.../~/angular2-prettyjson/src/prettyjson.module.js
Cannot find source file 'prettyjson.module.ts': Error: Can't resolve './prettyjson.module.ts' in 'C:\Projects\settingsone\OneI
.Web\node_modules\angular2-prettyjson\src'
 @ C:/Projects/.../~/angular2-prettyjson/index.js 1:0-59
 @ ../vendor.ts
 @ multi ../vendor.ts

WARNING in C:/Projects/.../~/angular2-prettyjson/src/json.pipe.js
Cannot find source file 'json.pipe.ts': Error: Can't resolve './json.pipe.ts' in 'C:\Projects\settingsone\OneInc.SettingsOne.W
s\angular2-prettyjson\src'
 @ C:/Projects/.../~/angular2-prettyjson/index.js 2:0-47
 @ ../vendor.ts
 @ multi ../vendor.ts

WARNING in C:/Projects/.../~/angular2-prettyjson/src/prettyjson.pipe.js
Cannot find source file 'prettyjson.pipe.ts': Error: Can't resolve './prettyjson.pipe.ts' in 'C:\Projects\settingsone\OneInc.S
\node_modules\angular2-prettyjson\src'
 @ C:/Projects/.../~/angular2-prettyjson/index.js 3:0-55
 @ ../vendor.ts
 @ multi ../vendor.ts

WARNING in C:/Projects/.../~/angular2-prettyjson/src/prettyjson.component.js
Cannot find source file 'prettyjson.component.ts': Error: Can't resolve './prettyjson.component.ts' in 'C:\Projects\settingson
ngsOne.Web\node_modules\angular2-prettyjson\src'
 @ C:/Projects/.../~/angular2-prettyjson/index.js 4:0-65
 @ ../vendor.ts
 @ multi ../vendor.ts

WARNING in C:/Projects/.../~/angular2-prettyjson/src/safe.util.js
Cannot find source file 'safe.util.ts': Error: Can't resolve './safe.util.ts' in 'C:\Projects\settingsone\OneInc.SettingsOne.W
s\angular2-prettyjson\src'
 @ C:/Projects/.../~/angular2-prettyjson/src/json.pipe.js 2:0-41
 @ C:/Projects/.../~/angular2-prettyjson/index.js
 @ ../vendor.ts
 @ multi ../vendor.ts

These messages can be supressed by adding this workaround:

module: {
    rules: [{
        test: /\.js$/,
        exclude: [path.resolve(__dirname, '../../node_modules/angular2-prettyjson') ,  // this
        use: 'source-map-loader'
    }]

}

Please, fix it

AOT broken after upgrade angular and angular-cli

Environment

@angular/cli: 1.0.0-beta.31
node: 7.5.0
os: linux x64
@angular/common: 2.4.7
@angular/compiler: 2.4.7
@angular/core: 2.4.7
@angular/flex-layout: 2.0.0-beta.5
@angular/forms: 2.4.7
@angular/http: 2.4.7
@angular/material: 2.0.0-beta.2
@angular/platform-browser: 2.4.7
@angular/platform-browser-dynamic: 2.4.7
@angular/router: 3.4.7
@angular/cli: 1.0.0-beta.31
@angular/compiler-cli: 2.4.7

Error

ERROR in Error encountered resolving symbol values statically. Calling function 'makeDecorator', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol NgModule in /home/maxime/Documents/pizza-sync/frontend/node_modules/angular2-prettyjson/node_modules/@angular/core/src/metadata/ng_module.d.ts, resolving symbol NgModule in /home/maxime/Documents/pizza-sync/frontend/node_modules/angular2-prettyjson/node_modules/@angular/core/src/metadata.d.ts, resolving symbol NgModule in /home/maxime/Documents/pizza-sync/frontend/node_modules/angular2-prettyjson/node_modules/@angular/core/src/core.d.ts, resolving symbol NgModule in /home/maxime/Documents/pizza-sync/frontend/node_modules/angular2-prettyjson/node_modules/@angular/core/index.d.ts, resolving symbol PrettyJsonModule in /home/maxime/Documents/pizza-sync/frontend/node_modules/angular2-prettyjson/src/prettyjson.module.d.ts, resolving symbol PrettyJsonModule in /home/maxime/Documents/pizza-sync/frontend/node_modules/angular2-prettyjson/src/prettyjson.module.d.ts

Other

Might be related to a previous issue #8

ParseError: 'import' and 'export' may appear only with 'sourceType: module'

I keep getting this error when I try to bundle this in my app (I [REMOVED] stuff that was personal and irrelavant):

> browserify -s main  wwwroot/js/main.js > wwwroot/js/bundle.js


C:\Code\[REMOVED]\application\src\[REMOVED]\node_modules\angular2-prettyjson\index.js:1
export { PrettyJsonModule } from "./src/prettyjson.module";
^
ParseError: 'import' and 'export' may appear only with 'sourceType: module'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [REMOVED]@1.0.0 browserify: `browserify -s main  wwwroot/js/main.js > wwwroot/js/bundle.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [REMOVED]@1.0.0 browserify script 'browserify -s main  wwwroot/js/main.js > wwwroot/js/bundle.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the [REMOVED] package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     browserify -s main  wwwroot/js/main.js > wwwroot/js/bundle.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs [REMOVED]
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls [REMOVED]
npm ERR! There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\[REMOVED]\AppData\Roaming\npm-cache\_logs\2017-05-12T05_07_22_762Z-debug.log

Update npm registry

Currently, 1.0.5 is the latest version in npm registry.

Idk, what is going wrong, but only 'typings' folder is coming, along with readme, package.json and tsconfig.json when installing via git link.

Got errors for project based on Angular Quickstart template when npm install angular2-prettyjson

+-- UNMET PEER DEPENDENCY @angular/[email protected]
+-- UNMET PEER DEPENDENCY @angular/[email protected]
+-- UNMET PEER DEPENDENCY @angular/[email protected]
+-- UNMET PEER DEPENDENCY @angular/[email protected]
+-- UNMET PEER DEPENDENCY @angular/[email protected]
+-- [email protected]
+-- UNMET PEER DEPENDENCY [email protected]
`-- UNMET PEER DEPENDENCY [email protected]

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN @angular/[email protected] requires a peer of @angular/[email protected] but none was installed.
npm WARN @angular/[email protected] requires a peer of @angular/[email protected] but none was installed.
npm WARN @angular/[email protected] requires a peer of @angular/[email protected] but none was installed.
npm WARN @angular/[email protected] requires a peer of [email protected] but none was installed.
npm WARN [email protected] requires a peer of @angular/[email protected] but none was installed.
npm WARN [email protected] requires a peer of @angular/[email protected] but none was installed.
npm WARN [email protected] requires a peer of @angular/[email protected] but none was installed.
npm WARN [email protected] requires a peer of @angular/[email protected] but none was installed.
npm WARN [email protected] requires a peer of @angular/[email protected] but none was installed.
npm WARN [email protected] requires a peer of [email protected] but none was installed.
npm WARN [email protected] requires a peer of zone.js@^0.6.21 but none was installed.
npm WARN [email protected] No repository field.
npm WARN [email protected] No license field.

Module not found

I added module as described but I get an error on my ng 8 cli based project:

ERROR in ./src/app/app.module.ngfactory.js
Module not found: Error: Can't resolve 'angular2-prettyjson/src/json.pipe' in 'D:\myapp\src\app'

Cannot import

Can you add correct systemjs.config.js entries to the README? I can't seem to import the library in a sane way.

How do you have it set up in your example?

The pipe 'prettyjson' could not be found ("

Hi,

I added pretty json to my main module but I get the error above

this works:
<pre [innerHtml]="products | json:4">

but this does produce the error
<pre [innerHtml]="products | prettyjson:4">

import {PrettyJsonModule, SafeJsonPipe} from 'angular2-prettyjson';
import {JsonPipe} from '@angular/common';
...
 providers: [
       { provide: JsonPipe, useClass: SafeJsonPipe }

do I have to export anything ?

thanks

Angular 5 error

Getting this error after upgrading my project to Angular 5:

compiler.js:466 Uncaught Error: Unexpected value 'PrettyJsonModule' imported by the module 'SharedModule'. Please add a @NgModule annotation.
    at syntaxError (compiler.js:466)
    at eval (compiler.js:15089)
    at Array.forEach (<anonymous>)
    at CompileMetadataResolver.getNgModuleMetadata (compiler.js:15072)
    at CompileMetadataResolver.getNgModuleSummary (compiler.js:14999)
    at eval (compiler.js:15087)
    at Array.forEach (<anonymous>)
    at CompileMetadataResolver.getNgModuleMetadata (compiler.js:15072)
    at JitCompiler._loadModules (compiler.js:33501)
    at JitCompiler._compileModuleAndComponents (compiler.js:33462)

Was working fine before the upgrade.

Is that a problem with the angular2-prettyjson?

Thank you.

Styles not being applied to component using: Pretty (and safe) Pipe

I've got the pipe working using the Component Method.

However when I'm using the Pretty (and safe) Pipe, the custom colors, defined in the css styles are not applied to the html generated by the pipe.

Component Definition:

@Component({
  selector: 'bom-view-table',
  template: `
     <div>
       <pre [innerHtml]="obj | prettyjson:3"></pre>
     </div>
  `,
  styles: [`
    string { color: green; }
    number { color: darkorange; }
    boolean { color: blue; }
    null { color: magenta; }
    key { color: red; }    
  `]
})

HTML Source:
image

HTML Output
image

The pipe correctly decorates the HTML with the class keywords, but the css styles from the component aren't applied. Is there something I'm doing wrong?

By the way, this is a very helpful module for debugging, thanks for your efforts!

About firstly failed to compile

Hello:
When I first 'ng serve' my project, I encounter a problem. The message is below:

ERROR in Error encountered resolving symbol values statically. Function calls are not supported. Consider replacing the function or lambda with a reference to an exported function (position 194:50 in the original .ts file), resolving symbol NgModule in E:/project/gss/oversee/ngOversee/node_modules/angular2-prettyjson/node_modules/@angular/core/core.d.ts, resolving symbol PrettyJsonModule in E:/project/g ss/oversee/ngOversee/node_modules/angular2-prettyjson/src/prettyjson.module.d.ts, resolving symbol PrettyJsonModule in E:/project/gss/oversee/ngOversee/node_modules/angular2-prettyjson/src/prettyjson.mod ule.d.ts
.

I use angular 4.

And then, when I save in any file, the problem disappears.

Thank you.

PrettyJsonComponent and SafeJsonPipe not exported

I'm getting this message when I try to import PrettyJsonComponent in app.component.ts :
[ts] Module '"c:/Users/redro/tree-converter/node_modules/angular2-prettyjson/angular2-prettyjson"' has no exported member 'PrettyJsonComponent'.

The import statement: import { PrettyJsonComponent } from 'angular2-prettyjson';

This also happens when I try to import SafeJsonPipe in app.module.ts.

Here are my dependencies:

    "@angular/animations": "^5.2.0",
    "@angular/common": "^5.2.0",
    "@angular/compiler": "^5.2.0",
    "@angular/core": "^5.2.0",
    "@angular/forms": "^5.2.0",
    "@angular/http": "^5.2.0",
    "@angular/platform-browser": "^5.2.0",
    "@angular/platform-browser-dynamic": "^5.2.0",
    "@angular/router": "^5.2.0",
    "ajv": "^6.1.1",
    "angular2-prettyjson": "^3.0.1",
    "core-js": "^2.4.1",
    "primeng": "^5.2.0",
    "rxjs": "^5.5.6",
    "zone.js": "^0.8.19"
  },
  "devDependencies": {
    "@angular/cli": "~1.7.0",
    "@angular/compiler-cli": "^5.2.0",
    "@angular/language-service": "^5.2.0",
    "@types/jasmine": "~2.8.3",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "codelyzer": "^4.0.1",
    "jasmine-core": "~2.8.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~2.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~4.1.0",
    "tslint": "~5.9.1",
    "typescript": "~2.5.3"
  }```

"Keys" and "Values" are not aligned for longer "Values"

Issue - "Keys" and "Values" are not aligned for longer "Values"

Example - "description" section below. The indentation of value is not correct as in below response-
Pretty_Json_Key_Value_Alignment_Issue.txt

"notices": [
{
"title": "Terms of Use",
"description": [
"Access to Public Interest Registry RDAP information is provided to assist persons in determining the contents of a domain name registration record in the Public Interest registry database. The data in this record is provided by Public Interest Registry for informational purposes only, and Public Interest Registry does not guarantee its accuracy. This service is intended only for query-based access. You agree that you will use this data only for lawful purposes and that, under no circumstances will you use this data to(a) allow, enable, or otherwise support the transmission by e-mail, telephone, or facsimile of mass unsolicited, commercial advertising or solicitations to entities other than the data recipient's own existing customers; or (b) enable high volume, automated, electronic processes that send queries or data to the systems of Registry Operator, a Registrar, or Afilias except as reasonably necessary to register domain names or modify existing registrations. All rights reserved. Public Interest Registry reserves the right to modify these terms at any time. By submitting this query, you agree to abide by this policy."
],
"links": [
{
"rel": "alternate",
"href": "https://rdap.publicinterestregistry.net/rdap/org/terms_of_use",
"type": "text/html"
}
]
}

css style not applied, instead literal<span> tags are shown

Hello and thanks for the great tool!

Sorry if this question is too stupid to be asked :)

In an angular template I am using string interpolation and the prettyjson pipe, intending to show a form value as formatted json:
{{ form.value | prettyjson }}

However in the browser, instead of the css style being applied, I see the raw html tags. I mean like this:
<span class="key">"application":</span> ... and so on.

What can I be doing wrong?

AOT issue ?

Hi !

First of all, let me thank you for this module because it's really helpful for debugging. ๐Ÿ‘

One thing tho, I'm now using it with angular-cli beta.24 and as soon as I import the PrettyJsonModule I get : ERROR in PrettyJsonModule is not an NgModule.

I was using your module in beta.22 and I didn't have that problem.
Since AOT checking was enabled by default in beta.23, I think the problem might come from there.

Did you build this module AOT compatible and I'm missing something or is it possible that the module is not yet AOT compatible ?

Cheers !

Incompatibility with Angular 5.2.0

The error I'm getting during ng serve:

ERROR in node_modules/@angular/core/src/render3/ng_dev_mode.d.ts(9,11): error TS2451: Cannot redeclare block-scoped variable 'ngDevMode'.
node_modules/angular2-prettyjson/node_modules/@angular/core/src/render3/ng_dev_mode.d.ts(9,11): error TS2451: Cannot redeclare block-scoped variable 'ngDevMode'.

Apparently Yarn decided to install Angular twice:

apk@apk:~/src/project/node_modules/angular2-prettyjson$ find . -maxdepth 3 -type d -exec ls -d "{}" \;
.
./node_modules
./node_modules/@angular
./node_modules/@angular/core
./src
./dist

angular5 angular-cli compilation error

Hi,
In an Angular 5 project setup with angular-cli:
Having the following compiling error when compiling a project that uses prettyjson dependency in the package.json:

> ERROR in Error during template compile of 'PrettyJsonModule'
>   Function expressions are not supported in decorators in 'NgModule'
>     'NgModule' contains the error at @angular\core\core.ts(194,31)
>       Consider changing the function expression into an exported function.

package.json includes the dependency:

"dependencies": {
    "angular2-prettyjson": "^2.0.6",
	...	
}

Looks like node_modules in the angular2-prettyjson folder gives a conflict with the main angular 5 version of my project (Angular 5.1.0).
Any idea what is the reason? Is this not compatible with Angular 5? thanks.

How to unescaped PrettyJson output?

I am using this module like this:

entryComponents: [ PrettyJsonComponent], imports: [ PrettyJsonModule]

<prettyjson [obj]="execution"></prettyjson>

I am getting a JSON output with escaped quotes for JSON strings. While this is accurate, it isn't very pretty.

ie:
"WorkflowMetadata": [ "{\"id\":\"597f805b55e1c063006f97e3\",\"identifier\":{\"id\":\"WorkflowMetadata\"},\"index\":0}", "{\"id\":\"5980ac79e76f8ab48b485b41\",\"identifier\":{\"id\":\"WorkflowMetadata\"},\"index\":1}" ],

Is there a simple way to configure this out?

Thank you!

Angular 2.0.0-FINAL support / modularization

In the final release of Angular 2 (technically, as of RC6), you can no longer define pipe dependencies at the component level: (cf. CHANGELOG.md)

[BREAKING CHANGES]

core: previously deprecated @Component.directives and @Component.pipes support was removed.

All the components and pipes now must be declared via an NgModule. NgModule is the basic compilation block passed into the Angular compiler via Compiler#compileModuleSync or #compileModuleAsync.

As a result, the package throws an error:

zone.js?fad3:344 Unhandled Promise rejection: Template parse errors:
The pipe 'prettyjson' could not be found (

   <pre [ERROR ->][innerHtml]="obj | prettyjson">
   </pre>

): PrettyJsonComponent@1:9

Temporarily users can manually declare the PrettyJsonPipe in their application's module's declarations array. But the long term solution would be to make this package into a module so it can declare that for itself. (The angular team is pushing package builders towards module encapsulation anyway.)

Complie error with Angular 5.1

Hi,

I've just tried to update my angular to 5.1 and received this error message with cli's prod build:

ERROR in Error: Error during template compile of 'PrettyJsonModule'
  Function calls are not supported in decorators in 'NgModule'
    'NgModule' calls a function at @angular/core/core.ts(194,31).

Can you fix this it please?

Handle long text

While debugging with prettyjson, I noticed that it let long text go outside the limit of the component :

image

In my opinion it would be nice to add word-wrap: break-word

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.