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

react-dynamic-parser

v1.0.0

Published

A React library for dynamic content parsing and form input

Downloads

5

Readme

React Dynamic Parser

A React library for dynamic content parsing and form input, allowing you to embed editable dynamic content into your React applications easily.

Features

  • Dynamic Content Parsing: Parse dynamic content embedded within text.
  • Customizable Inputs: Support for different input types (text, URL, number) based on the content type.
  • Custom Parsers: Ability to define custom parsers to fit specific needs.
  • Context-based State Management: Manage state seamlessly with React Context API.

Installation

Install the library using npm:

npm install react-dynamic-parser

Usage

import React from 'react';
import { DynamicContentProvider, DynamicContentDisplay, DynamicContentForm } from 'react-dynamic-parser';

const App = () => {
  const initialContent = "This is a sample content with [text:editable text] and [url:https://example.com]";

  return (
    <DynamicContentProvider initialContent={initialContent}>
      <DynamicContentDisplay />
      <DynamicContentForm />
    </DynamicContentProvider>
  );
};

export default App;

Custom Parsers

You can define custom parsers to parse content based on your requirements. Here's an example of a custom parser that parses content within square brackets:

const customParseContent = (content) => {
  // Custom parsing logic
  // Example: parse [bold:text] and [italic:text]
  const regex = /\[([^\]:]*):([^\]]+)\]/g;
  let match;
  const keyValuePairs = [];

  while ((match = regex.exec(content)) !== null) {
    keyValuePairs.push({ type: match[1], value: match[2], original: match[0] });
  }

  return keyValuePairs;
};

const App = () => {
  const initialContent = "This is a sample content with [bold:important text] and [italic:emphasized text]";

  return (
    <DynamicContentProvider initialContent={initialContent} parseContent={customParseContent}>
      <DynamicContentDisplay />
      <DynamicContentForm />
    </DynamicContentProvider>
  );
};

export default App;

Componnets

DynamicContentProvider

The provider component that initializes the context with the parsed content and manages state.

Props

  • initialContent (string): The initial content string to be parsed.
  • parseContent (function): Optional custom parser function.
<DynamicContentProvider 
    initialContent={initialContent} 
    parseContent={customParseContent}
>
  {children}

</DynamicContentProvider>

DynamicContentDisplay

The component responsible for rendering the dynamically generated content.

<DynamicContentDisplay />

DynamicContentForm

The component that renders the form inputs for editing the dynamic content.

<DynamicContentForm />

Example

Using Different Input Types

const initialContent = "Name: [text:John Doe], Age: [number:30], Website: [url:https://example.com]";

const App = () => {
  return (
    <DynamicContentProvider initialContent={initialContent}>
      <DynamicContentDisplay />
      <DynamicContentForm />
    </DynamicContentProvider>
  );
};

export default App;

Styling the Components

You can style the components by passing custom class names or using CSS modules.

/* App.css */
.input-container {
  margin-bottom: 1rem;
}

.input-container label {
  font-weight: bold;
}
import './App.css';

const App = () => {
  const initialContent = "Edit this text: [text:click to edit]";

  return (
    <DynamicContentProvider initialContent={initialContent}>
      <DynamicContentDisplay />
      <DynamicContentForm />
    </DynamicContentProvider>
  );
};

export default App;

API

DynamicContentProvider

| Prop | Type | Description | | --- | --- | --- | | initialContent | string | The initial content string to be parsed. | | parseContent | function | Optional custom parser function. |

DynamicContentDisplay

No props. Uses context to display the generated content.

DynamicContentForm

No props. Uses context to display and manage form inputs.

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue if you have any suggestions or feedback.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgements Note

By following this detailed README, users will have a clear understanding of how to install, use, and customize the ReactDynamicParser library.