New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

format-package

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

format-package - npm Package Compare versions

Comparing version 4.5.1 to 5.0.0

.huskrc.json

18

lib/defaults/formatter.js

@@ -1,5 +0,19 @@

function formatter(obj) {
return [JSON.stringify(obj, null, 2), '\n'].join('');
async function formatter(obj) {
const content = JSON.stringify(obj, null, 2);
let prettier;
try {
prettier = require('prettier');
} catch (error) {
return [content, '\n'].join('');
}
const options = (await prettier.resolveConfig(process.cwd())) || {};
return prettier.format(content, {
...options,
parser: 'json',
printWidth: 0,
});
}
module.exports = formatter;

36

package.json
{
"name": "format-package",
"version": "4.5.1",
"version": "5.0.0",
"description": "Sensible formatting and ordering of package.json",

@@ -32,14 +32,10 @@ "license": "MIT",

"format": "npm-run-all format:*",
"format:js": "prettier --write \"**/*.{md,js,json}\"",
"format:pkg": "./lib/cli/index.js -wp",
"format:src": "prettier --write \"**/*.{md,js,json}\"",
"gamut": "npm-run-all reset docs format lint test",
"lint": "eslint \"**/*.js\"",
"prepublishOnly": "yarn gamut",
"reset": "cross-env rimraf node_modules && yarn install",
"test": "jest"
},
"husky": {
"hooks": {
"post-merge": "install-deps-postmerge",
"pre-commit": "lint-staged",
"pre-push": "yarn test"
}
},
"lint-staged": {

@@ -63,18 +59,22 @@ "**/package.json": [

"convert-hrtime": "^3.0.0",
"globby": "^9.2.0",
"sort-scripts": "^1.0.0",
"globby": "10.0.1",
"sort-scripts": "^1.0.1",
"yargs": "^13.2.4"
},
"peerDependencies": {
"prettier": "^1.6.0"
},
"devDependencies": {
"codecov": "^3.5.0",
"eslint": "^5.16.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-config-prettier": "^4.3.0",
"cross-env": "^5.2.0",
"eslint": "^6.0.1",
"eslint-config-airbnb-base": "13.2.0",
"eslint-config-prettier": "^6.0.0",
"eslint-plugin-import": "^2.17.2",
"execa": "^1.0.0",
"execa": "2.0.3",
"glob": "^7.1.4",
"husky": "^2.3.0",
"husky": "3.0.0",
"install-deps-postmerge": "^1.0.3",
"jest": "^24.8.0",
"lint-staged": "^8.1.7",
"lint-staged": "9.0.2",
"markdown-magic": "^0.1.25",

@@ -86,4 +86,4 @@ "markdown-magic-engines": "^1.0.2",

"npm-run-all": "^4.1.5",
"prettier": "^1.17.1"
"prettier": "^1.18.2"
}
}

@@ -8,3 +8,3 @@ # Format Package [![codecov](https://codecov.io/gh/camacho/format-package/branch/master/graph/badge.svg)](https://codecov.io/gh/camacho/format-package)

```sh
yarn add -D format-package
yarn add -D format-package prettier@^1.6.0
```

@@ -321,3 +321,3 @@

By default, `JSON.stringify` is used:
By default, the formatter will try to use [`prettier`](https://github.com/prettier/prettier) if it is installed, and will fallback to `JSON.stringify` if the [peer dependency](https://nodejs.org/es/blog/npm/peer-dependencies/) is not found:

@@ -328,4 +328,18 @@ <!-- AUTO-GENERATED-CONTENT:START (CODE:src=./lib/defaults/formatter.js) -->

```js
function formatter(obj) {
return [JSON.stringify(obj, null, 2), '\n'].join('');
async function formatter(obj) {
const content = JSON.stringify(obj, null, 2);
let prettier;
try {
prettier = require('prettier');
} catch (error) {
return [content, '\n'].join('');
}
const options = (await prettier.resolveConfig(process.cwd())) || {};
return prettier.format(content, {
...options,
parser: 'json',
printWidth: 0,
});
}

@@ -338,22 +352,2 @@

An alternative would be to use [`prettier`](https://github.com/prettier/prettier):
<!-- AUTO-GENERATED-CONTENT:START (PRETTIER) -->
```js
const formatPkg = require('format-package');
const prettier = require('prettier');
const pkg = require('./package.json');
const formatter = async content => {
const options = await prettier.resolveConfig('./package.json');
// include `{ parser: 'json' }` in the options passed to prettier
return prettier.format(content, { ...options, parser: 'json' });
};
formatPkg(pkg, { formatter });
```
<!-- AUTO-GENERATED-CONTENT:END *-->
### CLI

@@ -432,10 +426,13 @@

| Script | Description |
| ------------ | --------------------------------------------------------------------------------------------------------------------- |
| `docs` | updates any auto-generated-content blocks in [Markdown](https://guides.github.com/features/mastering-markdown/) files |
| `format` | format the application code |
| `format:js` | format JS using [prettier](https://github.com/prettier/prettier) |
| `format:pkg` | format package.json |
| `lint` | lint the application code |
| `test` | run unit tests for the application |
| Script | Description |
| ---------------- | --------------------------------------------------------------------------------------------------------------------- |
| `docs` | updates any auto-generated-content blocks in [Markdown](https://guides.github.com/features/mastering-markdown/) files |
| `format` | format the application code |
| `format:pkg` | format package.json |
| `format:src` | format source content using [prettier](https://github.com/prettier/prettier) |
| `gamut` | run the full gamut of checks - reset environment, generate docs, format and lint code, and run tests |
| `lint` | lint the application code |
| `prepublishOnly` | make sure the package is in good state before publishing |
| `reset` | reset the `node_modules` dependencies |
| `test` | run unit tests for the application |

@@ -442,0 +439,0 @@ <!-- AUTO-GENERATED-CONTENT:END -->

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc