npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

edit-vs-json

v0.1.4

Published

A React JSON editor with syntax highlighting and auto-formatting

Downloads

43

Readme

edit-vs-json

This workspace has been generated by Nx, Smart Monorepos · Fast CI.

A JSON editor component for React applications.

  • provides on-the-fly JSON syntax highlighting
  • provides JSON formatting when you press the enter key
    • automatically wraps strings in quotes when missing
    • automatically adds an object value when a key is entered with no value complement
    • automatically provides closing punctuation to complete open braces, brackets, or quotes
    • adds trailing commas after the previous item as needed
  • removes trailing commas and revalidates when focus leaves the Editor
  • triggers an optional change event with the current JSON string value and a boolean indicating the validity of the JSON
  • triggers an optional key entry event when the Editor detects the user is editing an object key
    • can be used by the parent application to provide autocomplete-like functionality for object keys
    • can be used to restrict the object keys permitted in the Editor

NPM JavaScript Style Guide

Install

npm install --save edit-vs-json

or

yarn install edit-vs-json

Usage

import React, { FunctionComponent } from 'react'

import { Editor } from 'edit-vs-json';

const Example: FunctionComponent = () => {
    const [jsonIsValid, setJsonIsValid] = React.useState(true);
    
    const handleChange = (currentJsonValue: string, isValid: boolean) => {
      setJsonIsValid(isValid);
    };
    
    return (
        <Editor
          width="1400px"
          height="400px"
          onChange={handleChange}
          changeDebounceInterval={300}
        />
    );
}

Props

width: string = "100%"

the width of the JSON editor control

height: string = "100%"

the height of the JSON editor control

initValue: string = ""

the initial JSON string value for the Editor

onChange: optional function

onChange: (value: string, isValid: boolean) => void

the JSON editor change event handler, which receives 2 arguments:

  • the current JSON string value
  • a boolean indicating if the JSON is valid

changeDebounceInterval: number = 500

the debounce interval in ms for the change event

  • smaller values result in the change event being triggered more frequently
  • larger values cause the change event to be triggered only when editing pauses

onKeyEntry: optional function

onKeyEntry: (
  currentKey: string, 
  position: { x: number, y: number }, 
  callback: (newKey?: string | null)
) => void

the key entry event handler

  • the key entry event is triggered when the Editor detects the user is editing an object key
  • can be used to provide autocomplete-like functionality for keys to the Editor
  • can be used to restrict the keys permitted in the Editor
  • receives 3 arguments:
    • the key being edited
    • the position of the cursor relative to the Editor
    • a callback function that updates the key to the specified string

keyEntryDebounceInterval: number = 200

the debounce interval in ms for the key entry event

  • smaller values result in the key entry event being triggered more frequently
  • larger values cause the key entry event to be triggered only when editing the key pauses

locked: boolean = false

locks the editor when set to true

License

MIT © RichieMillennium