Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: keithamus/sort-package-json
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.5.0
Choose a base ref
...
head repository: keithamus/sort-package-json
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.5.1
Choose a head ref
  • 2 commits
  • 2 files changed
  • 2 contributors

Commits on Jul 2, 2023

  1. docs: adjust header for --stdin flag (#298)

    the header level was different than the rest
    danielpza authored Jul 2, 2023
    Copy the full SHA
    4ed94f9 View commit details

Commits on Jul 8, 2023

  1. Copy the full SHA
    058d8cb View commit details
Showing with 26 additions and 42 deletions.
  1. +1 −1 README.md
  2. +25 −41 index.d.ts
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -89,7 +89,7 @@ $ sort-package-json "**/package.json" --check --quiet
$ sort-package-json "**/package.json" --quiet
```

### `--stdin` flag
#### `--stdin` flag

To read from `stdin` and output the result to `stdout` use the `--stdin` flag.

66 changes: 25 additions & 41 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,33 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

declare namespace sortPackageJson {
interface SortPackageJsonFn {
/**
* Sort packageJson object.
*
* @param packageJson - A packageJson
* @param options - An options object
* @returns Sorted packageJson object
*/
<T extends Record<any, any>>(packageJson: T, options?: Options): T
type ComparatorFunction = (left: string, right: string) => number

/**
* Sort packageJson string.
*
* @param packageJson - A packageJson string.
* @param options - An options object
* @returns Sorted packageJson string.
*/
(packageJson: string, options?: Options): string
}

type ComparatorFunction = (left: string, right: string) => number

function sortObjectBy<T extends Record<any, any>>(
comparator?: string[],
deep?: boolean,
): (x: T) => T

interface Field {
readonly key: string
over?<T extends Record<any, any>>(x: T): T
}

interface Options {
readonly sortOrder?: readonly string[] | ComparatorFunction
}
interface Options {
readonly sortOrder?: readonly string[] | ComparatorFunction
}

interface sortPackageJsonExports extends sortPackageJson.SortPackageJsonFn {
readonly default: sortPackageJson.SortPackageJsonFn
readonly sortPackageJson: sortPackageJson.SortPackageJsonFn
readonly sortOrder: string[]
interface SortPackageJson {
/**
* Sort packageJson object.
*
* @param packageJson - A packageJson
* @param options - An options object
* @returns Sorted packageJson object
*/
<T extends Record<any, any>>(packageJson: T, options?: Options): T

/**
* Sort packageJson string.
*
* @param packageJson - A packageJson string.
* @param options - An options object
* @returns Sorted packageJson string.
*/
(packageJson: string, options?: Options): string
}

declare const sortPackageJsonExports: sortPackageJsonExports
declare const sortPackageJsonDefault: SortPackageJson
export default sortPackageJsonDefault

export = sortPackageJsonExports
export const sortPackageJson: SortPackageJson
export const sortOrder: string[]