Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular2-prettyjson",
"version": "3.0.7",
"version": "3.0.8",
"scripts": {
"ng": "ng",
"build": "npm-run-all -s clean:build build:prod",
Expand Down
2 changes: 1 addition & 1 deletion projects/angular2-prettyjson/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@talentia/angular2-prettyjson",
"title": "Angular Pretty JSON",
"description": "An Angular module to pretty print JSON objects.",
"version": "3.0.7",
"version": "3.0.8",
"license": "MIT",
"licenseFilename": "LICENSE",
"peerDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions projects/angular2-prettyjson/src/lib/json-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ export function serializer() {
const stack: any[] = [];
const keys: string[] = [];

const cycleReplacer = function(key: string, value: any) {
const cycleReplacer = function (key: string, value: any) {
if (stack[0] === value) {
return "[Circular ~]";
}
return "[Circular ~." + keys.slice(0, stack.indexOf(value)).join(".") + "]";
};

return function(this: any, key: string, value: any) {
return function (this: any, key: string, value: any) {
if (stack.length > 0) {
const thisPos = stack.indexOf(this);
~thisPos ? stack.splice(thisPos + 1) : stack.push(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, Input} from "@angular/core";
import { Component, Input } from "@angular/core";

@Component({
standalone: false,
Expand Down
14 changes: 6 additions & 8 deletions projects/angular2-prettyjson/src/lib/prettyjson.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@ import { PrettyJsonPipe } from './prettyjson.pipe';
import { PrettyJsonComponent } from './prettyjson.component';

@NgModule({
imports: [ CommonModule ],
declarations: [
imports: [CommonModule],
declarations: [
PrettyJsonPipe,
SafeJsonPipe,
PrettyJsonComponent
],
exports: [
],
exports: [
PrettyJsonPipe,
SafeJsonPipe,
PrettyJsonComponent
]
]
})
export class PrettyJsonModule {

}
export class PrettyJsonModule { }
28 changes: 14 additions & 14 deletions projects/angular2-prettyjson/src/lib/prettyjson.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Pipe, PipeTransform} from "@angular/core";
import { Pipe, PipeTransform } from "@angular/core";
import { serializer as circularSerializer } from './json-utils';

@Pipe({
Expand All @@ -13,7 +13,7 @@ export class PrettyJsonPipe implements PipeTransform {

private _syntaxHighlight(json: any, serializer: any, spacing: number): string {
if (json === undefined) {
return '<span class="undefined"></span>';
return '<span class="undefined"></span>';
}
// Credits to the accepted answer here
// http://stackoverflow.com/questions/4810841/how-can-i-pretty-print-json-using-javascript
Expand All @@ -22,19 +22,19 @@ export class PrettyJsonPipe implements PipeTransform {
}
json = json.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, (match: any) => {
let cls = "number";
if (/^"/.test(match)) {
if (/:$/.test(match)) {
cls = "key";
} else {
cls = "string";
}
} else if (/true|false/.test(match)) {
cls = "boolean";
} else if (/null/.test(match)) {
cls = "null";
let cls = "number";
if (/^"/.test(match)) {
if (/:$/.test(match)) {
cls = "key";
} else {
cls = "string";
}
return `<span class="${cls}">${match}</span>`;
} else if (/true|false/.test(match)) {
cls = "boolean";
} else if (/null/.test(match)) {
cls = "null";
}
return `<span class="${cls}">${match}</span>`;
});
}
}
1 change: 0 additions & 1 deletion projects/demo/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { PrettyJsonModule } from '@talentia/angular2-prettyjson';
AppRoutingModule,
PrettyJsonModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }