demo___customer_pitch-c4152739-a50b-4b5b-9d4d-0561461666d9.zip-extract/_dependencies/npm/express-4.18.2/lib/view.js

Path
demo___customer_pitch-c4152739-a50b-4b5b-9d4d-0561461666d9.zip-extract/_dependencies/npm/express-4.18.2/lib/view.js
Status
scanned
Type
file
Name
view.js
Extension
.js
Programming language
JavaScript
Mime type
text/plain
File type
ASCII text
Tag

      
    
Rootfs path

      
    
Size
3325 (3.2 KB)
MD5
09c05d27b2f11d1bd70fb54c24c60311
SHA1
4cfb7f23cb0a4b9f11dacc7e81dca3782f63552f
SHA256
ec627880c1b43aee5887164ac2e9c58f01e4ee8086e23a829eddf1af3858c021
SHA512

      
    
SHA1_git
c08ab4d8d521cc18cbb89c3a705d8f137d12d056
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
view.js | 3.2 KB |

/*! * express * Copyright(c) 2009-2013 TJ Holowaychuk * Copyright(c) 2013 Roman Shtylman * Copyright(c) 2014-2015 Douglas Christopher Wilson * MIT Licensed */ 'use strict'; /** * Module dependencies. * @private */ var debug = require('debug')('express:view'); var path = require('path'); var fs = require('fs'); /** * Module variables. * @private */ var dirname = path.dirname; var basename = path.basename; var extname = path.extname; var join = path.join; var resolve = path.resolve; /** * Module exports. * @public */ module.exports = View; /** * Initialize a new `View` with the given `name`. * * Options: * * - `defaultEngine` the default template engine name * - `engines` template engine require() cache * - `root` root path for view lookup * * @param {string} name * @param {object} options * @public */ function View(name, options) { var opts = options || {}; this.defaultEngine = opts.defaultEngine; this.ext = extname(name); this.name = name; this.root = opts.root; if (!this.ext && !this.defaultEngine) { throw new Error('No default engine was specified and no extension was provided.'); } var fileName = name; if (!this.ext) { // get extension from default engine name this.ext = this.defaultEngine[0] !== '.' ? '.' + this.defaultEngine : this.defaultEngine; fileName += this.ext; } if (!opts.engines[this.ext]) { // load engine var mod = this.ext.slice(1) debug('require "%s"', mod) // default engine export var fn = require(mod).__express if (typeof fn !== 'function') { throw new Error('Module "' + mod + '" does not provide a view engine.') } opts.engines[this.ext] = fn } // store loaded engine this.engine = opts.engines[this.ext]; // lookup path this.path = this.lookup(fileName); } /** * Lookup view by the given `name` * * @param {string} name * @private */ View.prototype.lookup = function lookup(name) { var path; var roots = [].concat(this.root); debug('lookup "%s"', name); for (var i = 0; i < roots.length && !path; i++) { var root = roots[i]; // resolve the path var loc = resolve(root, name); var dir = dirname(loc); var file = basename(loc); // resolve the file path = this.resolve(dir, file); } return path; }; /** * Render with the given options. * * @param {object} options * @param {function} callback * @private */ View.prototype.render = function render(options, callback) { debug('render "%s"', this.path); this.engine(this.path, options, callback); }; /** * Resolve the file within the given directory. * * @param {string} dir * @param {string} file * @private */ View.prototype.resolve = function resolve(dir, file) { var ext = this.ext; // <path>.<ext> var path = join(dir, file); var stat = tryStat(path); if (stat && stat.isFile()) { return path; } // <path>/index.<ext> path = join(dir, basename(file, ext), 'index' + ext); stat = tryStat(path); if (stat && stat.isFile()) { return path; } }; /** * Return a stat, maybe. * * @param {string} path * @return {fs.Stats} * @private */ function tryStat(path) { debug('stat "%s"', path); try { return fs.statSync(path); } catch (e) { return undefined; } }
Detected license expression
mit
Detected license expression (SPDX)
MIT
Percentage of license text
0.49
Copyrights
- end_line: 3
  copyright: Copyright (c) 2009-2013 TJ Holowaychuk
  start_line: 3
- end_line: 4
  copyright: Copyright (c) 2013 Roman Shtylman
  start_line: 4
- end_line: 5
  copyright: Copyright (c) 2014-2015 Douglas Christopher Wilson
  start_line: 5
Holders
- holder: TJ Holowaychuk
  end_line: 3
  start_line: 3
- holder: Roman Shtylman
  end_line: 4
  start_line: 4
- holder: Douglas Christopher Wilson
  end_line: 5
  start_line: 5
Authors

      
    
License detections License expression License expression SPDX
mit-4e7803e6-e54b-c9ca-bcd2-bee9755c0dd7 mit MIT
Package URL License Primary language
pkg:npm/express@4.18.2 mit JavaScript
pkg:npm/acme-demo-app@1.0.0 JavaScript