Skip to content

Commit

Permalink
Merge pull request #3 from Lukasz-pluszczewski/v2.0
Browse files Browse the repository at this point in the history
Improved types, added types exports
  • Loading branch information
Lukasz-pluszczewski authored Jul 11, 2021
2 parents 58f6fc7 + bd22ac6 commit 7389702
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 93 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,10 @@ swich function accepts two parameters: array of *Pattern*, *Result* tuples and *
## Changelog
### 1.2.0
- Improved types
- Added types exports
### 1.1.0
- Added fallThrough functionality
Expand Down
4 changes: 2 additions & 2 deletions build/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/index.js.map

Large diffs are not rendered by default.

70 changes: 27 additions & 43 deletions build/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Object } from "ts-toolbelt";
declare type Pattern<TValue> = RegExp | ((value: TValue) => boolean) | ((value: TValue) => any) | any;
declare type Result<TValue, TOutput> = TOutput | ((param: TValue) => TOutput);
declare type CaseElement<TValue, TOutput> = [
export declare type Pattern<TValue> = RegExp | ((value: TValue) => boolean) | ((value: TValue) => any) | any;
export declare type Result<TValue, TOutput> = TOutput | ((param: TValue) => TOutput);
export declare type CaseElement<TValue, TOutput> = [
Pattern<TValue>,
Result<TValue, TOutput>,
true?
];
declare type DefaultCaseElement<TValue, TOutput> = [Result<TValue, TOutput>];
declare type CaseElements<TValue, TOutput> = (CaseElement<TValue, TOutput> | DefaultCaseElement<TValue, TOutput>)[];
declare type Matcher<TValue, TOutput> = (config: Object.Omit<Config<TValue, TOutput>, "matcher" | "resultGetter">) => (valueToMatch: TValue, pattern: Pattern<TValue>) => boolean;
declare type ResultGetter<TValue, TOutput> = (config: Object.Omit<Config<TValue, TOutput>, "matcher" | "resultGetter">) => (valueToMatch: TValue, pattern: Pattern<TValue>, result: any) => TOutput;
declare type Config<TValue, TOutput> = {
export declare type DefaultCaseElement<TValue, TOutput> = [Result<TValue, TOutput>];
export declare type CaseElements<TValue, TOutput> = (CaseElement<TValue, TOutput> | DefaultCaseElement<TValue, TOutput>)[];
export declare type Matcher<TValue, TOutput> = (config: Object.Omit<Config<TValue, TOutput>, "matcher" | "resultGetter">) => (valueToMatch: TValue, pattern: Pattern<TValue>) => boolean;
export declare type ResultGetter<TValue, TOutput> = (config: Object.Omit<Config<TValue, TOutput>, "matcher" | "resultGetter">) => (valueToMatch: TValue, pattern: Pattern<TValue>, result: any) => TOutput;
export declare type Config<TValue, TOutput> = {
returnMany: boolean;
strict: boolean;
acceptTruthyFunctionReturn: boolean;
Expand All @@ -21,43 +21,27 @@ declare type Config<TValue, TOutput> = {
matcher: Matcher<TValue, TOutput>;
resultGetter: ResultGetter<TValue, TOutput>;
};
declare type BasicConfig<TValue, TOutput> = Object.Omit<Config<TValue, TOutput>, "matcher" | "resultGetter">;
export declare type BasicConfig<TValue, TOutput> = Object.Omit<Config<TValue, TOutput>, "matcher" | "resultGetter">;
export declare const defaultMatcher: <TValue, TOutput>(config: import("ts-toolbelt/out/Object/Omit")._Omit<Config<TValue, TOutput>, "matcher" | "resultGetter">) => (valueToMatch: TValue, pattern: any) => boolean;
export declare const defaultResultGetter: <TValue, TOutput>(config: import("ts-toolbelt/out/Object/Omit")._Omit<Config<TValue, TOutput>, "matcher" | "resultGetter">) => (valueToMatch: TValue, pattern: any, result: any) => TOutput;
export declare const createSwich: <TValue, TOutput>({ returnMany: defaultReturnMany, strict: defaultStrict, acceptTruthyFunctionReturn: defaultAcceptTruthyFunctionReturn, catchFunctionErrors: defaultCatchFunctionErrors, performReplaceOnRegex: defaultPerformReplaceOnRegex, runResultFunction: defaultRunResultFunction, stopFallThrough: defaultStopFallThrough, matcher: defaultMatcherValue, resultGetter: defaultResultGetterValue, }?: {
returnMany?: boolean;
strict?: boolean;
acceptTruthyFunctionReturn?: boolean;
catchFunctionErrors?: boolean;
performReplaceOnRegex?: boolean;
runResultFunction?: boolean;
stopFallThrough?: boolean;
matcher?: Matcher<TValue, TOutput>;
resultGetter?: ResultGetter<TValue, TOutput>;
}) => (patterns: CaseElements<TValue, TOutput>, { returnMany, strict, acceptTruthyFunctionReturn, catchFunctionErrors, performReplaceOnRegex, runResultFunction, stopFallThrough, matcher, resultGetter, }?: {
returnMany?: boolean;
strict?: boolean;
acceptTruthyFunctionReturn?: boolean;
catchFunctionErrors?: boolean;
performReplaceOnRegex?: boolean;
runResultFunction?: boolean;
stopFallThrough?: boolean;
matcher?: Matcher<TValue, TOutput>;
resultGetter?: ResultGetter<TValue, TOutput>;
}) => (valueToMatch?: boolean | TValue) => TOutput[];
export declare const defaultResultGetter: <TValue, TOutput>(config: import("ts-toolbelt/out/Object/Omit")._Omit<Config<TValue, TOutput>, "matcher" | "resultGetter">) => (valueToMatch: TValue, pattern: any, result: TOutput) => TOutput;
declare type SwichReturnMany<TValue, TOutput> = (valueToMatch?: TValue | true) => TOutput[];
declare type SwichReturnOne<TValue, TOutput> = (valueToMatch?: TValue | true) => TOutput;
declare function swich<TValue, TOutput>(patterns: CaseElements<TValue, TOutput>, config: Object.Optional<Config<TValue, TOutput>> & {
returnMany: true;
}): SwichReturnMany<TValue, TOutput>;
declare function swich<TValue, TOutput>(patterns: CaseElements<TValue, TOutput>, config?: Object.Optional<Config<TValue, TOutput>> & {
returnMany?: false;
}): SwichReturnOne<TValue, TOutput>;
export declare const gt: (compareValue: number) => (value: number) => boolean;
export declare const gte: (compareValue: number) => (value: number) => boolean;
export declare const lt: (compareValue: number) => (value: number) => boolean;
export declare const lte: (compareValue: number) => (value: number) => boolean;
declare const defaultSwich: <TValue, TOutput>(patterns: CaseElements<TValue, TOutput>, config?: {
returnMany?: boolean;
strict?: boolean;
acceptTruthyFunctionReturn?: boolean;
catchFunctionErrors?: boolean;
performReplaceOnRegex?: boolean;
runResultFunction?: boolean;
stopFallThrough?: boolean;
matcher?: Matcher<TValue, TOutput>;
resultGetter?: ResultGetter<TValue, TOutput>;
}) => (valueToMatch?: boolean | TValue) => TOutput[];
export default defaultSwich;
declare type CreateSwichReturnMany<TValue, TOutput> = <TValue, TOutput>(patterns: CaseElements<TValue, TOutput>, config?: Object.Optional<Config<TValue, TOutput>>) => SwichReturnMany<TValue, TOutput>;
declare type CreateSwichReturnOne<TValue, TOutput> = <TValue, TOutput>(patterns: CaseElements<TValue, TOutput>, config?: Object.Optional<Config<TValue, TOutput>>) => SwichReturnOne<TValue, TOutput>;
export declare function createSwich<TValue, TOutput>(defaultConfig: Object.Optional<Config<TValue, TOutput>> & {
returnMany: true;
}): CreateSwichReturnMany<TValue, TOutput>;
export declare function createSwich<TValue, TOutput>(defaultConfig: Object.Optional<Config<TValue, TOutput>> & {
returnMany?: false;
}): CreateSwichReturnOne<TValue, TOutput>;
export default swich;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "swich",
"version": "1.1.2",
"version": "1.2.0",
"description": "Switch, but better",
"main": "build/index.js",
"types": "build/types/index.d.ts",
Expand Down
Loading

0 comments on commit 7389702

Please sign in to comment.