htmlentities

1.0.0 • Public • Published

htmlentities.js lets you deal with "complex" HTML entities (not just the usual '<' '>' '"' and '&' special characters) in an elegant, JS-oriented way, on the server and in the browser, without dependencies.

Demo

Install

On the server

$ npm install htmlentities

var htmlentities = require('htmlentities');

In the browser

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

Methods

.encode(string[, encoding])

Returns the encoded version of string. If omitted, encoding defaults to UTF-8.

.decode(string[, encoding])

Returns the decoded version of string. If omitted, encoding defaults to UTF-8.

Encodings

The following encodings are supported:

  • UTF-8 (aliased utf8)

Notes

I wrote this plugin because I needed to compare two strings: one was encoded, one wasn't. I didn't find a library that would easily let me do it. There are nice node modules, there are client-side libraries, and there are jQuery hacks. But if you want a script that is straightforward and runs both in the browser and on the server, you will probably find htmlentities.js useful.

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i htmlentities

      Weekly Downloads

      47

      Version

      1.0.0

      License

      MIT

      Last publish

      Collaborators

      • alexduloz