"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/npm/lib/utils/module-name.js" (8 Mar 2017, 949 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 'use strict'
    2 var path = require('path')
    3 var validate = require('aproba')
    4 
    5 module.exports = moduleName
    6 module.exports.test = {}
    7 
    8 module.exports.test.pathToPackageName = pathToPackageName
    9 function pathToPackageName (dir) {
   10   if (dir == null) return ''
   11   if (dir === '') return ''
   12   var name = path.relative(path.resolve(dir, '..'), dir)
   13   var scoped = path.relative(path.resolve(dir, '../..'), dir)
   14   if (scoped[0] === '@') return scoped.replace(/\\/g, '/')
   15   return name
   16 }
   17 
   18 module.exports.test.isNotEmpty = isNotEmpty
   19 function isNotEmpty (str) {
   20   return str != null && str !== ''
   21 }
   22 
   23 var unknown = 0
   24 function moduleName (tree) {
   25   validate('O', arguments)
   26   var pkg = tree.package || tree
   27   if (isNotEmpty(pkg.name)) return pkg.name
   28   var pkgName = pathToPackageName(tree.path)
   29   if (pkgName !== '') return pkgName
   30   if (tree._invalidName != null) return tree._invalidName
   31   tree._invalidName = '!invalid#' + (++unknown)
   32   return tree._invalidName
   33 }