UNPKG

prettier-plugin-pkg

Version:

An opinionated package.json formatter plugin for Prettier

35 lines 1.03 kB
import { sortStringArray } from '../utils.js'; const process = (props) => { const filesNode = props.find(prop => prop.key.value === 'files'); if (!filesNode) { return props; } let readme; let license; const filesNodeValue = filesNode.value; const [normals, negations] = filesNodeValue.elements.reduce((acc, node) => { const value = node.value.toLowerCase(); if (value === 'license') { license = node; return acc; } if (value === 'readme' || value === 'readme.md') { readme = node; return acc; } acc[+value.startsWith('!')].push(node); return acc; }, [[], []]); normals.sort(sortStringArray); negations.sort(sortStringArray); if (readme) { normals.push(readme); } if (license) { normals.push(license); } filesNodeValue.elements = [...normals, ...negations]; return props; }; export { process as files }; //# sourceMappingURL=files.js.map