html-label-replacer-library

2.0.3 • Public • Published

HTML Label Replacer Library

This library provides a function to replace label placeholders in an HTML string with corresponding values from a provided JSON object.

Installation

Install the library using npm:

import React, { useEffect, useState } from 'react';
import replaceLabels from 'html-label-replacer-library';

const YourComponent = () => {
  const [modifiedHTML, setModifiedHTML] = useState('');

  useEffect(() => {
    const labels = {
      L001: 'HELLO',
      L002: 'visit my homepage <a href="www.abc.com" > here </a>',
      L003: 'https://pbs.twimg.com/profile_images/1701878932176351232/AlNU3WTK_400x400.jpg',
    };

    const htmlString = `
      <div>
        <h1>{{L001}}</h1>
        <p>{{L002}}</p>
        <img src="{{L003}}" alt="Test Image" />
      </div>
    `;

    const modified = replaceLabels(htmlString, labels);

    const parsedHTML = React.createElement('div', {
      dangerouslySetInnerHTML: { __html: modified },
    });

    setModifiedHTML(parsedHTML);
  }, []);

  return (
    <div>
      <p>Modified HTML:</p>
      {modifiedHTML}
    </div>
  );
};

export default YourComponent;

Readme

Keywords

none

Package Sidebar

Install

npm i html-label-replacer-library

Weekly Downloads

0

Version

2.0.3

License

ISC

Unpacked Size

2.84 kB

Total Files

3

Last publish

Collaborators

  • ateeb