Skip to content
Myr

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

4 files+5 added−49 removed

modified:lib/express/plugins/view.js+3 added-2 removed
modified:lib/express/mime.js+2 added-2 removed
3 unmodified lines
4/**5 * Module dependencies.6 */7 8var utils = require('express/utils')8var extname = require('path').extname910/**11 * Mime type lookup table.12 */
350 unmodified lines
363 */364365exports.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 lines
28 return uid29}3031/**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 */3940exports.extname = function(path) {41 if (path.lastIndexOf('.') < 0) return42 return path.slice(path.lastIndexOf('.') + 1)43}4445/**46 * Return the basename of the given _path_.47 *48 * @param {string} path49 * @return {string}50 * @api public51 */5253exports.basename = function(path) {54 return path.split('/').slice(-1)[0]55}5657/**32 * Escape special characters in _html_.33 *34 * @param {string} html35 * @return {string}
116 unmodified lines
modified:spec/spec.utils.js-19 removed
15 unmodified lines
16 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