github.com Open in urlscan Pro
140.82.121.3  Public Scan

Submitted URL: https://mths.be/he
Effective URL: https://github.com/mathiasbynens/he
Submission: On December 29 via api from US — Scanned from NL

Form analysis 1 forms found in the DOM

GET /mathiasbynens/he/search

<form class="js-site-search-form" role="search" aria-label="Site" data-scope-type="Repository" data-scope-id="10930707" data-scoped-search-url="/mathiasbynens/he/search" data-owner-scoped-search-url="/users/mathiasbynens/search"
  data-unscoped-search-url="/search" data-turbo="false" action="/mathiasbynens/he/search" accept-charset="UTF-8" method="get">
  <label class="form-control header-search-wrapper input-sm p-0 js-chromeless-input-container header-search-wrapper-jump-to position-relative d-flex flex-justify-between flex-items-center">
    <input type="text" class="form-control js-site-search-focus header-search-input jump-to-field js-jump-to-field js-site-search-field is-clearable" data-hotkey="s,/" name="q" data-test-selector="nav-search-input" placeholder="Search"
      data-unscoped-placeholder="Search GitHub" data-scoped-placeholder="Search" autocapitalize="off" role="combobox" aria-haspopup="listbox" aria-expanded="false" aria-autocomplete="list" aria-controls="jump-to-results" aria-label="Search"
      data-jump-to-suggestions-path="/_graphql/GetSuggestedNavigationDestinations" spellcheck="false" autocomplete="off">
    <input type="hidden" data-csrf="true" class="js-data-jump-to-suggestions-path-csrf" value="rW0vyF/ssI7hAkQrBo23xswTbY0el19MKwZCqUqHkBbe2AB/ngge8dWmveJh+7eH1st2FC3bzvRi+BpfVA08yA==">
    <input type="hidden" class="js-site-search-type-field" name="type">
    <svg xmlns="http://www.w3.org/2000/svg" width="22" height="20" aria-hidden="true" class="mr-1 header-search-key-slash">
      <path fill="none" stroke="#979A9C" opacity=".4" d="M3.5.5h12c1.7 0 3 1.3 3 3v13c0 1.7-1.3 3-3 3h-12c-1.7 0-3-1.3-3-3v-13c0-1.7 1.3-3 3-3z"></path>
      <path fill="#979A9C" d="M11.8 6L8 15.1h-.9L10.8 6h1z"></path>
    </svg>
    <div class="Box position-absolute overflow-hidden d-none jump-to-suggestions js-jump-to-suggestions-container">
      <ul class="d-none js-jump-to-suggestions-template-container">
        <li class="d-flex flex-justify-start flex-items-center p-0 f5 navigation-item js-navigation-item js-jump-to-suggestion" role="option">
          <a tabindex="-1" class="no-underline d-flex flex-auto flex-items-center jump-to-suggestions-path js-jump-to-suggestion-path js-navigation-open p-2" href="" data-item-type="suggestion">
    <div class="jump-to-octicon js-jump-to-octicon flex-shrink-0 mr-2 text-center d-none">
      <svg title="Repository" aria-label="Repository" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-repo js-jump-to-octicon-repo d-none flex-shrink-0">
    <path fill-rule="evenodd" d="M2 2.5A2.5 2.5 0 014.5 0h8.75a.75.75 0 01.75.75v12.5a.75.75 0 01-.75.75h-2.5a.75.75 0 110-1.5h1.75v-2h-8a1 1 0 00-.714 1.7.75.75 0 01-1.072 1.05A2.495 2.495 0 012 11.5v-9zm10.5-1V9h-8c-.356 0-.694.074-1 .208V2.5a1 1 0 011-1h8zM5 12.25v3.25a.25.25 0 00.4.2l1.45-1.087a.25.25 0 01.3 0L8.6 15.7a.25.25 0 00.4-.2v-3.25a.25.25 0 00-.25-.25h-3.5a.25.25 0 00-.25.25z"></path>
</svg>
      <svg title="Project" aria-label="Project" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-project js-jump-to-octicon-project d-none flex-shrink-0">
    <path fill-rule="evenodd" d="M1.75 0A1.75 1.75 0 000 1.75v12.5C0 15.216.784 16 1.75 16h12.5A1.75 1.75 0 0016 14.25V1.75A1.75 1.75 0 0014.25 0H1.75zM1.5 1.75a.25.25 0 01.25-.25h12.5a.25.25 0 01.25.25v12.5a.25.25 0 01-.25.25H1.75a.25.25 0 01-.25-.25V1.75zM11.75 3a.75.75 0 00-.75.75v7.5a.75.75 0 001.5 0v-7.5a.75.75 0 00-.75-.75zm-8.25.75a.75.75 0 011.5 0v5.5a.75.75 0 01-1.5 0v-5.5zM8 3a.75.75 0 00-.75.75v3.5a.75.75 0 001.5 0v-3.5A.75.75 0 008 3z"></path>
</svg>
      <svg title="Search" aria-label="Search" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-search js-jump-to-octicon-search d-none flex-shrink-0">
    <path fill-rule="evenodd" d="M11.5 7a4.499 4.499 0 11-8.998 0A4.499 4.499 0 0111.5 7zm-.82 4.74a6 6 0 111.06-1.06l3.04 3.04a.75.75 0 11-1.06 1.06l-3.04-3.04z"></path>
</svg>
    </div>

    <img class="avatar mr-2 flex-shrink-0 js-jump-to-suggestion-avatar d-none" alt="" aria-label="Team" src="" width="28" height="28">

    <div class="jump-to-suggestion-name js-jump-to-suggestion-name flex-auto overflow-hidden text-left no-wrap css-truncate css-truncate-target">
    </div>

    <div class="border rounded-2 flex-shrink-0 color-bg-subtle px-1 color-fg-muted ml-1 f6 d-none js-jump-to-badge-search">
      <span class="js-jump-to-badge-search-text-default d-none" aria-label="in this repository">
        In this repository
      </span>
      <span class="js-jump-to-badge-search-text-global d-none" aria-label="in all of GitHub">
        All GitHub
      </span>
      <span aria-hidden="true" class="d-inline-block ml-1 v-align-middle">↵</span>
    </div>

    <div aria-hidden="true" class="border rounded-2 flex-shrink-0 color-bg-subtle px-1 color-fg-muted ml-1 f6 d-none d-on-nav-focus js-jump-to-badge-jump">
      Jump to
      <span class="d-inline-block ml-1 v-align-middle">↵</span>
    </div>
  </a>
        </li>
      </ul>
      <ul class="d-none js-jump-to-no-results-template-container">
        <li class="d-flex flex-justify-center flex-items-center f5 d-none js-jump-to-suggestion p-2">
          <span class="color-fg-muted">No suggested jump to results</span>
        </li>
      </ul>
      <ul id="jump-to-results" role="listbox" class="p-0 m-0 js-navigation-container jump-to-suggestions-results-container js-jump-to-suggestions-results-container">
        <li class="d-flex flex-justify-start flex-items-center p-0 f5 navigation-item js-navigation-item js-jump-to-scoped-search d-none" role="option">
          <a tabindex="-1" class="no-underline d-flex flex-auto flex-items-center jump-to-suggestions-path js-jump-to-suggestion-path js-navigation-open p-2" href="" data-item-type="scoped_search">
    <div class="jump-to-octicon js-jump-to-octicon flex-shrink-0 mr-2 text-center d-none">
      <svg title="Repository" aria-label="Repository" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-repo js-jump-to-octicon-repo d-none flex-shrink-0">
    <path fill-rule="evenodd" d="M2 2.5A2.5 2.5 0 014.5 0h8.75a.75.75 0 01.75.75v12.5a.75.75 0 01-.75.75h-2.5a.75.75 0 110-1.5h1.75v-2h-8a1 1 0 00-.714 1.7.75.75 0 01-1.072 1.05A2.495 2.495 0 012 11.5v-9zm10.5-1V9h-8c-.356 0-.694.074-1 .208V2.5a1 1 0 011-1h8zM5 12.25v3.25a.25.25 0 00.4.2l1.45-1.087a.25.25 0 01.3 0L8.6 15.7a.25.25 0 00.4-.2v-3.25a.25.25 0 00-.25-.25h-3.5a.25.25 0 00-.25.25z"></path>
</svg>
      <svg title="Project" aria-label="Project" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-project js-jump-to-octicon-project d-none flex-shrink-0">
    <path fill-rule="evenodd" d="M1.75 0A1.75 1.75 0 000 1.75v12.5C0 15.216.784 16 1.75 16h12.5A1.75 1.75 0 0016 14.25V1.75A1.75 1.75 0 0014.25 0H1.75zM1.5 1.75a.25.25 0 01.25-.25h12.5a.25.25 0 01.25.25v12.5a.25.25 0 01-.25.25H1.75a.25.25 0 01-.25-.25V1.75zM11.75 3a.75.75 0 00-.75.75v7.5a.75.75 0 001.5 0v-7.5a.75.75 0 00-.75-.75zm-8.25.75a.75.75 0 011.5 0v5.5a.75.75 0 01-1.5 0v-5.5zM8 3a.75.75 0 00-.75.75v3.5a.75.75 0 001.5 0v-3.5A.75.75 0 008 3z"></path>
</svg>
      <svg title="Search" aria-label="Search" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-search js-jump-to-octicon-search d-none flex-shrink-0">
    <path fill-rule="evenodd" d="M11.5 7a4.499 4.499 0 11-8.998 0A4.499 4.499 0 0111.5 7zm-.82 4.74a6 6 0 111.06-1.06l3.04 3.04a.75.75 0 11-1.06 1.06l-3.04-3.04z"></path>
</svg>
    </div>

    <img class="avatar mr-2 flex-shrink-0 js-jump-to-suggestion-avatar d-none" alt="" aria-label="Team" src="" width="28" height="28">

    <div class="jump-to-suggestion-name js-jump-to-suggestion-name flex-auto overflow-hidden text-left no-wrap css-truncate css-truncate-target">
    </div>

    <div class="border rounded-2 flex-shrink-0 color-bg-subtle px-1 color-fg-muted ml-1 f6 d-none js-jump-to-badge-search">
      <span class="js-jump-to-badge-search-text-default d-none" aria-label="in this repository">
        In this repository
      </span>
      <span class="js-jump-to-badge-search-text-global d-none" aria-label="in all of GitHub">
        All GitHub
      </span>
      <span aria-hidden="true" class="d-inline-block ml-1 v-align-middle">↵</span>
    </div>

    <div aria-hidden="true" class="border rounded-2 flex-shrink-0 color-bg-subtle px-1 color-fg-muted ml-1 f6 d-none d-on-nav-focus js-jump-to-badge-jump">
      Jump to
      <span class="d-inline-block ml-1 v-align-middle">↵</span>
    </div>
  </a>
        </li>
        <li class="d-flex flex-justify-start flex-items-center p-0 f5 navigation-item js-navigation-item js-jump-to-owner-scoped-search d-none" role="option">
          <a tabindex="-1" class="no-underline d-flex flex-auto flex-items-center jump-to-suggestions-path js-jump-to-suggestion-path js-navigation-open p-2" href="" data-item-type="owner_scoped_search">
    <div class="jump-to-octicon js-jump-to-octicon flex-shrink-0 mr-2 text-center d-none">
      <svg title="Repository" aria-label="Repository" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-repo js-jump-to-octicon-repo d-none flex-shrink-0">
    <path fill-rule="evenodd" d="M2 2.5A2.5 2.5 0 014.5 0h8.75a.75.75 0 01.75.75v12.5a.75.75 0 01-.75.75h-2.5a.75.75 0 110-1.5h1.75v-2h-8a1 1 0 00-.714 1.7.75.75 0 01-1.072 1.05A2.495 2.495 0 012 11.5v-9zm10.5-1V9h-8c-.356 0-.694.074-1 .208V2.5a1 1 0 011-1h8zM5 12.25v3.25a.25.25 0 00.4.2l1.45-1.087a.25.25 0 01.3 0L8.6 15.7a.25.25 0 00.4-.2v-3.25a.25.25 0 00-.25-.25h-3.5a.25.25 0 00-.25.25z"></path>
</svg>
      <svg title="Project" aria-label="Project" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-project js-jump-to-octicon-project d-none flex-shrink-0">
    <path fill-rule="evenodd" d="M1.75 0A1.75 1.75 0 000 1.75v12.5C0 15.216.784 16 1.75 16h12.5A1.75 1.75 0 0016 14.25V1.75A1.75 1.75 0 0014.25 0H1.75zM1.5 1.75a.25.25 0 01.25-.25h12.5a.25.25 0 01.25.25v12.5a.25.25 0 01-.25.25H1.75a.25.25 0 01-.25-.25V1.75zM11.75 3a.75.75 0 00-.75.75v7.5a.75.75 0 001.5 0v-7.5a.75.75 0 00-.75-.75zm-8.25.75a.75.75 0 011.5 0v5.5a.75.75 0 01-1.5 0v-5.5zM8 3a.75.75 0 00-.75.75v3.5a.75.75 0 001.5 0v-3.5A.75.75 0 008 3z"></path>
</svg>
      <svg title="Search" aria-label="Search" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-search js-jump-to-octicon-search d-none flex-shrink-0">
    <path fill-rule="evenodd" d="M11.5 7a4.499 4.499 0 11-8.998 0A4.499 4.499 0 0111.5 7zm-.82 4.74a6 6 0 111.06-1.06l3.04 3.04a.75.75 0 11-1.06 1.06l-3.04-3.04z"></path>
</svg>
    </div>

    <img class="avatar mr-2 flex-shrink-0 js-jump-to-suggestion-avatar d-none" alt="" aria-label="Team" src="" width="28" height="28">

    <div class="jump-to-suggestion-name js-jump-to-suggestion-name flex-auto overflow-hidden text-left no-wrap css-truncate css-truncate-target">
    </div>

    <div class="border rounded-2 flex-shrink-0 color-bg-subtle px-1 color-fg-muted ml-1 f6 d-none js-jump-to-badge-search">
      <span class="js-jump-to-badge-search-text-default d-none" aria-label="in this user">
        In this user
      </span>
      <span class="js-jump-to-badge-search-text-global d-none" aria-label="in all of GitHub">
        All GitHub
      </span>
      <span aria-hidden="true" class="d-inline-block ml-1 v-align-middle">↵</span>
    </div>

    <div aria-hidden="true" class="border rounded-2 flex-shrink-0 color-bg-subtle px-1 color-fg-muted ml-1 f6 d-none d-on-nav-focus js-jump-to-badge-jump">
      Jump to
      <span class="d-inline-block ml-1 v-align-middle">↵</span>
    </div>
  </a>
        </li>
        <li class="d-flex flex-justify-start flex-items-center p-0 f5 navigation-item js-navigation-item js-jump-to-global-search d-none" role="option">
          <a tabindex="-1" class="no-underline d-flex flex-auto flex-items-center jump-to-suggestions-path js-jump-to-suggestion-path js-navigation-open p-2" href="" data-item-type="global_search">
    <div class="jump-to-octicon js-jump-to-octicon flex-shrink-0 mr-2 text-center d-none">
      <svg title="Repository" aria-label="Repository" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-repo js-jump-to-octicon-repo d-none flex-shrink-0">
    <path fill-rule="evenodd" d="M2 2.5A2.5 2.5 0 014.5 0h8.75a.75.75 0 01.75.75v12.5a.75.75 0 01-.75.75h-2.5a.75.75 0 110-1.5h1.75v-2h-8a1 1 0 00-.714 1.7.75.75 0 01-1.072 1.05A2.495 2.495 0 012 11.5v-9zm10.5-1V9h-8c-.356 0-.694.074-1 .208V2.5a1 1 0 011-1h8zM5 12.25v3.25a.25.25 0 00.4.2l1.45-1.087a.25.25 0 01.3 0L8.6 15.7a.25.25 0 00.4-.2v-3.25a.25.25 0 00-.25-.25h-3.5a.25.25 0 00-.25.25z"></path>
</svg>
      <svg title="Project" aria-label="Project" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-project js-jump-to-octicon-project d-none flex-shrink-0">
    <path fill-rule="evenodd" d="M1.75 0A1.75 1.75 0 000 1.75v12.5C0 15.216.784 16 1.75 16h12.5A1.75 1.75 0 0016 14.25V1.75A1.75 1.75 0 0014.25 0H1.75zM1.5 1.75a.25.25 0 01.25-.25h12.5a.25.25 0 01.25.25v12.5a.25.25 0 01-.25.25H1.75a.25.25 0 01-.25-.25V1.75zM11.75 3a.75.75 0 00-.75.75v7.5a.75.75 0 001.5 0v-7.5a.75.75 0 00-.75-.75zm-8.25.75a.75.75 0 011.5 0v5.5a.75.75 0 01-1.5 0v-5.5zM8 3a.75.75 0 00-.75.75v3.5a.75.75 0 001.5 0v-3.5A.75.75 0 008 3z"></path>
</svg>
      <svg title="Search" aria-label="Search" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-search js-jump-to-octicon-search d-none flex-shrink-0">
    <path fill-rule="evenodd" d="M11.5 7a4.499 4.499 0 11-8.998 0A4.499 4.499 0 0111.5 7zm-.82 4.74a6 6 0 111.06-1.06l3.04 3.04a.75.75 0 11-1.06 1.06l-3.04-3.04z"></path>
</svg>
    </div>

    <img class="avatar mr-2 flex-shrink-0 js-jump-to-suggestion-avatar d-none" alt="" aria-label="Team" src="" width="28" height="28">

    <div class="jump-to-suggestion-name js-jump-to-suggestion-name flex-auto overflow-hidden text-left no-wrap css-truncate css-truncate-target">
    </div>

    <div class="border rounded-2 flex-shrink-0 color-bg-subtle px-1 color-fg-muted ml-1 f6 d-none js-jump-to-badge-search">
      <span class="js-jump-to-badge-search-text-default d-none" aria-label="in this repository">
        In this repository
      </span>
      <span class="js-jump-to-badge-search-text-global d-none" aria-label="in all of GitHub">
        All GitHub
      </span>
      <span aria-hidden="true" class="d-inline-block ml-1 v-align-middle">↵</span>
    </div>

    <div aria-hidden="true" class="border rounded-2 flex-shrink-0 color-bg-subtle px-1 color-fg-muted ml-1 f6 d-none d-on-nav-focus js-jump-to-badge-jump">
      Jump to
      <span class="d-inline-block ml-1 v-align-middle">↵</span>
    </div>
  </a>
        </li>
      </ul>
    </div>
  </label>
</form>

Text Content

Skip to content
Toggle navigation
Sign up

 * Product
    * Actions
      Automate any workflow
    * Packages
      Host and manage packages
    * Security
      Find and fix vulnerabilities
    * Codespaces
      Instant dev environments
    * Copilot
      Write better code with AI
    * Code review
      Manage code changes
    * Issues
      Plan and track work
    * Discussions
      Collaborate outside of code
   
    * Explore
    * All features
    * Documentation
    * GitHub Skills
    * Blog

 * Solutions
    * For
    * Enterprise
    * Teams
    * Startups
    * Education
   
    * By Solution
    * CI/CD & Automation
    * DevOps
    * DevSecOps
   
    * Case Studies
    * Customer Stories
    * Resources

 * Open Source
    * GitHub Sponsors
      Fund open source developers
   
    * The ReadME Project
      GitHub community articles
   
    * Repositories
    * Topics
    * Trending
    * Collections

 * Pricing

 * In this repository All GitHub ↵
   Jump to ↵

 * No suggested jump to results

 * In this repository All GitHub ↵
   Jump to ↵
 * In this user All GitHub ↵
   Jump to ↵
 * In this repository All GitHub ↵
   Jump to ↵

Sign in
Sign up

{{ message }}
mathiasbynens / he Public
 * Notifications
 * Fork 254
 * Star 3.2k

A robust HTML entity encoder/decoder written in JavaScript.

mths.be/he


LICENSE

MIT license
3.2k stars 254 forks
Star
Notifications
 * Code
 * Issues 19
 * Pull requests 3
 * Actions
 * Projects 0
 * Security
 * Insights

More
 * Code
 * Issues
 * Pull requests
 * Actions
 * Projects
 * Security
 * Insights


MATHIASBYNENS/HE

This commit does not belong to any branch on this repository, and may belong to
a fork outside of the repository.
master
Switch branches/tags

Branches Tags
Could not load branches
Nothing to show

{{ refName }} default
View all branches
Could not load tags
Nothing to show
{{ refName }} default

View all tags


NAME ALREADY IN USE


A tag already exists with the provided branch name. Many Git commands accept
both tag and branch names, so creating this branch may cause unexpected
behavior. Are you sure you want to create this branch?
Cancel Create
2 branches 27 tags

Go to file Code
 * Local
 * Codespaces

 * Clone
   HTTPS GitHub CLI
   
   Use Git or checkout with SVN using the web URL.
   
   Work fast with our official CLI. Learn more.

 * Open with GitHub Desktop
 * Download ZIP

SIGN IN REQUIRED

Please sign in to use Codespaces.

LAUNCHING GITHUB DESKTOP

If nothing happens, download GitHub Desktop and try again.

LAUNCHING GITHUB DESKTOP

If nothing happens, download GitHub Desktop and try again.

LAUNCHING XCODE

If nothing happens, download Xcode and try again.

LAUNCHING VISUAL STUDIO CODE

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.


LATEST COMMIT

mathiasbynens Release v1.2.0
…
36afe17 Sep 23, 2018
Release v1.2.0
36afe17


GIT STATS

 * 140 commits


FILES

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
bin
bin: Return with exit status 0 when calling with -v
Apr 5, 2016
data
Update build scripts and data
Apr 4, 2016
man
bin: Return with exit status 0 when calling with -v
Apr 5, 2016
scripts
Handle legacy named character references correctly
Sep 23, 2018
src
Handle legacy named character references correctly
Sep 23, 2018
tests
Handle legacy named character references correctly
Sep 23, 2018
.editorconfig
Update build scripts and data
Apr 4, 2016
.gitattributes
Add Git configuration files
Jun 25, 2013
.gitignore
Set up Coveralls
May 25, 2014
.travis.yml
Update build scripts and data
Apr 4, 2016
Gruntfile.js
Use Codecov instead of Coveralls
Aug 31, 2015
LICENSE-MIT.txt
Update URLs
Aug 24, 2014
README.md
Improve he.encode documentation
Aug 31, 2016
bower.json
Release v1.1.1
Jan 23, 2017
component.json
Release v1.1.1
Jan 23, 2017
he.js
Release v1.2.0
Sep 23, 2018
package.json
Release v1.2.0
Sep 23, 2018
View code
he Installation API he.version he.encode(text, options) useNamedReferences
decimal encodeEverything strict allowUnsafeSymbols Overriding default encode
options globally he.decode(html, options) isAttributeValue strict Overriding
default decode options globally he.escape(text) he.unescape(html, options) Using
the he binary Support Unit tests & code coverage Acknowledgements Author License


README.MD


HE

he (for “HTML entities”) is a robust HTML entity encoder/decoder written in
JavaScript. It supports all standardized named character references as per HTML,
handles ambiguous ampersands and other edge cases just like a browser would, has
an extensive test suite, and — contrary to many other JavaScript solutions — he
handles astral Unicode symbols just fine. An online demo is available.


INSTALLATION

Via npm:

npm install he



Via Bower:

bower install he



Via Component:

component install mathiasbynens/he



In a browser:

<script src="he.js"></script>



In Node.js, io.js, Narwhal, and RingoJS:

var he = require('he');



In Rhino:

load('he.js');



Using an AMD loader like RequireJS:

require(
  {
    'paths': {
      'he': 'path/to/he'
    }
  },
  ['he'],
  function(he) {
    console.log(he);
  }
);




API


HE.VERSION

A string representing the semantic version number.


HE.ENCODE(TEXT, OPTIONS)

This function takes a string of text and encodes (by default) any symbols that
aren’t printable ASCII symbols and &, <, >, ", ', and `, replacing them with
character references.

he.encode('foo © bar ≠ baz 𝌆 qux');
// → 'foo &#xA9; bar &#x2260; baz &#x1D306; qux'



As long as the input string contains allowed code points only, the return value
of this function is always valid HTML. Any (invalid) code points that cannot be
represented using a character reference in the input are not encoded:

he.encode('foo \0 bar');
// → 'foo \0 bar'



However, enabling the strict option causes invalid code points to throw an
exception. With strict enabled, he.encode either throws (if the input contains
invalid code points) or returns a string of valid HTML.

The options object is optional. It recognizes the following properties:

USENAMEDREFERENCES

The default value for the useNamedReferences option is false. This means that
encode() will not use any named character references (e.g. &copy;) in the output
— hexadecimal escapes (e.g. &#xA9;) will be used instead. Set it to true to
enable the use of named references.

Note that if compatibility with older browsers is a concern, this option should
remain disabled.

// Using the global default setting (defaults to `false`):
he.encode('foo © bar ≠ baz 𝌆 qux');
// → 'foo &#xA9; bar &#x2260; baz &#x1D306; qux'

// Passing an `options` object to `encode`, to explicitly disallow named references:
he.encode('foo © bar ≠ baz 𝌆 qux', {
  'useNamedReferences': false
});
// → 'foo &#xA9; bar &#x2260; baz &#x1D306; qux'

// Passing an `options` object to `encode`, to explicitly allow named references:
he.encode('foo © bar ≠ baz 𝌆 qux', {
  'useNamedReferences': true
});
// → 'foo &copy; bar &ne; baz &#x1D306; qux'



DECIMAL

The default value for the decimal option is false. If the option is enabled,
encode will generally use decimal escapes (e.g. &#169;) rather than hexadecimal
escapes (e.g. &#xA9;). Beside of this replacement, the basic behavior remains
the same when combined with other options. For example: if both options
useNamedReferences and decimal are enabled, named references (e.g. &copy;) are
used over decimal escapes. HTML entities without a named reference are encoded
using decimal escapes.

// Using the global default setting (defaults to `false`):
he.encode('foo © bar ≠ baz 𝌆 qux');
// → 'foo &#xA9; bar &#x2260; baz &#x1D306; qux'

// Passing an `options` object to `encode`, to explicitly disable decimal escapes:
he.encode('foo © bar ≠ baz 𝌆 qux', {
  'decimal': false
});
// → 'foo &#xA9; bar &#x2260; baz &#x1D306; qux'

// Passing an `options` object to `encode`, to explicitly enable decimal escapes:
he.encode('foo © bar ≠ baz 𝌆 qux', {
  'decimal': true
});
// → 'foo &#169; bar &#8800; baz &#119558; qux'

// Passing an `options` object to `encode`, to explicitly allow named references and decimal escapes:
he.encode('foo © bar ≠ baz 𝌆 qux', {
  'useNamedReferences': true,
  'decimal': true
});
// → 'foo &copy; bar &ne; baz &#119558; qux'



ENCODEEVERYTHING

The default value for the encodeEverything option is false. This means that
encode() will not use any character references for printable ASCII symbols that
don’t need escaping. Set it to true to encode every symbol in the input string.
When set to true, this option takes precedence over allowUnsafeSymbols (i.e.
setting the latter to true in such a case has no effect).

// Using the global default setting (defaults to `false`):
he.encode('foo © bar ≠ baz 𝌆 qux');
// → 'foo &#xA9; bar &#x2260; baz &#x1D306; qux'

// Passing an `options` object to `encode`, to explicitly encode all symbols:
he.encode('foo © bar ≠ baz 𝌆 qux', {
  'encodeEverything': true
});
// → '&#x66;&#x6F;&#x6F;&#x20;&#xA9;&#x20;&#x62;&#x61;&#x72;&#x20;&#x2260;&#x20;&#x62;&#x61;&#x7A;&#x20;&#x1D306;&#x20;&#x71;&#x75;&#x78;'

// This setting can be combined with the `useNamedReferences` option:
he.encode('foo © bar ≠ baz 𝌆 qux', {
  'encodeEverything': true,
  'useNamedReferences': true
});
// → '&#x66;&#x6F;&#x6F;&#x20;&copy;&#x20;&#x62;&#x61;&#x72;&#x20;&ne;&#x20;&#x62;&#x61;&#x7A;&#x20;&#x1D306;&#x20;&#x71;&#x75;&#x78;'



STRICT

The default value for the strict option is false. This means that encode() will
encode any HTML text content you feed it, even if it contains any symbols that
cause parse errors. To throw an error when such invalid HTML is encountered, set
the strict option to true. This option makes it possible to use he as part of
HTML parsers and HTML validators.

// Using the global default setting (defaults to `false`, i.e. error-tolerant mode):
he.encode('\x01');
// → '&#x1;'

// Passing an `options` object to `encode`, to explicitly enable error-tolerant mode:
he.encode('\x01', {
  'strict': false
});
// → '&#x1;'

// Passing an `options` object to `encode`, to explicitly enable strict mode:
he.encode('\x01', {
  'strict': true
});
// → Parse error



ALLOWUNSAFESYMBOLS

The default value for the allowUnsafeSymbols option is false. This means that
characters that are unsafe for use in HTML content (&, <, >, ", ', and `) will
be encoded. When set to true, only non-ASCII characters will be encoded. If the
encodeEverything option is set to true, this option will be ignored.

he.encode('foo © and & ampersand', {
  'allowUnsafeSymbols': true
});
// → 'foo &#xA9; and & ampersand'



OVERRIDING DEFAULT ENCODE OPTIONS GLOBALLY

The global default setting can be overridden by modifying the he.encode.options
object. This saves you from passing in an options object for every call to
encode if you want to use the non-default setting.

// Read the global default setting:
he.encode.options.useNamedReferences;
// → `false` by default

// Override the global default setting:
he.encode.options.useNamedReferences = true;

// Using the global default setting, which is now `true`:
he.encode('foo © bar ≠ baz 𝌆 qux');
// → 'foo &copy; bar &ne; baz &#x1D306; qux'




HE.DECODE(HTML, OPTIONS)

This function takes a string of HTML and decodes any named and numerical
character references in it using the algorithm described in section 12.2.4.69 of
the HTML spec.

he.decode('foo &copy; bar &ne; baz &#x1D306; qux');
// → 'foo © bar ≠ baz 𝌆 qux'



The options object is optional. It recognizes the following properties:

ISATTRIBUTEVALUE

The default value for the isAttributeValue option is false. This means that
decode() will decode the string as if it were used in a text context in an HTML
document. HTML has different rules for parsing character references in attribute
values — set this option to true to treat the input string as if it were used as
an attribute value.

// Using the global default setting (defaults to `false`, i.e. HTML text context):
he.decode('foo&ampbar');
// → 'foo&bar'

// Passing an `options` object to `decode`, to explicitly assume an HTML text context:
he.decode('foo&ampbar', {
  'isAttributeValue': false
});
// → 'foo&bar'

// Passing an `options` object to `decode`, to explicitly assume an HTML attribute value context:
he.decode('foo&ampbar', {
  'isAttributeValue': true
});
// → 'foo&ampbar'



STRICT

The default value for the strict option is false. This means that decode() will
decode any HTML text content you feed it, even if it contains any entities that
cause parse errors. To throw an error when such invalid HTML is encountered, set
the strict option to true. This option makes it possible to use he as part of
HTML parsers and HTML validators.

// Using the global default setting (defaults to `false`, i.e. error-tolerant mode):
he.decode('foo&ampbar');
// → 'foo&bar'

// Passing an `options` object to `decode`, to explicitly enable error-tolerant mode:
he.decode('foo&ampbar', {
  'strict': false
});
// → 'foo&bar'

// Passing an `options` object to `decode`, to explicitly enable strict mode:
he.decode('foo&ampbar', {
  'strict': true
});
// → Parse error



OVERRIDING DEFAULT DECODE OPTIONS GLOBALLY

The global default settings for the decode function can be overridden by
modifying the he.decode.options object. This saves you from passing in an
options object for every call to decode if you want to use a non-default
setting.

// Read the global default setting:
he.decode.options.isAttributeValue;
// → `false` by default

// Override the global default setting:
he.decode.options.isAttributeValue = true;

// Using the global default setting, which is now `true`:
he.decode('foo&ampbar');
// → 'foo&ampbar'




HE.ESCAPE(TEXT)

This function takes a string of text and escapes it for use in text contexts in
XML or HTML documents. Only the following characters are escaped: &, <, >, ", ',
and `.

he.escape('<img src=\'x\' onerror="prompt(1)">');
// → '&lt;img src=&#x27;x&#x27; onerror=&quot;prompt(1)&quot;&gt;'




HE.UNESCAPE(HTML, OPTIONS)

he.unescape is an alias for he.decode. It takes a string of HTML and decodes any
named and numerical character references in it.


USING THE HE BINARY

To use the he binary in your shell, simply install he globally using npm:

npm install -g he



After that you will be able to encode/decode HTML entities from the command
line:

$ he --encode 'föo ♥ bår 𝌆 baz'
f&#xF6;o &#x2665; b&#xE5;r &#x1D306; baz

$ he --encode --use-named-refs 'föo ♥ bår 𝌆 baz'
f&ouml;o &hearts; b&aring;r &#x1D306; baz

$ he --decode 'f&ouml;o &hearts; b&aring;r &#x1D306; baz'
föo ♥ bår 𝌆 baz



Read a local text file, encode it for use in an HTML text context, and save the
result to a new file:

$ he --encode < foo.txt > foo-escaped.html



Or do the same with an online text file:

$ curl -sL "http://git.io/HnfEaw" | he --encode > escaped.html



Or, the opposite — read a local file containing a snippet of HTML in a text
context, decode it back to plain text, and save the result to a new file:

$ he --decode < foo-escaped.html > foo.txt



Or do the same with an online HTML snippet:

$ curl -sL "http://git.io/HnfEaw" | he --decode > decoded.txt



See he --help for the full list of options.


SUPPORT

he has been tested in at least:

 * Chrome 27-50
 * Firefox 3-45
 * Safari 4-9
 * Opera 10-12, 15–37
 * IE 6–11
 * Edge
 * Narwhal 0.3.2
 * Node.js v0.10, v0.12, v4, v5
 * PhantomJS 1.9.0
 * Rhino 1.7RC4
 * RingoJS 0.8-0.11


UNIT TESTS & CODE COVERAGE

After cloning this repository, run npm install to install the dependencies
needed for he development and testing. You may want to install Istanbul globally
using npm install istanbul -g.

Once that’s done, you can run the unit tests in Node using npm test or node
tests/tests.js. To run the tests in Rhino, Ringo, Narwhal, and web browsers as
well, use grunt test.

To generate the code coverage report, use grunt cover.


ACKNOWLEDGEMENTS

Thanks to Simon Pieters (@zcorpan) for the many suggestions.


AUTHOR

Mathias Bynens


LICENSE

he is available under the MIT license.


ABOUT

A robust HTML entity encoder/decoder written in JavaScript.

mths.be/he


TOPICS

javascript encoder decoder encode decode html-entities


RESOURCES

Readme


LICENSE

MIT license


STARS

3.2k stars


WATCHERS

61 watching


FORKS

254 forks


RELEASES

27 tags


PACKAGES 0

No packages published



USED BY 10M

 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 

+ 10,002,470


CONTRIBUTORS 7

 * 
 * 
 * 
 * 
 * 
 * 
 * 


LANGUAGES


 * JavaScript 99.2%
 * HTML 0.8%


FOOTER

© 2022 GitHub, Inc.


FOOTER NAVIGATION

 * Terms
 * Privacy
 * Security
 * Status
 * Docs
 * Contact GitHub
 * Pricing
 * API
 * Training
 * Blog
 * About


You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You
signed out in another tab or window. Reload to refresh your session.