Skip to content

Commit

Permalink
Make sure option names are consistent and update TS definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
HoldYourWaffle committed Jun 1, 2019
1 parent f2abb7d commit f8212e7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ reshape({

| Name | Description | Default |
| ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ |
| **replacementTag** | Tag used to replace the custom element tag name | `div` |
| **defaultReplacementTag** | Tag used to replace the custom element tag name | `div` |
| **additionalTags** | Array of tags to be processed despite being a normal HTML tag | `[]` |
| **blacklist** | Array of tags that should never be processed | `[]` |
| **replacementTagMap** | Object containing custom tag ↔ replacement tag mappings in the format: `ReplacedTag: [ customTag1, customTag2, ... ]`. Overrides `replacementTag` | `{}` |
Expand Down
15 changes: 10 additions & 5 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
export default function reshapeCustomElements(
options?: ReshapeCustomElementsOptions
): Function

export interface ReshapeCustomElementsOptions {
replacementTag: string
additionalTags: HtmlTags[]
defaultReplacementTag?: string
additionalTags?: HtmlTags[]
blacklist?: string[]
replacementTagMap?: ReplacementTagMap
replacementTagAttr?: string
}

export default function reshapeCustomElements(
options: ReshapeCustomElementsOptions
): Function
export type ReplacementTagMap = { [tag: string]: string[] }

type HtmlTags =
| 'a'
Expand Down
6 changes: 3 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ const { modifyNodes } = require('reshape-plugin-util')

module.exports = function reshapeCustomElements(options = {}) {
const defaultReplacementTag =
options.replacementTag || options.defaultTag || 'div'
options.defaultReplacementTag || options.defaultTag || 'div'
const additionalTags = options.additionalTags || options.skipTags || []
const blacklist = options.blacklist || []
const replacementTagMap = createLookupMap(options.replacementTagMap || {})
const replacementTagAttr =
options.replacementTagOverrideAttribute || 'data-replacement'
const replacementTagMap = createLookupMap(options.replacementTagMap || {})
const blacklist = options.blacklist || []

return function(tree) {
return modifyNodes(
Expand Down
4 changes: 2 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ test('undefined options', t => {
return compare(t, html, expected, undefined)
})

test('replacementTag', t => {
test('defaultReplacementTag', t => {
const html = '<custom class="custom">Test</custom>'
const expected = '<span class="custom">Test</span>'
return compare(t, html, expected, { replacementTag: 'span' })
return compare(t, html, expected, { defaultReplacementTag: 'span' })
})

test('additionalTags option', t => {
Expand Down

0 comments on commit f8212e7

Please sign in to comment.