This repository has been archived by the owner on Feb 12, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Remove deps - New exports named/default closes #8
- Loading branch information
1 parent
051e8c6
commit 1afa35e
Showing
8 changed files
with
96 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import { svgson, stringify } from './svgson' | ||
import svgson from './svgson' | ||
import stringify from './stringify' | ||
export default svgson | ||
export { stringify } | ||
export { stringify, svgson as parse } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
import { svgson, stringify } from './svgson' | ||
import svgson from './svgson' | ||
import stringify from './stringify' | ||
export default Object.assign({}, { parse: svgson, stringify }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { escapeText, escapeAttr } from './tools' | ||
|
||
const stringify = ( | ||
ast, | ||
{ | ||
transformAttr = (key, value, escape) => `${key}="${escape(value)}"`, | ||
selfClose = true, | ||
} = {} | ||
) => { | ||
if (Array.isArray(ast)) { | ||
return ast.map(ast => stringify(ast, { transformAttr, selfClose })).join('') | ||
} | ||
|
||
if (ast.type === 'text') { | ||
return escapeText(ast.value) | ||
} | ||
|
||
let attributes = '' | ||
for (const attr in ast.attributes) { | ||
const attrStr = transformAttr( | ||
attr, | ||
ast.attributes[attr], | ||
escapeAttr, | ||
ast.name | ||
) | ||
attributes += attrStr ? ` ${attrStr}` : '' | ||
} | ||
|
||
return ast.children.length || !selfClose | ||
? `<${ast.name}${attributes}>${stringify(ast.children, { | ||
transformAttr, | ||
selfClose, | ||
})}</${ast.name}>` | ||
: `<${ast.name}${attributes}/>` | ||
} | ||
|
||
export default stringify |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters