2.0.3 • Published 5 months ago

html-label-replacer-library v2.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
5 months ago

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;
2.0.3

5 months ago

2.0.2

5 months ago

2.0.1

5 months ago

2.0.0

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago