commit 4a0ce2acc27084ed312d6fe474d98fd36f56513d Author: Gerben Date: Tue Mar 17 02:56:23 2020 +0100 Published by publish-to-git 1a268df55bf1af5d37fc2c2a26ac1b46c6ccbfc9 (HEAD -> refs/heads/master, tag: refs/tags/v0.1.3) 0.1.3 diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..d48629d --- /dev/null +++ b/Readme.md @@ -0,0 +1,23 @@ +# doctype-to-string + +Convert a DOM [DocumentType](https://developer.mozilla.org/en-US/docs/Web/API/DocumentType) (usually obtained via `document.doctype`) into a string, e.g.: + - `` + - `` + +## Install + + npm install "git+https://code.treora.com/gerben/doctype-to-string#latest" + + npm install doctype-to-string@latest + +..or equivalent + +## Usage + + import doctypeToString from 'doctype-to-string' + + const string = doctypeToString(document.doctype) + +## Licence + +[CC0](https://creativecommons.org/publicdomain/zero/1.0/); do whatever you want with this code. diff --git a/lib/index.js b/lib/index.js new file mode 100644 index 0000000..8c86218 --- /dev/null +++ b/lib/index.js @@ -0,0 +1,19 @@ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = doctypeToString; +function doctypeToString(doctype) { + if (doctype === null) { + return ''; + } + // Checking with instanceof DocumentType might be neater, but how to get a + // reference to DocumentType without assuming it to be available globally? + // To play nice with custom DOM implementations, we resort to duck-typing. + if (!doctype || doctype.nodeType !== doctype.DOCUMENT_TYPE_NODE || typeof doctype.name !== 'string' || typeof doctype.publicId !== 'string' || typeof doctype.systemId !== 'string') { + throw new TypeError('Expected a DocumentType'); + } + var doctypeString = ''; + return doctypeString; +} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..ff3bc50 --- /dev/null +++ b/package.json @@ -0,0 +1,39 @@ +{ + "name": "doctype-to-string", + "version": "0.1.3", + "description": "Convert a DOM DocumentType into a string, e.g. \"\"", + "repository": { + "type": "git", + "url": "https://code.treora.com/gerben/doctype-to-string" + }, + "main": "lib", + "scripts": { + "build": "babel -d lib src", + "postpublish": "publish-to-git --force && publish-to-git --force --tag latest", + "prepublish": "npm run build", + "test": "ava" + }, + "author": "Gerben ", + "license": "CC0-1.0", + "files": [ + "lib" + ], + "devDependencies": { + "ava": "^1.4.1", + "babel-cli": "^6.26.0", + "babel-preset-env": "^1.7.0", + "babel-register": "^6.26.0", + "publish-to-git": "^1.1.7", + "window": "^4.2.6" + }, + "babel": { + "presets": [ + "env" + ] + }, + "ava": { + "require": [ + "babel-register" + ] + } +}