diff --git a/.gitignore b/.gitignore index e69de29..3c3629e 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/index.js b/index.js new file mode 100644 index 0000000..d214260 --- /dev/null +++ b/index.js @@ -0,0 +1,13 @@ +export default function doctypeToString(doctype) { + if (doctype === null) { + return '' + } + const doctypeString = `` + return doctypeString +} diff --git a/index.test.js b/index.test.js new file mode 100644 index 0000000..d1187ec --- /dev/null +++ b/index.test.js @@ -0,0 +1,48 @@ +import test from 'ava' +import Window from 'window'; + +import doctypeToString from '.' + +function makeStubDocument(doctype) { + const window = new Window() + const parser = new window.DOMParser() + const doc = parser.parseFromString( + `${doctype}`, + 'text/html' + ) + return doc +} + +test('should return empty string if absent', t => { + const doctype = '' + const doc = makeStubDocument() + t.is(doctypeToString(doc.doctype), doctype) +}) + +test('should work for a HTML5-ish doctype', t => { + const doctype = '' + const doc = makeStubDocument(doctype) + t.is(doctypeToString(doc.doctype), doctype) +}) + +test('should work for a HTML4-ish doctype', t => { + const doctype = '' + const doc = makeStubDocument(doctype) + t.is(doctypeToString(doc.doctype), doctype) +}) + +test('should work for a doctype without public id', t => { + const doctype = '' + const doc = makeStubDocument(doctype) + t.is(doctypeToString(doc.doctype), doctype) +}) + +// Cannot test, as modern parsers do not to support internal declarations. +// test('should work for a doctype with internal declarations', t => { +// const doctype = ` +// +// ]>` +// const doc = makeStubDocument(doctype) +// t.is(doctypeToString(doc.doctype), doctype) +// }) diff --git a/package.json b/package.json new file mode 100644 index 0000000..75ee1db --- /dev/null +++ b/package.json @@ -0,0 +1,27 @@ +{ + "name": "doctype-to-string", + "version": "0.0.0", + "description": "Convert a DOM DocumentType into a string, e.g. \"\"", + "main": "index.js", + "scripts": { + "test": "ava" + }, + "author": "Gerben ", + "license": "CC0-1.0", + "devDependencies": { + "ava": "^1.0.0-beta.3", + "babel-preset-env": "^1.6.1", + "babel-register": "^6.26.0", + "window": "^4.2.5" + }, + "babel": { + "presets": [ + "env" + ] + }, + "ava": { + "require": [ + "babel-register" + ] + } +}