lodash#escape TypeScript Examples

The following examples show how to use lodash#escape. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LogDisplay.tsx    From next-basics with GNU General Public License v3.0 6 votes vote down vote up
export function LogDisplay(props: LogDisplayProps): React.ReactElement {
  const { loadingIcon = true, hasBackspace, containerStyle } = props;
  const value = useMemo(
    () => (hasBackspace ? handleBackspace(props.value) : props.value),
    [props.value, hasBackspace]
  );

  const ellipsis = (
    <div className={style.ellipsis}>
      <span />
      <span />
      <span />
      <span />
    </div>
  );

  return (
    <pre className={style.terminal} style={containerStyle}>
      <div dangerouslySetInnerHTML={{ __html: escape(value) }}></div>
      {loadingIcon && ellipsis}
    </pre>
  );
}
Example #2
Source File: index.ts    From querybook with Apache License 2.0 6 votes vote down vote up
export function linkifyLog(log: string) {
    // https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url
    const urlRegex = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}(\.[a-z]{2,6})?\b([-a-zA-Z0-9@:%_\+.~#?&\/=]*)/;
    const processedParts: string[] = [];

    while (true) {
        const match = log.match(urlRegex);
        if (match) {
            const url = match[0];
            const matchStart = match.index;
            const matchEnd = match.index + url.length;

            const partBeforeMatch = log.slice(0, matchStart);
            log = log.slice(matchEnd);
            processedParts.push(escape(partBeforeMatch));
            processedParts.push(
                `<a target="_blank" rel="noopener noreferrer" href="${url}">${url}</a>`
            );
        } else {
            processedParts.push(escape(log));
            break;
        }
    }
    return processedParts.join('');
}