npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

special-entities

v1.0.2

Published

A small JavaScript library for normalizing the encoding of HTML entities.

Downloads

205

Readme

Special Entities

A small JavaScript library for normalizing the encoding of HTML entities.

Install

Download the latest version from our release page and use via a script tag. The variable Entities will be attached to window.

<script type="text/javascript" src="special-entities.js"></script>

If using Browserify or Node.js, you can install via NPM and use via require("special-entities").

$ npm install special-entities

Usage

This library exposes an object, Entities, with the following methods:

convert()

Entities.convert( val [, format ] )

Takes any single value, val, and returns it in the specified format or null if the value cannot be converted. val can be any single UTF-8 character, a valid HTML entity (ie. &amp; or &#x26;), or an integer representing a Unicode code point. format can be any of the following values:

  • numeric - A numeric character reference. Ex. &#38;, &#169;
  • hex - A hexadecimal character reference. Ex. &#x26;, &#xA9;
  • name - A named character reference (aka a special entity). Ex. &amp;, &copy;.
  • utf-8 - A single utf-8 character. Ex. &, ©
  • code - A Unicode code point. Ex. 38, 169
  • html - First looks for the named reference equivalent, otherwise returns a numeric reference. Basically a combo of name and xml. This is the default format.

normalizeXML()

Entities.normalizeXML( str [, format ] )

Takes, str, a string of xml (ie. html and xhtml) and converts all HTML entities and non-ASCII characters into the specified format. See above for valid formats. The default format is html.

normalizeEntities()

Entities.normalizeEntities( str [, format ] )

Takes, str, a string and converts all HTML entities into the specified format. See above for valid formats. The default format is html.

toCharCode()

Entities.toCharCode( val )

Takes any single value, val, and returns an integer representing the Unicode code point. Valid values for val are the same as specified in .convert().

toEntity()

Entities.toEntity( nameOrCode [, asHex ] )

Takes a code point or a special entity name and returns a formatted HTML entity. If passing a code point for the first argument, pass true for asHex to return the entity as a hex value instead of an integer value.

codeToName() / nameToCode()

Entities.codeToName( code )
Entities.nameToCode( name )

These methods help to convert between a special entity name and a unicode code point. Names should not include the HTML entity formatting (eg. just "copy", not "&copy;").