1.0.0 • Published 8 years ago

append-snippet v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

append-snippet

NPM version Linux Build Status Windows Build Status Dependency Status

A function that synchronously injects a snippet of markup into an HTML document, immediately before the closing </body> tag.

var appendSnippet = require('append-snippet');

var html = '<body>\n<h1>hello!</h1>\ndemo\n</body>';

var result = appendSnippet('<script>alert("cods")</script>', html);
// <body>\n<h1>hello!</h1>\ndemo\n<script>alert("cods")</script></body>

If there's no closing body tag, it goes just before the </html>, or failing that, the end of the string.

License

MIT © Callum Locke