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: add type declarations #113

Merged
merged 15 commits into from
Jan 9, 2022
44 changes: 44 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -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;
11 changes: 11 additions & 0 deletions lib/operator.d.ts
Original file line number Diff line number Diff line change
@@ -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;
6 changes: 6 additions & 0 deletions lib/semantic.d.ts
Original file line number Diff line number Diff line change
@@ -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;
22 changes: 22 additions & 0 deletions lib/shared.d.ts
Original file line number Diff line number Diff line change
@@ -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;
41 changes: 41 additions & 0 deletions lib/specifier.d.ts
Original file line number Diff line number Diff line change
@@ -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;
8 changes: 8 additions & 0 deletions lib/version.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { VersionFunctionType, parsed } from "./shared";
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved

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;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
},
"files": [
"index.js",
"lib"
"lib",
"index.d.ts"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is missing, the file won't included in published package. 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read somewhere that all files are included by default now, and only the files under .npmignore are left out.

Nonetheless this is a good code-practice and an advisable thing to do as per the docs.✨

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, by default all files are included. But if you define the files explicit, only those will be included in published package.

Copy link
Contributor Author

@RahulGautamSingh RahulGautamSingh Jan 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh yes, got it. I misunderstood and thought that even if we explicitly have a files property all others will be included.
Thanks , more clarity now.🙏

],
"dependencies": {
"xregexp": "4.4.1"
Expand Down