How to use string-replace-to-array - 8 common examples

To help you get started, we’ve selected a few string-replace-to-array examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github withspectrum / spectrum / src / views / thread / components / sidebar.js View on Github external
const renderDescriptionWithLinks = text => {
  return replace(text, MARKDOWN_LINK, (fullLink, text, url) => (
    <a rel="noopener noreferrer" href="{url}">
      {text}
    </a>
  ));
};
github tommoor / react-emoji-render / src / renderer.js View on Github external
let textWithoutAsciiAliases = textWithAsciiAliases;

    while (previousTextWithoutAsciiAliases !== textWithoutAsciiAliases) {
      previousTextWithoutAsciiAliases = textWithoutAsciiAliases;
      textWithoutAsciiAliases = textWithoutAsciiAliases.replace(
        asciiAliasesRegex,
        replaceAsciiAliases
      );
    }

    return textWithoutAsciiAliases;
  }

  const textWithouAsciiAliases = replaceAllAsciiAliases(text);

  return replace(
    textWithouAsciiAliases.replace(aliasesRegex, replaceAliases),
    unicodeEmojiRegex,
    replaceUnicodeEmoji
  );
}
github withspectrum / spectrum / src / helpers / utils.js View on Github external
export const renderMarkdownLinks = (text: string) =&gt; {
  const MARKDOWN_LINK = /(?:\[(.*?)\]\((.*?)\))/g;

  return replace(text, MARKDOWN_LINK, (fullLink, text, url) =&gt; (
    <a rel="noopener noreferrer" href="{url}">
      {text}
    </a>
  ));
};
github withspectrum / spectrum / src / components / bubbles / index.js View on Github external
export const renderLinks = text =&gt; {
  return replace(text, URL, (fullLink, text, url) =&gt; (
    <a rel="noopener nofollower" href="{url}">
      {text}
    </a>
  ));
};
github outline / outline / app / components / Highlight.js View on Github external
text,
  ...rest
}: Props) {
  let regex;
  if (highlight instanceof RegExp) {
    regex = highlight;
  } else {
    regex = new RegExp(
      (highlight || '').replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&amp;'),
      caseSensitive ? 'g' : 'gi'
    );
  }
  return (
    <span>
      {highlight
        ? replace(text, regex, (tag, index) =&gt; (
            <mark>{processResult ? processResult(tag) : tag}</mark>
          ))
        : text}
    </span>
  );
}
github theopolisme / fast-courses / fast-courses-app / src / util.js View on Github external
export function formatCourseDescription(raw, nameFormatter) {
  return raw ? replace(raw, COURSE_REGEX, nameFormatter) : '';
}
github withspectrum / spectrum / src / helpers / render-text-with-markdown-links.js View on Github external
export default (text: string) =&gt; {
  return replace(text, MARKDOWN_LINK, (fullLink, text, url) =&gt; {
    const regexp = new RegExp(SPECTRUM_URLS, 'ig');
    const match = regexp.exec(url);

    if (match &amp;&amp; match[0] &amp;&amp; match[1]) return {text};

    return (
      <a rel="noopener noreferrer" href="{url}">
        {text}
      </a>
    );
  });
};

string-replace-to-array

Works like String.prototype.replace but outputs an array. Useful for replacing parts of the string with objects of other types.

MIT
Latest version published 5 months ago

Package Health Score

64 / 100
Full package analysis

Popular string-replace-to-array functions