UNPKG

strman.htmldecode

Version:

The [strman](https://github.com/dleitee/strman) method `htmldecode` exported as a [Node.js](https://nodejs.org/) module.

41 lines (39 loc) 960 B
var entitiesDecode = require('strman.entitiesdecode') var replace = require('strman.replace') Object.defineProperty(exports, "__esModule", { value: true }); /** * @module htmlDecode * @description * Convert all HTML entities to applicable characters. * ## Install * Install all functions of strman * ```sh * yarn add strman * ``` * or just the htmlDecode function * ```sh * yarn add strman.htmldecode * ``` * ## Usage * ```javascript * import { htmlDecode } from 'strman' * // OR * import htmlDecode from 'strman.htmldecode' * ``` * @param {String} value - value to decode. * @example * htmlDecode('&lt;div&gt;') * // => '<div>' * @returns { String } The decoded data. */ exports.default = function (value) { return replace(value, '(&\\w+;)', function (match, index) { if (typeof entitiesDecode[index] !== 'undefined') { return entitiesDecode[index]; } return match; }); }; module.exports = exports['default'];