Huge news!Announcing our $20M Series A led by Andreessen Horowitz.Learn more
Socket
Socket
Log inDemoInstall

get-package-type

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Issues
File Explorer

Advanced tools

Install Socket

Protect your apps from supply chain attacks

Install

get-package-type

Determine the `package.json#type` which applies to a location

    0.1.0latest
    GitHub
    npm

Version published
Maintainers
1
Weekly downloads
21,441,378
decreased by-1.24%

Weekly downloads

Changelog

Source

0.1.0 (2020-05-19)

Features

  • Initial implementation (52863f4)

Readme

Source

get-package-type NPM Version

Determine the package.json#type which applies to a location.

Usage

const getPackageType = require('get-package-type');

(async () => {
  console.log(await getPackageType('file.js'));
  console.log(getPackageType.sync('file.js'));
})();

This function does not validate the value found in package.json#type. Any truthy value found will be returned. Non-truthy values will be reported as commonjs.

The argument must be a filename.

// This never looks at `dir1/`, first attempts to load `./package.json`.
const type1 = await getPackageType('dir1/');

// This attempts to load `dir1/package.json`.
const type2 = await getPackageType('dir1/index.cjs');

The extension of the filename does not effect the result. The primary use case for this module is to determine if myapp.config.js should be loaded with require or import.

FAQs

Last updated on 19 May 2020

Did you know?

Socket installs a GitHub app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install
SocketSocket SOC 2 Logo

Product

  • Package Issues
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc