index.js 408 B

1234567891011121314151617
  1. 'use strict'
  2. module.exports = function () {
  3. if (!process.env.npm_config_user_agent) {
  4. return undefined
  5. }
  6. return pmFromUserAgent(process.env.npm_config_user_agent)
  7. }
  8. function pmFromUserAgent (userAgent) {
  9. const pmSpec = userAgent.split(' ')[0]
  10. const separatorPos = pmSpec.lastIndexOf('/')
  11. return {
  12. name: pmSpec.substr(0, separatorPos),
  13. version: pmSpec.substr(separatorPos + 1)
  14. }
  15. }