diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..79c7e3b --- /dev/null +++ b/index.d.ts @@ -0,0 +1,44 @@ +import type { + OperatorFunctionType, + parsed, + SemanticFunctionType, + VersionFunctionType, +} from "./lib/shared"; + +export function valid(fn: VersionFunctionType): string | null; +export function clean(fn: VersionFunctionType): string | null; +export function explain(fn: VersionFunctionType): parsed | null; + +//operator +export function compare(fn: OperatorFunctionType): number; +export function rcompare(fn: OperatorFunctionType): number; +export function gt(fn: OperatorFunctionType): boolean; +export function eq(fn: OperatorFunctionType): boolean; +export function lt(fn: OperatorFunctionType): boolean; +export function ge(fn: OperatorFunctionType): boolean; +export function nq(fn: OperatorFunctionType): boolean; +export function gte(fn: OperatorFunctionType): boolean; +export function neq(fn: OperatorFunctionType): boolean; +export function le(fn: OperatorFunctionType): boolean; +export function lte(fn: OperatorFunctionType): boolean; +export function arbitrary(fn: OperatorFunctionType): boolean; + +//range +export function satisfies(version: string, specifier: string): boolean; +export function validRange(specifier: string): boolean; +export function maxSatisfying( + version: string, + specifier: string, + options: parsed +): string | null; +export function minSatisfying( + version: string, + specifier: string, + options: parsed +): string | null; + +//semantic +export function major(fn: SemanticFunctionType): number; +export function minor(fn: SemanticFunctionType): number; +export function patch(fn: SemanticFunctionType): number; +export function inc(fn: SemanticFunctionType): string | null; diff --git a/lib/operator.d.ts b/lib/operator.d.ts new file mode 100644 index 0000000..9f70d5e --- /dev/null +++ b/lib/operator.d.ts @@ -0,0 +1,11 @@ +import type { OperatorFunctionType } from "./shared"; + +export function compare(fn: OperatorFunctionType): number; +export function rcompare(fn: OperatorFunctionType): number; +export function gt(fn: OperatorFunctionType): boolean; +export function eq(fn: OperatorFunctionType): boolean; +export function lt(fn: OperatorFunctionType): boolean; +export function ge(fn: OperatorFunctionType): boolean; +export function nq(fn: OperatorFunctionType): boolean; +export function le(fn: OperatorFunctionType): boolean; +export function arbitrary(fn: OperatorFunctionType): boolean; diff --git a/lib/semantic.d.ts b/lib/semantic.d.ts new file mode 100644 index 0000000..c073897 --- /dev/null +++ b/lib/semantic.d.ts @@ -0,0 +1,6 @@ +import type { SemanticFunctionType } from "./shared"; + +export function major(fn: SemanticFunctionType): number; +export function minor(fn: SemanticFunctionType): number; +export function patch(fn: SemanticFunctionType): number; +export function inc(fn: SemanticFunctionType): string | null; diff --git a/lib/shared.d.ts b/lib/shared.d.ts new file mode 100644 index 0000000..aef4bc2 --- /dev/null +++ b/lib/shared.d.ts @@ -0,0 +1,22 @@ +import type { SemVer } from "semver"; +export interface parsed { + public: string; + base_version: string; + is_prerelease: boolean; + is_devrelease: boolean; + is_postrelease: boolean; + epoch: number; + release: number[]; + pre: (string | number)[]; + post: (string | number)[]; + dev: (string | number)[]; + local: string | null; +} +export interface Range { + operator: string; + prefix: string; + version: string; +} +export type VersionFunctionType = (version: string) => string | null; +export type SemanticFunctionType = (input: string | SemVer) => number; +export type OperatorFunctionType = (version: string, other: string) => number; diff --git a/lib/specifier.d.ts b/lib/specifier.d.ts new file mode 100644 index 0000000..f9a4998 --- /dev/null +++ b/lib/specifier.d.ts @@ -0,0 +1,41 @@ +import type { parsed, Range } from "./shared"; + +export const RANGE_PATTERN: string; + +/* + parse function takes a string and returns an object that has the values of both th ebelow interfaces combined + interface Range { + operator: string; + prefix: string; + version: string; + } + * interface parsed{ + public: string; + base_version: string; + is_prerelease: boolean; + is_devrelease: boolean; + is_postrelease: boolean; + epoch: number; + release: number[]; + pre: (string | number)[]; + post: (string | number)[]; + dev: (string | number)[]; + local: string | null; +} + still I have used interface Range as its return type cause it is being used in the file + lib/versioning/pep440/range.ts as so L52 + */ +export function parse(ranges: string): Range[]; // have doubts regarding this which need to be discussed +export function filter(versions: string[], range: string): string[]; +export function satisfies(version: string, specifier: string): boolean; +export function validRange(specifier: string): boolean; +export function maxSatisfying( + version: string, + specifier: string, + options: parsed +): string | null; +export function minSatisfying( + version: string, + specifier: string, + options: parsed +): string | null; diff --git a/lib/version.d.ts b/lib/version.d.ts new file mode 100644 index 0000000..f31cd53 --- /dev/null +++ b/lib/version.d.ts @@ -0,0 +1,8 @@ +import type { VersionFunctionType, parsed } from "./shared"; + +export const VERSION_PATTERN: string; +export function valid(fn: VersionFunctionType): string | null; +export function clean(fn: VersionFunctionType): string | null; +export function stringify(fn: VersionFunctionType): string | null; +export function parse(fn: VersionFunctionType): parsed | null; +export function explain(fn: VersionFunctionType): parsed | null; diff --git a/package.json b/package.json index ca9c873..0e833c8 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,8 @@ }, "files": [ "index.js", - "lib" + "lib", + "index.d.ts" ], "dependencies": { "xregexp": "4.4.1"