From a718acac7debfb4e71e3a2b796cd78798ac17041 Mon Sep 17 00:00:00 2001 From: Robin Tregaskis Date: Mon, 7 May 2018 19:17:00 +0100 Subject: [PATCH] update: (types/he): version 1.1.1 updates, include `decimal` in EncodeOptions interface (#25484) --- types/he/he-tests.ts | 42 ++++++++++++++++++++++++++++++++---------- types/he/index.d.ts | 15 ++++++++++++++- 2 files changed, 46 insertions(+), 11 deletions(-) diff --git a/types/he/he-tests.ts b/types/he/he-tests.ts index 6045574fa5..3fce7214c9 100644 --- a/types/he/he-tests.ts +++ b/types/he/he-tests.ts @@ -2,18 +2,18 @@ import he = require('he'); function main() { var result: string; - + result = he.encode('foo \xa9 bar \u2260 baz qux'); // 'foo © bar ≠ baz qux' - + he.encode('foo \0 bar'); // 'foo \0 bar' - + // Passing an `options` object to `encode`, to explicitly disallow named references: he.encode('foo \xa9 bar \u2260 baz qux', { 'useNamedReferences': false }); - + he.encode('foo \xa9 bar \u2260 baz qux', { 'encodeEverything': true }); @@ -22,21 +22,43 @@ function main() { 'encodeEverything': true, 'useNamedReferences': true }); - + he.encode('\x01', { 'strict': false }); - // '' - + // '' + he.encode('foo © and & ampersand', { 'allowUnsafeSymbols': true }); - + + // Using the global default setting (defaults to `false`): + he.encode('foo © bar ≠ baz 𝌆 qux'); + // → 'foo © bar ≠ baz 𝌆 qux' + + // Passing an `options` object to `encode`, to explicitly disable decimal escapes: + he.encode('foo © bar ≠ baz 𝌆 qux', { + 'decimal': false + }); + // → 'foo © bar ≠ baz 𝌆 qux' + + // Passing an `options` object to `encode`, to explicitly enable decimal escapes: + he.encode('foo © bar ≠ baz 𝌆 qux', { + 'decimal': true + }); + // → 'foo © bar ≠ baz 𝌆 qux' + + // Passing an `options` object to `encode`, to explicitly allow named references and decimal escapes: + he.encode('foo © bar ≠ baz 𝌆 qux', { + 'useNamedReferences': true, + 'decimal': true + }); + // Override the global default setting: he.encode.options.useNamedReferences = true; - + he.decode('foo © bar ≠ baz 𝌆 qux'); - + he.decode('foo&bar', { 'isAttributeValue': false }); diff --git a/types/he/index.d.ts b/types/he/index.d.ts index a890ad823c..e729b6bbdc 100644 --- a/types/he/index.d.ts +++ b/types/he/index.d.ts @@ -1,6 +1,7 @@ -// Type definitions for he v0.5.0 +// Type definitions for he v1.1.1 // Project: https://github.com/mathiasbynens/he // Definitions by: Simon Edwards +// Robin Tregaskis // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // he - "HTML Entities" - A high quality pair of HTML encode and decode functions. @@ -18,6 +19,18 @@ export interface EncodeOptions { */ useNamedReferences?: boolean; + /** + * The default value for the decimal option is false. If the option is + * enabled, encode will generally use decimal escapes (e.g. ©) + * rather than hexadecimal escapes (e.g. ©). Beside of this + * replacement, the basic behavior remains the same when combined with + * other options. For example: if both options useNamedReferences and + * decimal are enabled, named references (e.g. ©) are used over + * decimal escapes. HTML entities without a named reference are encoded + * using decimal escapes. + */ + decimal?: boolean; + /** * The default value for the encodeEverything option is false. This means * that encode() will not use any character references for printable ASCII