Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sort-package-json

Package Overview
Dependencies
Maintainers
1
Versions
97
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sort-package-json - npm Package Compare versions

Comparing version 1.41.0 to 1.42.0

6

cli.js

@@ -6,3 +6,3 @@ #!/usr/bin/env node

const isCheckFlag = argument => argument === '--check' || argument === '-c'
const isCheckFlag = (argument) => argument === '--check' || argument === '-c'

@@ -12,3 +12,3 @@ const cliArguments = process.argv.slice(2)

const patterns = cliArguments.filter(argument => !isCheckFlag(argument))
const patterns = cliArguments.filter((argument) => !isCheckFlag(argument))

@@ -28,3 +28,3 @@ if (!patterns.length) {

files.forEach(file => {
files.forEach((file) => {
const packageJson = fs.readFileSync(file, 'utf8')

@@ -31,0 +31,0 @@ const sorted = sortPackageJson(packageJson)

/* eslint-disable @typescript-eslint/no-explicit-any */
type ComparatorFunction = (left: string, right: string) => number
declare namespace sortPackageJson {
interface Options {
readonly sortOrder?: readonly string[] | ComparatorFunction
}
}
declare const sortPackageJson: {
/**
/**
Sort packageJson.

@@ -18,25 +9,19 @@

@returns Sorted packageJson object or string.
*/
<T extends any>(packageJson: T, options?: sortPackageJson.Options): T
*/
declare function sortPackageJsonCore<T extends Record<any, any>>(packageJson: T, options?: sortPackageJsonCore.Options): T;
declare namespace sortPackageJsonCore {
var sortPackageJson: typeof sortPackageJsonCore;
// @ts-ignore
var default: typeof sortPackageJsonCore;
}
declare namespace sortPackageJsonCore {
type ComparatorFunction = (left: string, right: string) => number;
interface Options {
readonly sortOrder?: readonly string[] | ComparatorFunction;
}
/**
Sort packageJson.
@param packageJson - A packageJson object or string.
@param options
@returns Sorted packageJson object or string.
*/
sortPackageJson<T extends any>(
packageJson: T,
options?: sortPackageJson.Options,
): T
/**
Default sort order.
*/
readonly sortOrder: readonly string[]
const sortOrder: readonly string[];
}
export default sortPackageJson
export = sortPackageJsonCore;

@@ -9,12 +9,12 @@ const sortObjectKeys = require('sort-object-keys')

Object.prototype.hasOwnProperty.call(object, property)
const pipe = fns => x => fns.reduce((result, fn) => fn(result), x)
const onArray = fn => x => (Array.isArray(x) ? fn(x) : x)
const onStringArray = fn => x =>
Array.isArray(x) && x.every(item => typeof item === 'string') ? fn(x) : x
const uniq = onStringArray(xs => xs.filter((x, i) => i === xs.indexOf(x)))
const sortArray = onStringArray(array => [...array].sort())
const pipe = (fns) => (x) => fns.reduce((result, fn) => fn(result), x)
const onArray = (fn) => (x) => (Array.isArray(x) ? fn(x) : x)
const onStringArray = (fn) => (x) =>
Array.isArray(x) && x.every((item) => typeof item === 'string') ? fn(x) : x
const uniq = onStringArray((xs) => xs.filter((x, i) => i === xs.indexOf(x)))
const sortArray = onStringArray((array) => [...array].sort())
const uniqAndSortArray = pipe([uniq, sortArray])
const onObject = fn => x => (isPlainObject(x) ? fn(x) : x)
const onObject = (fn) => (x) => (isPlainObject(x) ? fn(x) : x)
const sortObjectBy = (comparator, deep) => {
const over = onObject(object => {
const over = onObject((object) => {
object = sortObjectKeys(object, comparator)

@@ -42,3 +42,3 @@ if (deep) {

])
const overProperty = (property, over) => object =>
const overProperty = (property, over) => (object) =>
hasOwnProperty(object, property)

@@ -77,3 +77,3 @@ ? Object.assign(object, { [property]: over(object[property]) })

'overrides',
onArray(overrides => overrides.map(sortEslintConfig)),
onArray((overrides) => overrides.map(sortEslintConfig)),
),

@@ -97,6 +97,6 @@ overProperty('parserOptions', sortObject),

// sort keys alphabetically, but put `overrides` at bottom
config =>
(config) =>
sortObjectKeys(config, [
...Object.keys(config)
.filter(key => key !== 'overrides')
.filter((key) => key !== 'overrides')
.sort(),

@@ -109,3 +109,3 @@ 'overrides',

// and `config.overrides` is an array
onArray(overrides =>
onArray((overrides) =>
overrides.map(

@@ -139,3 +139,3 @@ pipe([

const sortScripts = onObject(scripts => {
const sortScripts = onObject((scripts) => {
const names = Object.keys(scripts)

@@ -145,3 +145,3 @@ const prefixable = new Set()

const keys = names
.map(name => {
.map((name) => {
const omitted = name.replace(/^(?:pre|post)/, '')

@@ -193,3 +193,3 @@ if (defaultNpmScripts.has(omitted) || names.includes(omitted)) {

key: 'contributors',
over: onArray(contributors => contributors.map(sortPeopleObject)),
over: onArray((contributors) => contributors.map(sortPeopleObject)),
},

@@ -247,2 +247,3 @@ /* vscode */ { key: 'publisher' },

{ key: 'eslintIgnore' },
{ key: 'npmpkgjsonlint', over: sortObject },
{ key: 'remarkConfig', over: sortObject },

@@ -275,3 +276,3 @@ { key: 'stylelint' },

key: 'badges',
over: onArray(badge => badge.map(sortVSCodeBadgeObject)),
over: onArray((badge) => badge.map(sortVSCodeBadgeObject)),
},

@@ -310,3 +311,3 @@ /* vscode */ { key: 'galleryBanner', over: sortObject },

const isPrivateKey = key => key[0] === '_'
const isPrivateKey = (key) => key[0] === '_'
const partition = (array, predicate) =>

@@ -323,3 +324,3 @@ array.reduce(

jsonIsh,
onObject(json => {
onObject((json) => {
let sortOrder = options.sortOrder ? options.sortOrder : defaultSortOrder

@@ -346,1 +347,2 @@

module.exports.sortOrder = defaultSortOrder
module.exports.default = sortPackageJson
{
"name": "sort-package-json",
"version": "1.41.0",
"version": "1.42.0",
"description": "Sort an Object or package.json based on the well-known package.json keys",

@@ -84,3 +84,3 @@ "keywords": [

"@commitlint/config-conventional": "8.3.4",
"ava": "3.4.0",
"ava": "3.5.1",
"del": "5.1.0",

@@ -100,6 +100,6 @@ "dot-prop": "^5.2.0",

"nyc": "^15.0.0",
"prettier": "^1.19.1",
"semantic-release": "17.0.4",
"prettier": "^2.0.4",
"semantic-release": "17.0.5",
"tempy": "0.4.0"
}
}

@@ -183,2 +183,3 @@ # Sort Package.json

- [node-pre-gyp](https://github.com/mapbox/node-pre-gyp)
- [npm-package-json-lint](https://npmpackagejsonlint.org/)
- [Prettier](https://prettier.io/)

@@ -185,0 +186,0 @@ - [remark](https://remark.js.org/)

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