Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

json-lighter

Package Overview
Dependencies
Maintainers
0
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-lighter

A lightweight JSON syntax highlighter for the web.

  • 0.1.1
  • unpublished
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
0
Weekly downloads
 
Created
Source

json-lighter

A lightweight JSON syntax highlighter for the web.

Installation

npm install json-lighter

Usage

import { JsonLighter } from "json-lighter";

const lighter = new JsonLighter({
  spaces: 2,
  colors: {
    punctuation: "gray",
    string: "orange",
    number: "green",
    boolean: "purple",
    null: "blue",
  },
});

// Inject the CSS into the document
lighter.injectCSS();

// Highlight JSON
const html = lighter.highlight(`
  {
    "string": "value",
    "number": 123.123,
    "boolean": false,
    "null": null
  }
`);

## API

### `JsonLighter(options)`

Creates a new instance of JsonLighter.

#### Options

- `spaces` (number): Number of spaces for indentation.
- `colors` (object): Custom colors for different JSON elements
  - `punctuation` (string): Color for punctuation characters
  - `string` (string): Color for string values
  - `number` (string): Color for number values
  - `boolean` (string): Color for boolean values
  - `null` (string): Color for null values

### `lighter.injectCSS()`

Injects the necessary CSS into the document's head. Call this once before using the `highlight` method.

### `lighter.highlight(json)`

Highlights the provided JSON string and returns HTML with syntax highlighting.

#### Parameters

- `json` (string): The JSON string to highlight

#### Returns

- (string): HTML string with syntax highlighting

FAQs

Package last updated on 16 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc