Run NPM script ONLY when a JS file is staged
<p>Is there a way to run an NPM script ONLY when a JS file is staged? Specifically, after a <code>pre-commit</code> git hook (using <a href="https://github.com/typicode/husky" rel="nofollow noreferrer">Husky</a>). I have the following scripts in my <code>package.json</code>:</p>

<pre><code>"scripts": {
    ...
    "test": "jest",
    "precommit": "npm test",
    ...
},
</code></pre>

<p>I want to be able to only run <code>jest</code> if there are JS files staged. How can I achieve this?</p>