Removed extname() / basename() utils. Using path module
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent 1385988 · Browse files · 4 files·+5 added−49 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+5 added−49 removed
- tests:+0 added−19 removed
- other:+5 added−30 removed
Provenance
- Commit
962f5fa- Tree
6084e42- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
1385988
4 files changed+5 added−49 removed
modified:lib/express/plugins/view.js+3 added-2 removed
4 unmodified lines567891011121353 unmodified lines67686970707172737475767777787980818219 unmodified lines4 unmodified lines * Module dependencies. */
var utils = require('express/utils'), extname = require('path').extname, fs = require('fs')
/** * Supported template engines.53 unmodified lines var self = this, options = options || {}, path = set('views') + '/' + view, type = path.split('.').slice(-2)[0], ext = utils.extname(path), ext = extname(path), layout = options.layout === undefined ? 'layout' : options.layout options.context = options.context || this self.contentType(ext) function render(content) { content = engine[type].render(content, options) if (layout) self.render(layout + '.' + type + '.' + ext, utils.mixin(true, options, { self.render(layout + '.' + type + ext, utils.mixin(true, options, { layout: false, locals: { body: content }19 unmodified linesmodified:lib/express/mime.js+2 added-2 removed
3 unmodified lines4 /**5 * Module dependencies.6 */7 8-var utils = require('express/utils')8+var extname = require('path').extname9 10 /**11 * Mime type lookup table.12 */350 unmodified lines363 */364 365 exports.type = function(path) {366 return exports.types[path] || 367- exports.types[utils.extname(path)] || 367+ exports.types[extname(path).substr(1)] || 368 set('default mime type') || 369 'application/octet-stream' 370 }modified:lib/express/utils.js-26 removed
27 unmodified lines28 return uid29 }30 31 /**32- * Return the extension name of the given _path_,33- * or null when not present.34- *35- * @param {string} path36- * @return {string}37- * @api public38- */39-40-exports.extname = function(path) {41- if (path.lastIndexOf('.') < 0) return42- return path.slice(path.lastIndexOf('.') + 1)43-}44-45-/**46- * Return the basename of the given _path_.47- *48- * @param {string} path49- * @return {string}50- * @api public51- */52-53-exports.basename = function(path) {54- return path.split('/').slice(-1)[0]55-}56-57-/**32 * Escape special characters in _html_.33 *34 * @param {string} html35 * @return {string}116 unmodified linesmodified:spec/spec.utils.js-19 removed
15 unmodified lines16 utils.uid().length.should.be_greater_than 2017 end18 end19 20- describe 'extname()'21- it 'should return the a files extension'22- utils.extname('image.png').should.eql 'png'23- utils.extname('image.large.png').should.eql 'png'24- utils.extname('/path/to/image.large.png').should.eql 'png'25- end26- 27- it 'should return null when not found'28- utils.extname('path').should.be_null29- utils.extname('/just/a/path').should.be_null30- end31- end32- 33- describe 'basename()'34- it 'should return a files basename'35- utils.basename('foo/bar/baz.image.png').should.eql 'baz.image.png'36- end37- end38- 20 describe 'mergeParam()'21 describe 'with empty params'22 it 'should merge the given key and value'23 params = {}81 unmodified lines