1// [email protected] downloaded from https://ga.jspm.io/npm:[email protected]/index.js 2 3import{characterEntitiesLegacy as t}from"character-entities-legacy";import{characterEntitiesHtml4 as e}from"character-entities-html4"; 4/** 5 * @typedef CoreOptions 6 * @property {ReadonlyArray<string>} [subset=[]] 7 * Whether to only escape the given subset of characters. 8 * @property {boolean} [escapeOnly=false] 9 * Whether to only escape possibly dangerous characters. 10 * Those characters are `"`, `&`, `'`, `<`, `>`, and `` ` ``. 11 * 12 * @typedef FormatOptions 13 * @property {(code: number, next: number, options: CoreWithFormatOptions) => string} format 14 * Format strategy. 15 * 16 * @typedef {CoreOptions & FormatOptions & import('./util/format-smart.js').FormatSmartOptions} CoreWithFormatOptions 17 */const r=/["&'<>`]/g;const n=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g;const o=/[\x01-\t\v\f\x0E-\x1F\x7F\x81\x8D\x8F\x90\x9D\xA0-\uFFFF]/g;const s=/[|\\{}()[\]^$+*?.]/g; 18/** @type {WeakMap<ReadonlyArray<string>, RegExp>} */const c=new WeakMap; 19/** 20 * Encode certain characters in `value`. 21 * 22 * @param {string} value 23 * @param {CoreWithFormatOptions} options 24 * @returns {string} 25 */function core(t,e){t=t.replace(e.subset?charactersToExpressionCached(e.subset):r,basic);return e.subset||e.escapeOnly?t:t.replace(n,surrogate).replace(o,basic) 26/** 27 * @param {string} pair 28 * @param {number} index 29 * @param {string} all 30 */;function surrogate(t,r,n){return e.format(1024*(t.charCodeAt(0)-55296)+t.charCodeAt(1)-56320+65536,n.charCodeAt(r+2),e)} 31/** 32 * @param {string} character 33 * @param {number} index 34 * @param {string} all 35 */function basic(t,r,n){return e.format(t.charCodeAt(0),n.charCodeAt(r+1),e)}} 36/** 37 * A wrapper function that caches the result of `charactersToExpression` with a WeakMap. 38 * This can improve performance when tooling calls `charactersToExpression` repeatedly 39 * with the same subset. 40 * 41 * @param {ReadonlyArray<string>} subset 42 * @returns {RegExp} 43 */function charactersToExpressionCached(t){let e=c.get(t);if(!e){e=charactersToExpression(t);c.set(t,e)}return e} 44/** 45 * @param {ReadonlyArray<string>} subset 46 * @returns {RegExp} 47 */function charactersToExpression(t){ 48/** @type {Array<string>} */ 49const e=[];let r=-1;while(++r<t.length)e.push(t[r].replace(s,"\\$&"));return new RegExp("(?:"+e.join("|")+")","g")}const i=/[\dA-Fa-f]/; 50/** 51 * Configurable ways to encode characters as hexadecimal references. 52 * 53 * @param {number} code 54 * @param {number} next 55 * @param {boolean|undefined} omit 56 * @returns {string} 57 */function toHexadecimal(t,e,r){const n="&#x"+t.toString(16).toUpperCase();return r&&e&&!i.test(String.fromCharCode(e))?n:n+";"}const a=/\d/; 58/** 59 * Configurable ways to encode characters as decimal references. 60 * 61 * @param {number} code 62 * @param {number} next 63 * @param {boolean|undefined} omit 64 * @returns {string} 65 */function toDecimal(t,e,r){const n="&#"+String(t);return r&&e&&!a.test(String.fromCharCode(e))?n:n+";"} 66/** 67 * List of legacy (that donât need a trailing `;`) named references which could, 68 * depending on what follows them, turn into a different meaning 69 * 70 * @type {Array<string>} 71 */const u=["cent","copy","divide","gt","lt","not","para","times"];const f={}.hasOwnProperty; 72/** 73 * `characterEntitiesHtml4` but inverted. 74 * 75 * @type {Record<string, string>} 76 */const l={}; 77/** @type {string} */let m;for(m in e)f.call(e,m)&&(l[e[m]]=m);const h=/[^\dA-Za-z]/; 78/** 79 * Configurable ways to encode characters as named references. 80 * 81 * @param {number} code 82 * @param {number} next 83 * @param {boolean|undefined} omit 84 * @param {boolean|undefined} attribute 85 * @returns {string} 86 */function toNamed(e,r,n,o){const s=String.fromCharCode(e);if(f.call(l,s)){const e=l[s];const c="&"+e;return n&&t.includes(e)&&!u.includes(e)&&(!o||r&&r!==61&&h.test(String.fromCharCode(r)))?c:c+";"}return""} 87/** 88 * @typedef FormatSmartOptions 89 * @property {boolean} [useNamedReferences=false] 90 * Prefer named character references (`&`) where possible. 91 * @property {boolean} [useShortestReferences=false] 92 * Prefer the shortest possible reference, if that results in less bytes. 93 * **Note**: `useNamedReferences` can be omitted when using `useShortestReferences`. 94 * @property {boolean} [omitOptionalSemicolons=false] 95 * Whether to omit semicolons when possible. 96 * **Note**: This creates what HTML calls âparse errorsâ but is otherwise still valid HTML â donât use this except when building a minifier.
97 * Omitting semicolons is possible for certain named and numeric references in some cases. 98 * @property {boolean} [attribute=false] 99 * Create character references which donât fail in attributes. 100 * **Note**: `attribute` only applies when operating dangerously with 101 * `omitOptionalSemicolons: true`. 102 */ 103/** 104 * Configurable ways to encode a character yielding pretty or small results. 105 * 106 * @param {number} code 107 * @param {number} next 108 * @param {FormatSmartOptions} options 109 * @returns {string} 110 */function formatSmart(t,e,r){let n=toHexadecimal(t,e,r.omitOptionalSemicolons); 111/** @type {string|undefined} */let o;(r.useNamedReferences||r.useShortestReferences)&&(o=toNamed(t,e,r.omitOptionalSemicolons,r.attribute));if((r.useShortestReferences||!o)&&r.useShortestReferences){const o=toDecimal(t,e,r.omitOptionalSemicolons);o.length<n.length&&(n=o)}return o&&(!r.useShortestReferences||o.length<n.length)?o:n} 112/** 113 * The smallest way to encode a character. 114 * 115 * @param {number} code 116 * @returns {string} 117 */function formatBasic(t){return"&#x"+t.toString(16).toUpperCase()+";"} 118/** 119 * @typedef {import('./core.js').CoreOptions & import('./util/format-smart.js').FormatSmartOptions} Options 120 * @typedef {import('./core.js').CoreOptions} LightOptions 121 */ 122/** 123 * Encode special characters in `value`. 124 * 125 * @param {string} value 126 * Value to encode. 127 * @param {Options} [options] 128 * Configuration. 129 * @returns {string} 130 * Encoded value. 131 */function stringifyEntities(t,e){return core(t,Object.assign({format:formatSmart},e))} 132/** 133 * Encode special characters in `value` as hexadecimals. 134 * 135 * @param {string} value 136 * Value to encode. 137 * @param {LightOptions} [options] 138 * Configuration. 139 * @returns {string} 140 * Encoded value. 141 */function stringifyEntitiesLight(t,e){return core(t,Object.assign({format:formatBasic},e))} 142/** 143 * @typedef {import('./lib/index.js').LightOptions} LightOptions 144 * @typedef {import('./lib/index.js').Options} Options 145 */export{stringifyEntities,stringifyEntitiesLight}; 146
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.