Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: modernize type declarations #299

Merged
merged 1 commit into from
Jul 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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[]