UNPKG

@netlify/framework-info

Version:

Framework detection utility

31 lines (30 loc) 1.02 kB
import { includeKeys } from 'filter-obj'; import isPlainObj from 'is-plain-obj'; export const getPackageJsonContent = function (packageJson) { if (packageJson === undefined) { return { npmDependencies: [], scripts: {} }; } const npmDependencies = getNpmDependencies(packageJson); const scripts = getScripts(packageJson); return { npmDependencies, scripts }; }; // Retrieve `package.json` `dependencies` and `devDependencies` names const getNpmDependencies = function ({ dependencies, devDependencies }) { return [...getObjectKeys(dependencies), ...getObjectKeys(devDependencies)]; }; const getObjectKeys = function (value) { if (!isPlainObj(value)) { return []; } return Object.keys(value); }; // Retrieve `package.json` `scripts` const getScripts = function ({ scripts }) { if (!isPlainObj(scripts)) { return {}; } return includeKeys(scripts, isValidScript); }; const isValidScript = function (_key, value) { return typeof value === 'string'; };