Install via yarn add locutus and import:
import { get_html_translation_table } from 'locutus/php/strings/get_html_translation_table'.
Or with CommonJS: const { get_html_translation_table } = require('locutus/php/strings/get_html_translation_table')
Use a bundler that supports tree-shaking so you only ship the functions you actually use.
Vite,
webpack,
Rollup, and
Parcel
all handle this. For server-side use this is less of a concern.
Examples
These examples are extracted from test cases that automatically verify our functions against their native counterparts.
It has been decided that we’re not going to add global
dependencies to Locutus, meaning the constants are not
real constants, but strings instead. Integers are also supported if someone
chooses to create the constants themselves.
exportfunctionget_html_translation_table( table: string | number = 'HTML_SPECIALCHARS', quoteStyle: string | number = 'ENT_COMPAT', ): Record<string, string> { // discuss at: https://locutus.io/php/get_html_translation_table/ // original by: Philip Peterson // revised by: Kevin van Zonneveld (https://kvz.io) // bugfixed by: noname // bugfixed by: Alex // bugfixed by: Marco // bugfixed by: madipta // bugfixed by: Brett Zamir (https://brett-zamir.me) // bugfixed by: T.Wild // improved by: KELAN // improved by: Brett Zamir (https://brett-zamir.me) // input by: Frank Forte // input by: Ratheous // note 1: It has been decided that we're not going to add global // note 1: dependencies to Locutus, meaning the constants are not // note 1: real constants, but strings instead. Integers are also supported if someone // note 1: chooses to create the constants themselves. // example 1: get_html_translation_table('HTML_SPECIALCHARS') // returns 1: {'"': '"', '&': '&', '<': '<', '>': '>'}
// ascii decimals to real symbols for (const [decimal, entity] ofObject.entries(entities)) { hashMap[String.fromCharCode(Number(decimal))] = entity ?? '' }
return hashMap }
exportfunctionget_html_translation_table(table = 'HTML_SPECIALCHARS', quoteStyle = 'ENT_COMPAT') { // discuss at: https://locutus.io/php/get_html_translation_table/ // original by: Philip Peterson // revised by: Kevin van Zonneveld (https://kvz.io) // bugfixed by: noname // bugfixed by: Alex // bugfixed by: Marco // bugfixed by: madipta // bugfixed by: Brett Zamir (https://brett-zamir.me) // bugfixed by: T.Wild // improved by: KELAN // improved by: Brett Zamir (https://brett-zamir.me) // input by: Frank Forte // input by: Ratheous // note 1: It has been decided that we're not going to add global // note 1: dependencies to Locutus, meaning the constants are not // note 1: real constants, but strings instead. Integers are also supported if someone // note 1: chooses to create the constants themselves. // example 1: get_html_translation_table('HTML_SPECIALCHARS') // returns 1: {'"': '"', '&': '&', '<': '<', '>': '>'}
// ascii decimals to real symbols for (const [decimal, entity] ofObject.entries(entities)) { hashMap[String.fromCharCode(Number(decimal))] = entity ?? '' }
return hashMap }
Improve this function
Locutus is a community effort following
The McDonald's Theory:
we ship first iterations, hoping others will improve them.
If you see something that could be better, we'd love your contribution.