This commit is contained in:
3
node_modules/stringify-entities/index.js
generated
vendored
Normal file
3
node_modules/stringify-entities/index.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = require('./lib')
|
||||
1
node_modules/stringify-entities/lib/constant/assign.js
generated
vendored
Normal file
1
node_modules/stringify-entities/lib/constant/assign.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = Object.assign
|
||||
10
node_modules/stringify-entities/lib/constant/characters.js
generated
vendored
Normal file
10
node_modules/stringify-entities/lib/constant/characters.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
var entities = require('character-entities-html4')
|
||||
|
||||
var characters = {}
|
||||
var name
|
||||
|
||||
module.exports = characters
|
||||
|
||||
for (name in entities) {
|
||||
characters[entities[name]] = name
|
||||
}
|
||||
10
node_modules/stringify-entities/lib/constant/dangerous.json
generated
vendored
Normal file
10
node_modules/stringify-entities/lib/constant/dangerous.json
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
[
|
||||
"cent",
|
||||
"copy",
|
||||
"divide",
|
||||
"gt",
|
||||
"lt",
|
||||
"not",
|
||||
"para",
|
||||
"times"
|
||||
]
|
||||
1
node_modules/stringify-entities/lib/constant/from-char-code.js
generated
vendored
Normal file
1
node_modules/stringify-entities/lib/constant/from-char-code.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = String.fromCharCode
|
||||
1
node_modules/stringify-entities/lib/constant/has-own-property.js
generated
vendored
Normal file
1
node_modules/stringify-entities/lib/constant/has-own-property.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = {}.hasOwnProperty
|
||||
58
node_modules/stringify-entities/lib/core.js
generated
vendored
Normal file
58
node_modules/stringify-entities/lib/core.js
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = encode
|
||||
|
||||
// Encode special characters in `value`.
|
||||
function encode(value, options) {
|
||||
value = value.replace(
|
||||
options.subset ? charactersToExpression(options.subset) : /["&'<>`]/g,
|
||||
basic
|
||||
)
|
||||
|
||||
if (options.subset || options.escapeOnly) {
|
||||
return value
|
||||
}
|
||||
|
||||
return (
|
||||
value
|
||||
// Surrogate pairs.
|
||||
.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g, surrogate)
|
||||
// BMP control characters (C0 except for LF, CR, SP; DEL; and some more
|
||||
// non-ASCII ones).
|
||||
.replace(
|
||||
// eslint-disable-next-line no-control-regex, unicorn/no-hex-escape
|
||||
/[\x01-\t\v\f\x0E-\x1F\x7F\x81\x8D\x8F\x90\x9D\xA0-\uFFFF]/g,
|
||||
basic
|
||||
)
|
||||
)
|
||||
|
||||
function surrogate(pair, index, all) {
|
||||
return options.format(
|
||||
(pair.charCodeAt(0) - 0xd800) * 0x400 +
|
||||
pair.charCodeAt(1) -
|
||||
0xdc00 +
|
||||
0x10000,
|
||||
all.charCodeAt(index + 2),
|
||||
options
|
||||
)
|
||||
}
|
||||
|
||||
function basic(character, index, all) {
|
||||
return options.format(
|
||||
character.charCodeAt(0),
|
||||
all.charCodeAt(index + 1),
|
||||
options
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
function charactersToExpression(subset) {
|
||||
var groups = []
|
||||
var index = -1
|
||||
|
||||
while (++index < subset.length) {
|
||||
groups.push(subset[index].replace(/[|\\{}()[\]^$+*?.]/g, '\\$&'))
|
||||
}
|
||||
|
||||
return new RegExp('(?:' + groups.join('|') + ')', 'g')
|
||||
}
|
||||
14
node_modules/stringify-entities/lib/encode-hexadecimal.js
generated
vendored
Normal file
14
node_modules/stringify-entities/lib/encode-hexadecimal.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
'use strict'
|
||||
|
||||
var core = require('./core')
|
||||
var assign = require('./constant/assign')
|
||||
var basic = require('./util/format-basic')
|
||||
|
||||
module.exports = encodeHexadecimal
|
||||
|
||||
// Encode special characters in `value` as hexadecimals.
|
||||
function encodeHexadecimal(value, options) {
|
||||
// Note: this file was added in a minor release, so here we can use
|
||||
// `Object.assign`.
|
||||
return core(value, assign({format: basic}, options))
|
||||
}
|
||||
13
node_modules/stringify-entities/lib/encode.js
generated
vendored
Normal file
13
node_modules/stringify-entities/lib/encode.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
'use strict'
|
||||
|
||||
var xtend = require('xtend')
|
||||
var core = require('./core')
|
||||
var smart = require('./util/format-smart')
|
||||
|
||||
module.exports = encode
|
||||
|
||||
// Encode special characters in `value`.
|
||||
function encode(value, options) {
|
||||
// Note: Switch to `Object.assign` next major.
|
||||
return core(value, xtend(options, {format: smart}))
|
||||
}
|
||||
15
node_modules/stringify-entities/lib/escape.js
generated
vendored
Normal file
15
node_modules/stringify-entities/lib/escape.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
'use strict'
|
||||
|
||||
var core = require('./core')
|
||||
var smart = require('./util/format-smart')
|
||||
|
||||
module.exports = escape
|
||||
|
||||
// Shortcut to escape special characters in HTML.
|
||||
function escape(value) {
|
||||
return core(value, {
|
||||
escapeOnly: true,
|
||||
useNamedReferences: true,
|
||||
format: smart
|
||||
})
|
||||
}
|
||||
7
node_modules/stringify-entities/lib/index.js
generated
vendored
Normal file
7
node_modules/stringify-entities/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
var encode = require('./encode')
|
||||
var escape = require('./escape')
|
||||
|
||||
module.exports = encode
|
||||
encode.escape = escape
|
||||
5
node_modules/stringify-entities/lib/util/format-basic.js
generated
vendored
Normal file
5
node_modules/stringify-entities/lib/util/format-basic.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
module.exports = formatBasic
|
||||
|
||||
function formatBasic(code) {
|
||||
return '&#x' + code.toString(16).toUpperCase() + ';'
|
||||
}
|
||||
48
node_modules/stringify-entities/lib/util/format-smart.js
generated
vendored
Normal file
48
node_modules/stringify-entities/lib/util/format-smart.js
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
module.exports = formatPretty
|
||||
|
||||
var toHexadecimal = require('./to-hexadecimal')
|
||||
var toDecimal = require('./to-decimal')
|
||||
var toNamed = require('./to-named')
|
||||
|
||||
// Encode `character` according to `options`.
|
||||
function formatPretty(code, next, options) {
|
||||
var named
|
||||
var numeric
|
||||
var decimal
|
||||
|
||||
if (options.useNamedReferences || options.useShortestReferences) {
|
||||
named = toNamed(
|
||||
code,
|
||||
next,
|
||||
options.omitOptionalSemicolons,
|
||||
options.attribute
|
||||
)
|
||||
}
|
||||
|
||||
if (options.useShortestReferences || !named) {
|
||||
numeric = toHexadecimal(code, next, options.omitOptionalSemicolons)
|
||||
|
||||
// Use the shortest numeric reference when requested.
|
||||
// A simple algorithm would use decimal for all code points under 100, as
|
||||
// those are shorter than hexadecimal:
|
||||
//
|
||||
// * `c` vs `c` (decimal shorter)
|
||||
// * `d` vs `d` (equal)
|
||||
//
|
||||
// However, because we take `next` into consideration when `omit` is used,
|
||||
// And it would be possible that decimals are shorter on bigger values as
|
||||
// well if `next` is hexadecimal but not decimal, we instead compare both.
|
||||
if (options.useShortestReferences) {
|
||||
decimal = toDecimal(code, next, options.omitOptionalSemicolons)
|
||||
|
||||
if (decimal.length < numeric.length) {
|
||||
numeric = decimal
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return named &&
|
||||
(!options.useShortestReferences || named.length < numeric.length)
|
||||
? named
|
||||
: numeric
|
||||
}
|
||||
9
node_modules/stringify-entities/lib/util/to-decimal.js
generated
vendored
Normal file
9
node_modules/stringify-entities/lib/util/to-decimal.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
module.exports = toDecimalReference
|
||||
|
||||
var fromCharCode = require('../constant/from-char-code')
|
||||
|
||||
// Transform `code` into a decimal character reference.
|
||||
function toDecimalReference(code, next, omit) {
|
||||
var value = '&#' + String(code)
|
||||
return omit && next && !/\d/.test(fromCharCode(next)) ? value : value + ';'
|
||||
}
|
||||
11
node_modules/stringify-entities/lib/util/to-hexadecimal.js
generated
vendored
Normal file
11
node_modules/stringify-entities/lib/util/to-hexadecimal.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
module.exports = toHexReference
|
||||
|
||||
var fromCharCode = require('../constant/from-char-code')
|
||||
|
||||
// Transform `code` into a hexadecimal character reference.
|
||||
function toHexReference(code, next, omit) {
|
||||
var value = '&#x' + code.toString(16).toUpperCase()
|
||||
return omit && next && !/[\dA-Fa-f]/.test(fromCharCode(next))
|
||||
? value
|
||||
: value + ';'
|
||||
}
|
||||
33
node_modules/stringify-entities/lib/util/to-named.js
generated
vendored
Normal file
33
node_modules/stringify-entities/lib/util/to-named.js
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
module.exports = toNamed
|
||||
|
||||
var legacy = require('character-entities-legacy')
|
||||
var characters = require('../constant/characters')
|
||||
var fromCharCode = require('../constant/from-char-code')
|
||||
var own = require('../constant/has-own-property')
|
||||
var dangerous = require('../constant/dangerous.json')
|
||||
|
||||
// Transform `code` into a named character reference.
|
||||
function toNamed(code, next, omit, attribute) {
|
||||
var character = fromCharCode(code)
|
||||
var name
|
||||
var value
|
||||
|
||||
if (own.call(characters, character)) {
|
||||
name = characters[character]
|
||||
value = '&' + name
|
||||
|
||||
if (
|
||||
omit &&
|
||||
own.call(legacy, name) &&
|
||||
dangerous.indexOf(name) === -1 &&
|
||||
(!attribute ||
|
||||
(next && next !== 61 /* `=` */ && /[^\da-z]/i.test(fromCharCode(next))))
|
||||
) {
|
||||
return value
|
||||
}
|
||||
|
||||
return value + ';'
|
||||
}
|
||||
|
||||
return ''
|
||||
}
|
||||
22
node_modules/stringify-entities/license
generated
vendored
Normal file
22
node_modules/stringify-entities/license
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2015 Titus Wormer <mailto:tituswormer@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
3
node_modules/stringify-entities/light.js
generated
vendored
Normal file
3
node_modules/stringify-entities/light.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = require('./lib/encode-hexadecimal')
|
||||
91
node_modules/stringify-entities/package.json
generated
vendored
Normal file
91
node_modules/stringify-entities/package.json
generated
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
{
|
||||
"name": "stringify-entities",
|
||||
"version": "3.1.0",
|
||||
"description": "Encode HTML character references and character entities",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"stringify",
|
||||
"encode",
|
||||
"escape",
|
||||
"html",
|
||||
"character",
|
||||
"reference",
|
||||
"entity",
|
||||
"entities"
|
||||
],
|
||||
"repository": "wooorm/stringify-entities",
|
||||
"bugs": "https://github.com/wooorm/stringify-entities/issues",
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/wooorm"
|
||||
},
|
||||
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
|
||||
"contributors": [
|
||||
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
|
||||
],
|
||||
"files": [
|
||||
"lib/",
|
||||
"index.js",
|
||||
"light.js",
|
||||
"types/index.d.ts"
|
||||
],
|
||||
"types": "types/index.d.ts",
|
||||
"dependencies": {
|
||||
"character-entities-html4": "^1.0.0",
|
||||
"character-entities-legacy": "^1.0.0",
|
||||
"xtend": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"browserify": "^17.0.0",
|
||||
"character-entities": "^1.0.0",
|
||||
"dtslint": "^4.0.0",
|
||||
"nyc": "^15.0.0",
|
||||
"prettier": "^2.0.0",
|
||||
"remark-cli": "^9.0.0",
|
||||
"remark-preset-wooorm": "^8.0.0",
|
||||
"tape": "^5.0.0",
|
||||
"tinyify": "^3.0.0",
|
||||
"xo": "^0.34.0"
|
||||
},
|
||||
"scripts": {
|
||||
"generate": "node build",
|
||||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
|
||||
"build-bundle": "browserify . -s stringifyEntities -o stringify-entities.js",
|
||||
"build-mangle": "browserify . -s stringifyEntities -p tinyify -o stringify-entities.min.js",
|
||||
"build": "npm run build-bundle && npm run build-mangle",
|
||||
"test-api": "node test",
|
||||
"test-coverage": "nyc --reporter lcov tape test.js",
|
||||
"test-types": "dtslint types",
|
||||
"test": "npm run format && npm run build && npm run test-coverage && npm run test-types"
|
||||
},
|
||||
"nyc": {
|
||||
"check-coverage": true,
|
||||
"lines": 100,
|
||||
"functions": 100,
|
||||
"branches": 100
|
||||
},
|
||||
"prettier": {
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"singleQuote": true,
|
||||
"bracketSpacing": false,
|
||||
"semi": false,
|
||||
"trailingComma": "none"
|
||||
},
|
||||
"xo": {
|
||||
"prettier": true,
|
||||
"esnext": false,
|
||||
"rules": {
|
||||
"unicorn/prefer-includes": "off",
|
||||
"guard-for-in": "off"
|
||||
},
|
||||
"ignores": [
|
||||
"stringify-entities.js"
|
||||
]
|
||||
},
|
||||
"remarkConfig": {
|
||||
"plugins": [
|
||||
"preset-wooorm"
|
||||
]
|
||||
}
|
||||
}
|
||||
160
node_modules/stringify-entities/readme.md
generated
vendored
Normal file
160
node_modules/stringify-entities/readme.md
generated
vendored
Normal file
@@ -0,0 +1,160 @@
|
||||
# stringify-entities
|
||||
|
||||
[![Build Status][build-badge]][build-status]
|
||||
[![Coverage Status][coverage-badge]][coverage-status]
|
||||
[![Downloads][downloads-badge]][downloads]
|
||||
[![Size][size-badge]][size]
|
||||
|
||||
Encode HTML character references.
|
||||
|
||||
* [x] Very fast
|
||||
* [x] Just the encoding part
|
||||
* [x] Has either all the options you need for a minifier/prettifier, or a tiny
|
||||
size w/ `stringify-entities/light`
|
||||
* [x] Reliable: ``'`'`` characters are escaped to ensure no scripts
|
||||
run in Internet Explorer 6 to 8.
|
||||
Additionally, only named references recognized by HTML4 are encoded, meaning
|
||||
the infamous `'` (which people think is a [virus][]) won’t show up
|
||||
|
||||
## Algorithm
|
||||
|
||||
By default, all dangerous, non-ASCII, and non-printable ASCII characters are
|
||||
encoded.
|
||||
A [subset][] of characters can be given to encode just those characters.
|
||||
Alternatively, pass [`escapeOnly`][escapeonly] to escape just the dangerous
|
||||
characters (`"`, `'`, `<`, `>`, `&`, `` ` ``).
|
||||
By default, hexadecimal character references are used.
|
||||
Pass [`useNamedReferences`][named] to use named character references when
|
||||
possible, or [`useShortestReferences`][short] to use whichever is shortest:
|
||||
decimal, hexadecimal, or named.
|
||||
There is also a `stringify-entities/light` module, which works just like
|
||||
`stringifyEntities` but without the formatting options: it’s much smaller but
|
||||
always outputs hexadecimal character references.
|
||||
|
||||
## Install
|
||||
|
||||
[npm][]:
|
||||
|
||||
```sh
|
||||
npm install stringify-entities
|
||||
```
|
||||
|
||||
## Use
|
||||
|
||||
```js
|
||||
var stringify = require('stringify-entities')
|
||||
|
||||
stringify('alpha © bravo ≠ charlie 𝌆 delta')
|
||||
// => 'alpha © bravo ≠ charlie 𝌆 delta'
|
||||
|
||||
stringify('alpha © bravo ≠ charlie 𝌆 delta', {useNamedReferences: true})
|
||||
// => 'alpha © bravo ≠ charlie 𝌆 delta'
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### `stringifyEntities(value[, options])`
|
||||
|
||||
Encode special characters in `value`.
|
||||
|
||||
##### `options`
|
||||
|
||||
##### Core options
|
||||
|
||||
###### `options.escapeOnly`
|
||||
|
||||
Whether to only escape possibly dangerous characters (`boolean`, default:
|
||||
`false`).
|
||||
Those characters are `"`, `&`, `'`, `<`, `>`, and `` ` ``.
|
||||
|
||||
###### `options.subset`
|
||||
|
||||
Whether to only escape the given subset of characters (`Array.<string>`).
|
||||
Note that only BMP characters are supported here (so no emoji).
|
||||
|
||||
##### Formatting options
|
||||
|
||||
If you do not care about these, use `stringify-entities/light`, which always
|
||||
outputs hexadecimal character references.
|
||||
|
||||
###### `options.useNamedReferences`
|
||||
|
||||
Prefer named character references (`&`) where possible (`boolean?`, default:
|
||||
`false`).
|
||||
|
||||
###### `options.useShortestReferences`
|
||||
|
||||
Prefer the shortest possible reference, if that results in less bytes
|
||||
(`boolean?`, default: `false`).
|
||||
**Note**: `useNamedReferences` can be omitted when using
|
||||
`useShortestReferences`.
|
||||
|
||||
###### `options.omitOptionalSemicolons`
|
||||
|
||||
Whether to omit semicolons when possible (`boolean?`, default: `false`).
|
||||
**Note**: This creates what HTML calls “parse errors” but is otherwise still
|
||||
valid HTML — don’t use this except when building a minifier.
|
||||
|
||||
Omitting semicolons is possible for [legacy][] named references in
|
||||
[certain][dangerous] cases, and numeric references in some cases.
|
||||
|
||||
###### `options.attribute`
|
||||
|
||||
Only needed when operating dangerously with `omitOptionalSemicolons: true`.
|
||||
Create character references which don’t fail in attributes (`boolean?`, default:
|
||||
`false`).
|
||||
|
||||
## Related
|
||||
|
||||
* [`parse-entities`](https://github.com/wooorm/parse-entities)
|
||||
— Parse HTML character references
|
||||
* [`character-entities`](https://github.com/wooorm/character-entities)
|
||||
— Info on character entities
|
||||
* [`character-entities-html4`](https://github.com/wooorm/character-entities-html4)
|
||||
— Info on HTML 4 character entities
|
||||
* [`character-entities-legacy`](https://github.com/wooorm/character-entities-legacy)
|
||||
— Info on legacy character entities
|
||||
* [`character-reference-invalid`](https://github.com/wooorm/character-reference-invalid)
|
||||
— Info on invalid numeric character references
|
||||
|
||||
## License
|
||||
|
||||
[MIT][license] © [Titus Wormer][author]
|
||||
|
||||
<!-- Definitions -->
|
||||
|
||||
[build-badge]: https://img.shields.io/travis/wooorm/stringify-entities.svg
|
||||
|
||||
[build-status]: https://travis-ci.org/wooorm/stringify-entities
|
||||
|
||||
[coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/stringify-entities.svg
|
||||
|
||||
[coverage-status]: https://codecov.io/github/wooorm/stringify-entities
|
||||
|
||||
[downloads-badge]: https://img.shields.io/npm/dm/stringify-entities.svg
|
||||
|
||||
[downloads]: https://www.npmjs.com/package/stringify-entities
|
||||
|
||||
[size-badge]: https://img.shields.io/bundlephobia/minzip/stringify-entities.svg
|
||||
|
||||
[size]: https://bundlephobia.com/result?p=stringify-entities
|
||||
|
||||
[license]: license
|
||||
|
||||
[author]: https://wooorm.com
|
||||
|
||||
[npm]: https://docs.npmjs.com/cli/install
|
||||
|
||||
[virus]: https://www.telegraph.co.uk/technology/advice/10516839/Why-do-some-apostrophes-get-replaced-with-andapos.html
|
||||
|
||||
[dangerous]: lib/constant/dangerous.json
|
||||
|
||||
[legacy]: https://github.com/wooorm/character-entities-legacy
|
||||
|
||||
[subset]: #optionssubset
|
||||
|
||||
[escapeonly]: #optionsescapeonly
|
||||
|
||||
[named]: #optionsusenamedreferences
|
||||
|
||||
[short]: #optionsuseshortestreferences
|
||||
51
node_modules/stringify-entities/types/index.d.ts
generated
vendored
Normal file
51
node_modules/stringify-entities/types/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
// TypeScript Version: 3.0
|
||||
|
||||
declare namespace stringifyEntities {
|
||||
interface StringifyEntitiesOptions {
|
||||
/**
|
||||
* Whether to only escape possibly dangerous characters (`boolean`, default: `false`).
|
||||
* Those characters are `"`, `&`, `'`, `<`, `>`, and `` ` ``.
|
||||
*/
|
||||
escapeOnly?: boolean
|
||||
|
||||
/**
|
||||
* Whether to only escape the given subset of characters (`Array.<string>`).
|
||||
*/
|
||||
subset?: string[]
|
||||
|
||||
/**
|
||||
* Prefer named character references (`&`) where possible (`boolean?`, default: `false`).
|
||||
*/
|
||||
useNamedReferences?: boolean
|
||||
|
||||
/**
|
||||
* Prefer the shortest possible reference, if that results in less bytes (`boolean?`, default: `false`).
|
||||
* **Note**: `useNamedReferences` can be omitted when using `useShortestReferences`.
|
||||
*/
|
||||
useShortestReferences?: boolean
|
||||
|
||||
/**
|
||||
* Whether to omit semicolons when possible (`boolean?`, default: `false`).
|
||||
* **Note**: This creates what HTML calls “parse errors” but is otherwise still valid HTML — don’t use this except when building a minifier.
|
||||
*
|
||||
* Omitting semicolons is possible for legacy named references in certain cases, and numeric references in some cases.
|
||||
*/
|
||||
omitOptionalSemicolons?: boolean
|
||||
|
||||
/**
|
||||
* Only needed when operating dangerously with `omitOptionalSemicolons: true`.
|
||||
* Create character references which don’t fail in attributes (`boolean?`, default: `false`).
|
||||
*/
|
||||
attribute?: boolean
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode special characters in `value`.
|
||||
*/
|
||||
declare function stringifyEntities(
|
||||
value: string,
|
||||
options?: stringifyEntities.StringifyEntitiesOptions
|
||||
): string
|
||||
|
||||
export = stringifyEntities
|
||||
Reference in New Issue
Block a user