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 .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ concurrency:
jobs:
build:

runs-on: ubuntu-latest
runs-on: ubuntu-24.04

strategy:
matrix:
node-version: [20.19.5]
node-version: [24.22.1]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish-oidc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:

publish-npm:
# needs: build
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
strategy:
matrix:
node-version: [20.19.5]
node-version: [24.22.1]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- name: Check out repo
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish-token.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:

publish-npm:
# needs: build
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
strategy:
matrix:
node-version: [20.19.5]
node-version: [24.22.1]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- name: Check out repo
Expand Down
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
24.22.1
60 changes: 60 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## What this is

`@talentia/angular2-prettyjson` is a **fork of [matiboy/angular2-prettyjson](https://github.com/matiboy/angular2-prettyjson)**
(git remote `upstream`), kept current with Angular by Talentia: two pipes and a component to
pretty-print JSON with syntax highlighting and circular-structure handling. It is consumed by
`@talentia/components` (core-components) and by the HCM front-end — check real usage there before
changing behavior or styles.

The workspace has two projects: the library (`projects/angular2-prettyjson`) and a demo app
(`projects/demo`). The library version follows the release branch name (e.g. `3.0.13`).

## Commands

```bash
npm run build # clean:build + build:prod — production library build (dist/angular2-prettyjson)
npm run build:dev # development build
npm start # build:dev + ng serve demo (http://localhost:4200)
npm run watch # lib + demo in watch mode
npm run demo:prod # production build of the demo (also demo:dev); CI runs build:prod + demo:prod
npm run lint # ng lint (lib + demo)
npm run lint:lib-fix # ng lint of the library with --fix
npm run update-browserslist
```

There is no test framework (no Jest/Karma, no `*.spec.ts`): verify in the demo or in a consumer.
Node version: `.nvmrc`.

## Architecture

Everything lives in `projects/angular2-prettyjson/src/lib/`:

- **`json-utils.ts`** — `serializer()`: a `JSON.stringify` replacer that turns circular references
into a placeholder instead of throwing.
- **`prettyjson-safe.pipe.ts`** — `SafeJsonPipe`, pipe name **`safejson`** (impure): like `json` but
circular-safe, optional `spaces` argument (default 2).
- **`prettyjson.pipe.ts`** — `PrettyJsonPipe`, pipe name `prettyjson` (impure): returns HTML where
keys/values are wrapped in `<span class="key|string|number|boolean|null">`, meant for `[innerHtml]`.
- **`prettyjson.component.ts`** — `PrettyJsonComponent` (`<prettyjson [obj]>`): a `<pre>` bound to
the `prettyjson` pipe. **`ViewEncapsulation.None` + host class `prettyjson`**: its styles are global
but scoped by that class (`.prettyjson .string { ... }`), because the spans are injected via
`[innerHtml]` and emulated encapsulation would never reach them. This replaced `::ng-deep` in
HCM-8031 with the same specificity, so consumers' overrides still win as before.
- **`prettyjson.module.ts`** — `PrettyJsonModule` declares/exports the pipes and the component (all
`standalone: false`); it does not import `CommonModule` (nothing in the template needs it).

## Working in this codebase

- Angular upgrades are done **without adopting new Angular features** (NgModule, `standalone: false`,
zone.js in the demo via `provideZoneChangeDetection()`).
- Any change to the component styles can affect consumer overrides: compare old/new demo builds
(computed styles of every span, pixel diff, typical override selectors). The HCM-8031 worklog in
`tmp/` has scripts for this (`tmp/HCM-8031/regression/compare.js` / `overrides.js`; pass absolute
paths).
- `@angular/*` versions are pinned exactly; peer range `^<major>.0.0`. No `overrides` in
`package.json`: transitive `@angular-devkit/*` are kept on the framework patch only by the lock.
- `tmp/` is git-ignored and may contain task worklogs/scripts.
56 changes: 38 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
# @talentia/angular2-prettyjson

An Angular module to pretty print JSON objects.
Contains a pipe similar to [JsonPipe](https://angular.io/docs/ts/latest/api/common/index/JsonPipe-class.html) but adds support for spacing and handling of circular structures.
Contains a pipe similar to [JsonPipe](https://angular.dev/api/common/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.

## Compatibility

| @talentia/angular2-prettyjson | Angular |
| ----------------------------- | ------- |
| 3.0.13 | 21.x |
| 3.0.12 | 20.x |
| 3.0.9 - 3.0.11 | 19.x |
| 3.0.7 - 3.0.8 | 18.x |
| 3.0.6 | 17.x |
| 3.0.4 - 3.0.5 | 16.x |
| 3.0.2 - 3.0.3 | 15.x |

## Install

```bash
Expand Down Expand Up @@ -35,7 +47,7 @@ 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.
The `SafeJsonPipe` (pipe name `safejson`) works like the `JsonPipe` but also handles circular structures. It also accepts an optional argument `spaces=2` for the JSON stringify spacing.

```ts
@Component({
Expand Down Expand Up @@ -74,7 +86,9 @@ The `PrettyJsonPipe` stringifies the object and then adds spans around propertie
...
```

A good set of styles to use is
The spans are injected via `[innerHtml]`, so Angular's emulated view encapsulation does not apply to them:
component `styles` will not reach them (unless using the discouraged `::ng-deep`).
Put the styles in a global stylesheet (e.g. `styles.css`). A good set of styles to use is

```css
pre span {white-space: normal;}
Expand All @@ -85,34 +99,40 @@ The `PrettyJsonPipe` stringifies the object and then adds spans around propertie
.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.
To keep them scoped, wrap the `pre` in an element with your own class and prefix the selectors, e.g.

```ts
@Component({
....
template: `
<pre [innerHtml]="circularObj | prettyjson:3"></pre>
`,
styles: [
`pre {outline: 1px solid #ccc; padding: 5px; margin: 5px; }
:host ::ng-deep span {white-space: normal;}
:host ::ng-deep .string { color: green; }
:host ::ng-deep .number { color: darkorange; }
:host ::ng-deep .boolean { color: blue; }
:host ::ng-deep .null { color: magenta; }
:host ::ng-deep .key { color: red; }`
]
<div class="my-json">
<pre [innerHtml]="circularObj | prettyjson:3"></pre>
</div>
`
})
...
```

```css
/* styles.css */
.my-json span {white-space: normal;}
.my-json .string { color: green; }
.my-json .number { color: darkorange; }
.my-json .boolean { color: blue; }
.my-json .null { color: magenta; }
.my-json .key { color: red; }
```

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.

The component host gets the `prettyjson` CSS class and its styles are scoped by it
(`.prettyjson .string`, `.prettyjson .key`, ...): to customize the colors, override those selectors
in a global stylesheet.

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

Make sure `PrettyJsonModule` is imported in your own module.
Expand All @@ -132,9 +152,9 @@ The `PrettyJsonPipe` stringifies the object and then adds spans around propertie

## Further help

This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 18.2.14.
This project currently uses [Angular CLI](https://github.com/angular/angular-cli) version 21.2.25.

To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.

## Reference

Expand Down
6 changes: 3 additions & 3 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@
}
}
},
"cli": {
"analytics": false
},
"schematics": {
"@schematics/angular:component": {
"type": "component"
Expand All @@ -132,5 +129,8 @@
"@schematics/angular:resolver": {
"typeSeparator": "."
}
},
"cli": {
"analytics": false
}
}
3 changes: 2 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// @ts-check
const eslint = require("@eslint/js");
const { defineConfig } = require("eslint/config");
const tseslint = require("typescript-eslint");
const angular = require("angular-eslint");

module.exports = tseslint.config(
module.exports = defineConfig(
{
files: ["**/*.ts"],
extends: [
Expand Down
Loading