Skip to content

Commit 1bbf914

Browse files
Chore: Rename Option to Config
1 parent ed5f8d2 commit 1bbf914

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed

src/options.ts renamed to src/config.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export interface UserProfiles {
2929
svgFilters?: boolean
3030
}
3131

32-
export interface DOMOptions {
32+
export interface DOMConfig {
3333
ADD_ATTR?: string[]
3434
ADD_TAGS?: string[]
3535
ALLOW_DATA_ATTR?: boolean
@@ -51,32 +51,32 @@ export interface DOMOptions {
5151
WHOLE_DOCUMENT?: boolean
5252
}
5353

54-
export interface Options {
55-
dom?: DOMOptions
54+
export interface Config {
55+
dom?: DOMConfig
5656
eventHandlers?: SelectorsToEventHandlers
5757
}
5858

5959
/**
6060
* Options that cannot be overidden by the user because they are used internaly by the library
6161
*/
62-
const mandatoryOptions: Options = {
62+
const mandatoryConfig: Config = {
6363
dom: {
6464
RETURN_DOM: false,
6565
RETURN_DOM_FRAGMENT: true,
6666
RETURN_DOM_IMPORT: false,
6767
},
6868
}
6969

70-
const defaultOptions: Options = {
70+
const defaultConfig: Config = {
7171
dom: {
7272
ADD_ATTR: ['key'],
7373
},
7474
}
7575

76-
export function getOptions(options?: Partial<Options>): Options {
77-
if (options) {
78-
return deepMerge(defaultOptions, deepMerge(options, mandatoryOptions))
76+
export function getConfig(config?: Partial<Config>): Config {
77+
if (config) {
78+
return deepMerge(defaultConfig, deepMerge(config, mandatoryConfig))
7979
} else {
80-
return deepMerge(defaultOptions, mandatoryOptions)
80+
return deepMerge(defaultConfig, mandatoryConfig)
8181
}
8282
}

src/dom.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as dompurify from 'dompurify'
22

3-
import { Options } from './options'
3+
import { Config } from './config'
44

55
export enum NodeType {
66
ELEMENT_NODE = 1,
@@ -21,6 +21,6 @@ export function getAttributes(elementAttributes: NamedNodeMap) {
2121
return attributes
2222
}
2323

24-
export function parse(html: string, options: Options): DocumentFragment {
25-
return dompurify.sanitize(html, options.dom) as DocumentFragment
24+
export function parse(html: string, config: Config): DocumentFragment {
25+
return dompurify.sanitize(html, config.dom) as DocumentFragment
2626
}

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
import { Config, getConfig } from './config'
12
import * as dom from './dom'
23
import { addEventHandlers } from './event'
3-
import { getOptions, Options } from './options'
44
import { render } from './react'
55

6-
export function parse(html: string, userOptions?: Options): React.ReactNode[] {
6+
export function parse(html: string, userOptions?: Config): React.ReactNode[] {
77
if (typeof html !== 'string') {
88
throw new TypeError('First argument must be a string.')
99
}
1010

11-
const options = getOptions(userOptions)
11+
const options = getConfig(userOptions)
1212
const document = dom.parse(html, options)
1313

1414
if (options.eventHandlers) {

tests/options.spec.ts renamed to tests/config.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { getOptions } from '../src/options'
1+
import { getConfig } from '../src/config'
22

33
describe('Options', () => {
44
describe('#getOptions', () => {
55
it('should get default options', () => {
6-
const defaultOptions = getOptions()
6+
const defaultOptions = getConfig()
77
expect(defaultOptions).toEqual({
88
dom: {
99
ADD_ATTR: ['key'],
@@ -15,7 +15,7 @@ describe('Options', () => {
1515
})
1616

1717
it('should merge user options and default options', () => {
18-
const options = getOptions({
18+
const options = getConfig({
1919
dom: {
2020
ADD_TAGS: ['script'],
2121
},
@@ -32,7 +32,7 @@ describe('Options', () => {
3232
})
3333

3434
it('should not be possible to override mandatory options set internaly by the library', () => {
35-
const options = getOptions({
35+
const options = getConfig({
3636
dom: {
3737
RETURN_DOM_FRAGMENT: false,
3838
},

tests/dom.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import { getConfig } from '../src/config'
12
import { parse } from '../src/dom'
2-
import { getOptions } from '../src/options'
33

44
describe('DOM', () => {
55
describe('#parse', () => {
66
it('should sanitize input', () => {
7-
const document = parse('This is a <a onclick="console.log(\"WAZAAAA\")">test</a> <script/>', getOptions())
7+
const document = parse('This is a <a onclick="console.log(\"WAZAAAA\")">test</a> <script/>', getConfig())
88
const children = document.childNodes
99
expect(children.length).toEqual(3)
1010
expect(children.item(0).textContent).toEqual('This is a ')

0 commit comments

Comments
 (0)