pax_global_header00006660000000000000000000000064134753017600014520gustar00rootroot0000000000000052 comment=b63e05164d3a63018ad6ec2f2ee914b43c02d32f 3rd-Eden-commenting-b63e051/000077500000000000000000000000001347530176000155465ustar00rootroot000000000000003rd-Eden-commenting-b63e051/.gitignore000066400000000000000000000000261347530176000175340ustar00rootroot00000000000000node_modules coverage 3rd-Eden-commenting-b63e051/README.md000066400000000000000000000032531347530176000170300ustar00rootroot00000000000000# commenting Commenting is a small module that allows you to wrap text in to a comment format which is suitable for the supplied extension. This can be useful if you do not want to trigger content errors for 404 routes on static assets so you can put your reason inside a comment instead of returning HTML. But it can also be used a development tool to inject build information in to your files for example. ## Installation Module is released in the public npm registry and can be installed by running: ``` npm install --save commenting ``` ## Usage The module exposes a single function as API. This function accepts the text as string or array as first argument and an options object as last argument. The following options are supported: - extension: The file extension, which is used to figure out which comment style should be used. - style: Override default extension mapping and provide a comment style your self (should be an object with start, body and end properties which contains the comment styles). ```js 'use strict'; var commenting = require('commenting') , comment; comment = commenting('hello world', { extension: '.js' }); /** * hello world */ comment = commenting(['hello', 'world'], { extension: '.jade' }); // // hello // world // ``` The following extensions are supported: - html, html: Uses HTML comments. - js, css, less, sass: Uses `/**/` style comments - coffee: Uses `###` style comments. - jade: Uses `//` style comments. Empty files or extension option with `''` as value is automatically mapped to a hash `#` based comment style. This is because things like `.npmignore` or `.gitignore` don't have have extensions that we can track. ## License MIT 3rd-Eden-commenting-b63e051/index.js000066400000000000000000000045251347530176000172210ustar00rootroot00000000000000'use strict'; var extension = Object.create(null) , styles = Object.create(null); /** * Representation of a single comment style. * * @constructor * @param {String} body Comment style for the body. * @param {String} start Comment style to start a comment. * @param {String} end Comment style to end a comment. * @api private */ function Style(body, start, end) { this.body = body; this.end = end || body; this.start = start || body; } // // Generate the different comment styles. // styles.hash = new Style('#'); styles.slash = new Style('//'); styles.star = new Style(' *','/**', ' */'); styles.triple = new Style('', '###', '###'); styles.html = new Style(' //', ''); // // Assign the different extensions to their correct commenting styles. // extension['.htm'] = extension['.svg'] = extension['.xml'] = extension['.html'] = styles.html; extension['.js'] = extension['.css'] = extension['.less'] = extension['.sass'] = extension['.styl'] = styles.star; extension['.coffee'] = styles.triple; extension['.jade'] = styles.slash; extension['.appcache'] = extension[''] = styles.hash; /** * Generate the resulting comment. * * Options: * * - style: Comment style for the given extension. * - extension: Extension where we determine our commenting style upon. * * @param {String|Array} text Text for the actual comment. * @param {Object} options Additional configuration. * @returns {String} * @api public */ function commenting(text, options) { // // Force comments to an array so we can easily assemble the resulting comment. // if ('string' === typeof text) text = text.split('\n'); if (options.extension && options.extension.charAt(0) !== '.') { options.extension = '.'+ options.extension; } var style = options.style || extension[options.extension] || styles.star , comment = []; comment.push(style.start); // // Just map the text and prefix it with comment body so we can optimize for // fewer Array.push calls for larger comments. // Array.prototype.push.apply(comment, text.map(function each(line) { return style.body + (line ? ' ' + line.trim() : ''); })); comment.push(style.end); comment.push(''); return comment.join('\n'); } // // Expose all the interfaces. // commenting.Style = Style; commenting.styles = styles; commenting.extension = extension; module.exports = commenting; 3rd-Eden-commenting-b63e051/package.json000066400000000000000000000020011347530176000200250ustar00rootroot00000000000000{ "name": "commenting", "version": "1.1.0", "description": "Wrap content in a comment that is valid for a given file type.", "main": "index.js", "scripts": { "100%": "istanbul check-coverage --statements 100 --functions 100 --lines 100 --branches 100", "test": "mocha test.js", "watch": "mocha --watch test.js", "coverage": "istanbul cover ./node_modules/.bin/_mocha -- test.js", "test-travis": "istanbul cover node_modules/.bin/_mocha --report lcovonly -- test.js" }, "repository": { "type": "git", "url": "git+https://github.com/3rd-Eden/commenting.git" }, "keywords": [ "comment", "comments", "commenting" ], "author": "Arnout Kazemier", "license": "MIT", "bugs": { "url": "https://github.com/3rd-Eden/commenting/issues" }, "homepage": "https://github.com/3rd-Eden/commenting#readme", "devDependencies": { "assume": "1.4.x", "istanbul": "0.3.x", "mocha": "2.2.x", "pre-commit": "1.0.x" }, "pre-commit": ["coverage", "100%"] } 3rd-Eden-commenting-b63e051/test.js000066400000000000000000000050771347530176000170740ustar00rootroot00000000000000describe('commenting', function () { 'use strict'; var commenting = require('./') , assume = require('assume'); it('is exported as a function', function () { assume(commenting).is.a('function'); }); it('can use array for multi-line comments', function () { var comment = commenting(['hello', 'world'], { extension: '.js' }); assume(comment).includes('/**\n'); assume(comment).includes(' * hello\n'); assume(comment).includes(' * world\n'); assume(comment).includes(' */'); }); it('trims comments', function () { var comment = commenting('hello ', { extension: '.js' }); assume(comment).includes('/**\n'); assume(comment).includes(' * hello\n'); assume(comment).includes(' */\n'); }); it('keep empty lines', function () { var comment = commenting(['hello', '', 'world'], { extension: '.js' }); assume(comment).includes('/**\n'); assume(comment).includes(' * hello\n'); assume(comment).includes(' *\n'); assume(comment).includes(' * world\n'); assume(comment).includes(' */\n'); }); it('uses the supplied style', function () { var comment = commenting('hello ', { style: commenting.styles.slash }); assume(comment).includes('//\n'); assume(comment).includes('// hello\n'); }); it('accepts extensions without a dot prefix', function () { var comment = commenting('hello', { extension: 'html' }); assume(comment).includes('\n'); }); it('defaults to /* if extension can not be determined', function () { var comment = commenting(['hello', 'world'], { extension: '.js'+ Math.random() }); assume(comment).includes('/**\n'); assume(comment).includes(' * hello\n'); assume(comment).includes(' * world\n'); assume(comment).includes(' */'); }); it('maps an empty string extension to hash', function () { var comment = commenting(['hello', 'world'], { extension: '' }); assume(comment).includes('# hello\n'); assume(comment).includes('# world\n'); }); it('maps appcache extension to hash', function () { var comment = commenting(['hello', 'world'], { extension: '.appcache' }); assume(comment).includes('# hello\n'); assume(comment).includes('# world\n'); }); it('maps xml extension to html style', function () { var comment = commenting(['hello', 'world'], { extension: '.xml' }); assume(comment).equals('\n'); }); });