-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from MrAntix/main
feat(parse): allow negate on types
- Loading branch information
Showing
55 changed files
with
700 additions
and
276 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Is } from './Is'; | ||
|
||
describe('Is', () => { | ||
|
||
it('throws when construtcor is called', () => { | ||
|
||
expect(() => new ( | ||
Is as unknown as any // eslint-disable-line @typescript-eslint/no-explicit-any | ||
)()).toThrow(); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,37 @@ | ||
import { isNullOrEmpty } from '../predicates'; | ||
import { ArrayParser, IArray } from './arrays'; | ||
import { DictionaryParser, IDictionary } from './dictionaries'; | ||
import { BooleanParser, IBoolean } from './booleans'; | ||
import { createParseResult } from './createParseResult'; | ||
import { DateParser, IDate } from './dates'; | ||
import { ArrayParser, IArray, provideParseArray } from './arrays'; | ||
import { DictionaryParser, IDictionary, provideParseDictionary } from './dictionaries'; | ||
import { BooleanParser, IBoolean, provideParseBoolean } from './booleans'; | ||
import { DateParser, IDate, provideParseDate } from './dates'; | ||
import { IParser } from './IParser'; | ||
import { IRoot } from './IRoot'; | ||
import { FloatParser, IFloat, IInt, IntParser } from './numbers'; | ||
import { FloatParser, IFloat, IInt, IntParser, provideParseFloat, provideParseInt } from './numbers'; | ||
import { ComplexParser, ComplexSchema, IComplex } from './complex'; | ||
import { parseChain } from './parseChain'; | ||
import { ParseErrors } from './ParseErrors'; | ||
import { IString, StringParser } from './strings'; | ||
import { IJson, JsonParser } from './json'; | ||
import { IString, StringParser, provideParseString } from './strings'; | ||
import { IJson, JsonParser, provideParseJson } from './json'; | ||
import { provideParseRoot } from './provideParseRoot'; | ||
|
||
export class RootParser implements IRoot.Parser { | ||
constructor( | ||
private isRequried = false | ||
private isRequried = false, | ||
private negate = false | ||
) { } | ||
|
||
readonly parse = parseChain(null, value => | ||
this.isRequried && isNullOrEmpty(value) | ||
? createParseResult(value, ParseErrors.required) | ||
: createParseResult(value)); | ||
readonly parse = parseChain(null, provideParseRoot(this.isRequried)); | ||
|
||
readonly boolean: IBoolean.Parser = new BooleanParser(this); | ||
readonly int: IInt.Parser = new IntParser(this); | ||
readonly float: IFloat.Parser = new FloatParser(this); | ||
readonly date: IDate.Parser = new DateParser(this); | ||
readonly string: IString.Parser = new StringParser(this); | ||
readonly array: IArray.Parser = new ArrayParser(this); | ||
readonly dictionary: IDictionary.Parser = new DictionaryParser(this); | ||
readonly json: IJson.Parser = new JsonParser(this); | ||
readonly boolean: IBoolean.Parser = new BooleanParser(this, provideParseBoolean(this.negate)); | ||
readonly int: IInt.Parser = new IntParser(this, provideParseInt(this.negate)); | ||
readonly float: IFloat.Parser = new FloatParser(this, provideParseFloat(this.negate)); | ||
readonly date: IDate.Parser = new DateParser(this, provideParseDate(this.negate)); | ||
readonly string: IString.Parser = new StringParser(this, provideParseString(this.negate)); | ||
readonly array: IArray.Parser = new ArrayParser(this, provideParseArray(this.negate)); | ||
readonly dictionary: IDictionary.Parser = new DictionaryParser(this, provideParseDictionary(this.negate)); | ||
readonly json: IJson.Parser = new JsonParser(this, provideParseJson(this.negate)); | ||
|
||
readonly for = <T>(schema: ComplexSchema<T>): IComplex.Parser<T> => new ComplexParser(this, schema); | ||
readonly use = <T>(parser: IParser<T>) => ({ parse: parseChain<T>(this, parser.parse) }); | ||
|
||
get not() { | ||
return new RootParser(this.isRequried, true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.