get-package-type [![NPM Version][npm-image]][npm-url]
-
<h2>get-package-type [![NPM Version][npm-image]][npm-url]</h2>
<p>Determine the <code>package.json#type</code> which applies to a location.</p>
<h3>Usage</h3>
<pre><code>
const getPackageType = require('get-package-type');(async () => {
console.log(await getPackageType('file.js'));
console.log(getPackageType.sync('file.js'));
})();
</code></pre><p>This function does not validate the value found in <code>package.json#type</code>. Any truthy value</p>
<p>found will be returned. Non-truthy values will be reported as <code>commonjs</code>.</p><p>The argument must be a filename.</p>
<pre><code>
// This never looks atdir1/, 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');
</code></pre><p>The extension of the filename does not effect the result. The primary use case for this</p>
<p>module is to determine if <code>myapp.config.js</code> should be loaded with <code>require</code> or <code>import</code>.</p><p>[npm-image]: https://img.shields.io/npm/v/get-package-type.svg</p>
<p>[npm-url]: https://npmjs.org/package/get-package-type</p><hr>
<p>本文由模极社发布</p>
<h4>
内容概览</h4><table>
<tr><td>分类</td><td>要点</td><td>建议/说明</td></tr>
<tr><td>核心概念</td><td>get-package-type [![</td><td>详见正文</td></tr>
<tr><td>操作步骤</td><td>get-package-type [![</td><td>详见正文</td></tr>
<tr><td>注意事项</td><td>get-package-type [![</td><td>详见正文</td></tr>
<tr><td>适用场景</td><td>get-package-type [![</td><td>详见正文</td></tr>
<tr><td>常见问题</td><td>get-package-type [![</td><td>详见正文</td></tr>
</table><hr>
<h4>
你可能还感兴趣</h4>
<ul>
<li><a href="/t/3459/3459">厦门模具产业集群</a></li>
<li><a href="/t/887/887">SKD61适合做什么模具?</a></li>
<li><a href="/t/4804/4804">重庆模具产业集群 — 中国西部汽车模具之都</a></li>
</ul><hr>
<p><strong>相关推荐:</strong></p>
<ul>
<li><a href="https://www.mj7.cn/t/topic">注塑产品报价不会算?完整成本计算模板来了(附公式+案例)</a></li>
<li><a href="https://www.mj7.cn/t/pp">PP塑料:性能参数与注塑成型指南</a></li>
<li><a href="https://www.mj7.cn/t/pa">PA塑料:性能参数与注塑成型指南</a></li>
</ul><hr>
<p>各位师傅觉得这个方案怎么样?有更好的做法吗?</p>