5
5
* @typedef {import('hast').Properties } Properties
6
6
* @typedef {Parent['children'][number]|Root } Node
7
7
*
8
- * @typedef {Properties[string] } PropertyValue Possible property values
9
- * @typedef {string|number|boolean } PrimitivePropertyValue Possible primitive HTML attribute values
10
- * @typedef {string|[string, ...PrimitivePropertyValue[]] } AttributeValue
11
- * @typedef {Object.<string, Array.<PrimitivePropertyValue>> } AttributeMap
8
+ * @typedef {Properties[string] } PropertyValue
9
+ * Possible property values
10
+ * @typedef {string|number|boolean } PrimitivePropertyValue
11
+ * Possible primitive HTML attribute values
12
+ * @typedef {string|[string, ...Array<PrimitivePropertyValue>] } AttributeValue
13
+ * @typedef {Record<string, Array<PrimitivePropertyValue>> } AttributeMap
12
14
*
13
15
* @typedef Schema Sanitization configuration
14
- * @property {Object<string, Array<AttributeValue>> } [attributes] Map of tag names to allowed property names. The special '*' key defines property names allowed on all elements
15
- * @property {Object<string, Object<string, PropertyValue>> } [required] Map of tag names to required property names and their default property value
16
- * @property {Array.<string> } [tagNames] List of allowed tag names
17
- * @property {Object<string, Array.<string>> } [protocols] Map of protocols to allow in property values
18
- * @property {Object<string, Array.<string>> } [ancestors] Map of tag names to their required ancestor elements
19
- * @property {Array.<string> } [clobber] List of allowed property names which can clobber
20
- * @property {string } [clobberPrefix] Prefix to use before potentially clobbering property names
21
- * @property {Array.<string> } [strip] Names of elements to strip from the tree
22
- * @property {boolean } [allowComments] Whether to allow comments
23
- * @property {boolean } [allowDoctypes] Whether to allow doctypes
16
+ * @property {Record<string, Array<AttributeValue>> } [attributes]
17
+ * Map of tag names to allowed property names. The special '*' key defines property names allowed on all elements
18
+ * @property {Record<string, Record<string, PropertyValue>> } [required]
19
+ * Map of tag names to required property names and their default property value
20
+ * @property {Array<string> } [tagNames]
21
+ * List of allowed tag names
22
+ * @property {Record<string, Array<string>> } [protocols]
23
+ * Map of protocols to allow in property values
24
+ * @property {Record<string, Array<string>> } [ancestors]
25
+ * Map of tag names to their required ancestor elements
26
+ * @property {Array<string> } [clobber]
27
+ * List of allowed property names which can clobber
28
+ * @property {string } [clobberPrefix]
29
+ * Prefix to use before potentially clobbering property names
30
+ * @property {Array<string> } [strip]
31
+ * Names of elements to strip from the tree
32
+ * @property {boolean } [allowComments]
33
+ * Whether to allow comments
34
+ * @property {boolean } [allowDoctypes]
35
+ * Whether to allow doctypes
24
36
*
25
- * @typedef {(schema: Schema, value: any, node: any, stack: Array. <string>) => unknown } Handler
26
- * @typedef {Object. <string, Handler> } NodeDefinition
37
+ * @typedef {(schema: Schema, value: any, node: any, stack: Array<string>) => unknown } Handler
38
+ * @typedef {Record <string, Handler> } NodeDefinition
27
39
* @typedef {((schema: Schema, node: Node) => NodeDefinition|undefined) } NodeDefinitionGetter
28
- * @typedef {Object. <string, NodeDefinition|NodeDefinitionGetter> } NodeSchema
40
+ * @typedef {Record <string, NodeDefinition|NodeDefinitionGetter> } NodeSchema
29
41
*/
30
42
31
43
import { defaultSchema } from './schema.js'
@@ -49,8 +61,10 @@ const nodeSchema = {
49
61
/**
50
62
* Utility to sanitize a tree
51
63
*
52
- * @param {Node } node Hast tree to sanitize
53
- * @param {Schema } [schema] Schema defining how to sanitize - defaults to Github style sanitation
64
+ * @param {Node } node
65
+ * Hast tree to sanitize
66
+ * @param {Schema } [schema]
67
+ * Schema defining how to sanitize - defaults to Github style sanitation
54
68
*/
55
69
export function sanitize ( node , schema ) {
56
70
/** @type {Node } */
@@ -85,8 +99,8 @@ export function sanitize(node, schema) {
85
99
*
86
100
* @param {Schema } schema
87
101
* @param {Node } node
88
- * @param {Array. <string> } stack
89
- * @returns {Node|Array. <Node>|undefined }
102
+ * @param {Array<string> } stack
103
+ * @returns {Node|Array<Node>|undefined }
90
104
*/
91
105
function one ( schema , node , stack ) {
92
106
const type = node && node . type
@@ -149,12 +163,12 @@ function one(schema, node, stack) {
149
163
* Sanitize `children`.
150
164
*
151
165
* @type {Handler }
152
- * @param {Array. <Node> } children
166
+ * @param {Array<Node> } children
153
167
* @param {Node } node
154
- * @returns {Array. <Node> }
168
+ * @returns {Array<Node> }
155
169
*/
156
170
function all ( schema , children , node , stack ) {
157
- /** @type {Array. <Node> } */
171
+ /** @type {Array<Node> } */
158
172
const results = [ ]
159
173
160
174
if ( Array . isArray ( children ) ) {
@@ -222,7 +236,7 @@ function handleProperties(schema, properties, node, stack) {
222
236
for ( key in props ) {
223
237
if ( own . call ( props , key ) ) {
224
238
let value = props [ key ]
225
- /** @type {Array. <PrimitivePropertyValue> } */
239
+ /** @type {Array<PrimitivePropertyValue> } */
226
240
let definition
227
241
228
242
if ( own . call ( allowed , key ) ) {
@@ -338,14 +352,14 @@ function allow(_, value) {
338
352
* Sanitize a property value which is a list.
339
353
*
340
354
* @param {Schema } schema
341
- * @param {Array. <unknown> } values
355
+ * @param {Array<unknown> } values
342
356
* @param {string } prop
343
- * @param {Array. <PrimitivePropertyValue> } definition
344
- * @returns {Array. <string|number> }
357
+ * @param {Array<PrimitivePropertyValue> } definition
358
+ * @returns {Array<string|number> }
345
359
*/
346
360
function handlePropertyValues ( schema , values , prop , definition ) {
347
361
let index = - 1
348
- /** @type {Array. <string|number> } */
362
+ /** @type {Array<string|number> } */
349
363
const result = [ ]
350
364
351
365
while ( ++ index < values . length ) {
@@ -366,7 +380,7 @@ function handlePropertyValues(schema, values, prop, definition) {
366
380
* @param {Schema } schema
367
381
* @param {unknown } value
368
382
* @param {string } prop
369
- * @param {Array. <PropertyValue> } definition
383
+ * @param {Array<PropertyValue> } definition
370
384
* @returns {PropertyValue }
371
385
*/
372
386
function handlePropertyValue ( schema , value , prop , definition ) {
@@ -431,7 +445,7 @@ function safeProtocol(schema, value, prop) {
431
445
/**
432
446
* Create a map from a list of props or a list of properties and values.
433
447
*
434
- * @param {Array. <AttributeValue> } values
448
+ * @param {Array<AttributeValue> } values
435
449
* @returns {AttributeMap }
436
450
*/
437
451
function toPropertyValueMap ( values ) {
0 commit comments