Skip to content

[Replacement]: escape-html #945

Open

Description

@gameroman

Package to replace

escape-html

Suggested replacement(s)

const map = {
  '&': '&',
  '<': '&lt;',
  '>': '&gt;',
  '"': '&quot;',
  "'": '&#39;'
}

function escapeHtml(string) {
  return string.replace(/[&<>"']/g, char => map[char])
}

Manifest type

micro-utility (tiny utility replaceable with native code or removal)

Rationale

It's a simple util

Availability

No response

Code example (optional)

Activity

  1. 43081j commented on Aug 17, 2026

    @43081j
    Contributor

    it uses an iterative approach for performance reasons i imagine. since the early exit and the jump ahead is faster than a replace most likely.

    in common cases where that level of perf doesn't matter as much, your example does work well.

    i'm not sure if we should add it or not in that case though. let's see what @ghostdevv thinks

  2. gameroman commented on Aug 17, 2026

    @gameroman
    ContributorAuthor

    it uses an iterative approach for performance reasons i imagine. since the early exit and the jump ahead is faster than a replace most likely.

    in common cases where that level of perf doesn't matter as much, your example does work well.

    i'm not sure if we should add it or not in that case though. let's see what @ghostdevv thinks

    It is just an old package that wasn't updated for a decade, so that's why it uses that, not for perf reasons

  3. gameroman commented on Aug 26, 2026

    @gameroman
    ContributorAuthor

    Also html-escaper

  4. added
    acceptedUsed to signal if a suggested replacement has been accepted.
    on Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedUsed to signal if a suggested replacement has been accepted.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions