diff --git a/README.md b/README.md index 78e78c9..4d27f2b 100644 --- a/README.md +++ b/README.md @@ -175,6 +175,6 @@ const TNumberBiggerThan10 = TValidate( All guards can be imported as a single module, which enables tree-shaking: ```ts -import TString from "tguard/guards/TString"; -import { GuardedType } from "tguard/Guard"; +import TString from "tguard/lib/guards/TString"; +import Guard, { GuardedType } from "tguard/lib/Guard"; ``` diff --git a/docs/README.md b/docs/README.md index ec55f6e..417ed4f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -177,6 +177,6 @@ const TNumberBiggerThan10 = TValidate( All guards can be imported as a single module, which enables tree-shaking: ```ts -import TString from "tguard/guards/TString"; -import { GuardedType } from "tguard/Guard"; +import TString from "tguard/lib/guards/TString"; +import Guard, { GuardedType } from "tguard/lib/Guard"; ``` diff --git a/docs/classes/Guard.md b/docs/classes/Guard.md index 055e788..bb05f47 100644 --- a/docs/classes/Guard.md +++ b/docs/classes/Guard.md @@ -47,7 +47,7 @@ An abstract class, which is the parent class of all Guards. (Names starting with #### Defined in -[src/Guard.ts:11](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/Guard.ts#L11) +[src/Guard.ts:11](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/Guard.ts#L11) ## Methods @@ -67,7 +67,7 @@ An abstract class, which is the parent class of all Guards. (Names starting with #### Defined in -[src/Guard.ts:13](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/Guard.ts#L13) +[src/Guard.ts:13](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/Guard.ts#L13) ___ @@ -87,4 +87,4 @@ value is T #### Defined in -[src/Guard.ts:12](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/Guard.ts#L12) +[src/Guard.ts:12](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/Guard.ts#L12) diff --git a/docs/classes/ValidationError.md b/docs/classes/ValidationError.md index f0e6ad0..699e480 100644 --- a/docs/classes/ValidationError.md +++ b/docs/classes/ValidationError.md @@ -48,7 +48,7 @@ Error.constructor #### Defined in -[src/errors.ts:5](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/errors.ts#L5) +[src/errors.ts:5](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/errors.ts#L5) ## Properties @@ -58,7 +58,7 @@ Error.constructor #### Defined in -[src/errors.ts:3](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/errors.ts#L3) +[src/errors.ts:3](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/errors.ts#L3) ___ @@ -96,7 +96,7 @@ ___ #### Defined in -[src/errors.ts:2](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/errors.ts#L2) +[src/errors.ts:2](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/errors.ts#L2) ___ diff --git a/docs/modules.md b/docs/modules.md index 275d174..df7c27e 100644 --- a/docs/modules.md +++ b/docs/modules.md @@ -29,6 +29,7 @@ - [TString](modules.md#tstring) - [TStringEmail](modules.md#tstringemail) - [TStringISODate](modules.md#tstringisodate) +- [TStringJSON](modules.md#tstringjson) - [TStringJWT](modules.md#tstringjwt) - [TStringMIMEType](modules.md#tstringmimetype) - [TStringPhoneNumber](modules.md#tstringphonenumber) @@ -67,7 +68,7 @@ Infers the type, that the given `Guard` guards. #### Defined in -[src/Guard.ts:22](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/Guard.ts#L22) +[src/Guard.ts:22](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/Guard.ts#L22) ___ @@ -85,7 +86,7 @@ Infers the type, that the given `Schema` represents. #### Defined in -[src/guards/TObject/types.ts:8](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/guards/TObject/types.ts#L8) +[src/guards/TObject/types.ts:8](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/guards/TObject/types.ts#L8) ## Variables @@ -99,7 +100,7 @@ Guard that accepts any value. #### Defined in -[src/guards/TAny/index.ts:8](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/guards/TAny/index.ts#L8) +[src/guards/TAny/index.ts:8](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/guards/TAny/index.ts#L8) ___ @@ -114,7 +115,7 @@ Does not accept null. #### Defined in -[src/guards/TAnyObject/index.ts:9](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/guards/TAnyObject/index.ts#L9) +[src/guards/TAnyObject/index.ts:9](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/guards/TAnyObject/index.ts#L9) ___ @@ -128,7 +129,7 @@ Primitive guard that only accepts `bigint` values. #### Defined in -[src/guards/TBigInt/index.ts:8](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/guards/TBigInt/index.ts#L8) +[src/guards/TBigInt/index.ts:8](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/guards/TBigInt/index.ts#L8) ___ @@ -142,7 +143,7 @@ Primitive guard that only accepts `boolean` values. #### Defined in -[src/guards/TBoolean/index.ts:8](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/guards/TBoolean/index.ts#L8) +[src/guards/TBoolean/index.ts:8](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/guards/TBoolean/index.ts#L8) ___ @@ -156,7 +157,7 @@ Primitive guard that only accepts `function` values. #### Defined in -[src/guards/TFunction/index.ts:8](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/guards/TFunction/index.ts#L8) +[src/guards/TFunction/index.ts:8](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/guards/TFunction/index.ts#L8) ___ @@ -177,7 +178,7 @@ TInteger.isValid(15); // true #### Defined in -[src/guards/TInteger/index.ts:15](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/guards/TInteger/index.ts#L15) +[src/guards/TInteger/index.ts:15](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/guards/TInteger/index.ts#L15) ___ @@ -198,7 +199,7 @@ TIntegerAsString.isValid("15"); // true #### Defined in -[src/guards/TIntegerAsString/index.ts:16](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/guards/TIntegerAsString/index.ts#L16) +[src/guards/TIntegerAsString/index.ts:16](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/guards/TIntegerAsString/index.ts#L16) ___ @@ -212,7 +213,7 @@ Guard that only accepts `null`. #### Defined in -[src/guards/TNull/index.ts:8](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/guards/TNull/index.ts#L8) +[src/guards/TNull/index.ts:8](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/guards/TNull/index.ts#L8) ___ @@ -227,7 +228,7 @@ Not accepts `NaN`. #### Defined in -[src/guards/TNumber/index.ts:9](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/guards/TNumber/index.ts#L9) +[src/guards/TNumber/index.ts:9](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/guards/TNumber/index.ts#L9) ___ @@ -248,7 +249,7 @@ TNumberAsString.isValid("15.223"); // true #### Defined in -[src/guards/TNumberAsString/index.ts:15](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/guards/TNumberAsString/index.ts#L15) +[src/guards/TNumberAsString/index.ts:15](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/guards/TNumberAsString/index.ts#L15) ___ @@ -262,7 +263,7 @@ Primitive guard that only accepts `string` values. #### Defined in -[src/guards/TString/index.ts:8](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/guards/TString/index.ts#L8) +[src/guards/TString/index.ts:8](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/guards/TString/index.ts#L8) ___ @@ -283,7 +284,7 @@ TStringEmail.name === "string(email)"; // true #### Defined in -[src/guards/TStringEmail/index.ts:16](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/guards/TStringEmail/index.ts#L16) +[src/guards/TStringEmail/index.ts:16](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/guards/TStringEmail/index.ts#L16) ___ @@ -304,7 +305,28 @@ TStringISODate.name === "string(date)"; // true #### Defined in -[src/guards/TStringISODate/index.ts:16](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/guards/TStringISODate/index.ts#L16) +[src/guards/TStringISODate/index.ts:16](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/guards/TStringISODate/index.ts#L16) + +___ + +### TStringJSON + +• `Const` **TStringJSON**: [`Guard`](classes/Guard.md)<`string`\> + +A `Guard` which validates if a string is a valid JSON. + +`guard.name: "string(JSON)"` + +**`example`** +```ts +TStringJSON.isValid("1234"); // false +TStringJSON.isValid("{\"foo\": 2}"); // true +TStringJSON.name === "string(JSON)"; // true +``` + +#### Defined in + +[src/guards/TStringJSON/index.ts:16](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/guards/TStringJSON/index.ts#L16) ___ @@ -325,7 +347,7 @@ TStringJWT.name === "string(JSON)"; // true #### Defined in -[src/guards/TStringJWT/index.ts:16](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/guards/TStringJWT/index.ts#L16) +[src/guards/TStringJWT/index.ts:16](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/guards/TStringJWT/index.ts#L16) ___ @@ -346,7 +368,7 @@ TStringMIMEType.name === "string(MIME type)"; // true #### Defined in -[src/guards/TStringMIMEType/index.ts:16](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/guards/TStringMIMEType/index.ts#L16) +[src/guards/TStringMIMEType/index.ts:16](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/guards/TStringMIMEType/index.ts#L16) ___ @@ -368,7 +390,7 @@ TStringPhoneNumber.name === "string(phone number)"; // true #### Defined in -[src/guards/TStringPhoneNumber/index.ts:17](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/guards/TStringPhoneNumber/index.ts#L17) +[src/guards/TStringPhoneNumber/index.ts:17](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/guards/TStringPhoneNumber/index.ts#L17) ___ @@ -389,7 +411,7 @@ TStringSemVer.name === "string(SemVer)"; // true #### Defined in -[src/guards/TStringSemVer/index.ts:16](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/guards/TStringSemVer/index.ts#L16) +[src/guards/TStringSemVer/index.ts:16](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/guards/TStringSemVer/index.ts#L16) ___ @@ -410,7 +432,7 @@ TStringURL.name === "string(URL)"; // true #### Defined in -[src/guards/TStringURL/index.ts:16](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/guards/TStringURL/index.ts#L16) +[src/guards/TStringURL/index.ts:16](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/guards/TStringURL/index.ts#L16) ___ @@ -434,7 +456,7 @@ TStringUUID.name === "string(UUID)"; // true #### Defined in -[src/guards/TStringUUID/index.ts:19](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/guards/TStringUUID/index.ts#L19) +[src/guards/TStringUUID/index.ts:19](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/guards/TStringUUID/index.ts#L19) ___ @@ -448,7 +470,7 @@ Primitive guard that only accepts `undefined` values. #### Defined in -[src/guards/TUndefined/index.ts:8](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/guards/TUndefined/index.ts#L8) +[src/guards/TUndefined/index.ts:8](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/guards/TUndefined/index.ts#L8) ## Functions @@ -483,7 +505,7 @@ Accepts a value when it was accepted by both `guardA` and `guardB`. #### Defined in -[src/guards/TAnd/index.ts:14](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/guards/TAnd/index.ts#L14) +[src/guards/TAnd/index.ts:14](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/guards/TAnd/index.ts#L14) ___ @@ -526,7 +548,7 @@ A `Guard` that checks if the given value is an array of the given type. #### Defined in -[src/guards/TArray/index.ts:24](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/guards/TArray/index.ts#L24) +[src/guards/TArray/index.ts:24](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/guards/TArray/index.ts#L24) ___ @@ -569,7 +591,7 @@ A `Guard` which checks if the given value is equals to the `constant` literal. #### Defined in -[src/guards/TConstant/index.ts:26](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/guards/TConstant/index.ts#L26) +[src/guards/TConstant/index.ts:26](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/guards/TConstant/index.ts#L26) ___ @@ -608,7 +630,7 @@ A `Guard` that accepts a value when it was **not** accepted by the given guard. #### Defined in -[src/guards/TNot/index.ts:21](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/guards/TNot/index.ts#L21) +[src/guards/TNot/index.ts:21](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/guards/TNot/index.ts#L21) ___ @@ -656,7 +678,7 @@ A `Guard`. #### Defined in -[src/guards/TObject/index.ts:30](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/guards/TObject/index.ts#L30) +[src/guards/TObject/index.ts:30](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/guards/TObject/index.ts#L30) ___ @@ -714,7 +736,7 @@ Similar in concept as TypeScript's `{[keys: string]: number}` type annotations. #### Defined in -[src/guards/TObjectOfShape/index.ts:39](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/guards/TObjectOfShape/index.ts#L39) +[src/guards/TObjectOfShape/index.ts:39](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/guards/TObjectOfShape/index.ts#L39) ___ @@ -760,7 +782,7 @@ Accepts a value when it was accepted by at least one of the `guards`. #### Defined in -[src/guards/TOr/index.ts:22](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/guards/TOr/index.ts#L22) +[src/guards/TOr/index.ts:22](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/guards/TOr/index.ts#L22) ___ @@ -794,7 +816,7 @@ A `Guard` that accepts only strings that are base64 encoded. #### Defined in -[src/guards/TStringBase64/index.ts:21](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/guards/TStringBase64/index.ts#L21) +[src/guards/TStringBase64/index.ts:21](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/guards/TStringBase64/index.ts#L21) ___ @@ -829,7 +851,7 @@ A `Guard` that accepts only strings that matches the given `regexp`. #### Defined in -[src/guards/TStringMatch/index.ts:23](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/guards/TStringMatch/index.ts#L23) +[src/guards/TStringMatch/index.ts:23](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/guards/TStringMatch/index.ts#L23) ___ @@ -864,7 +886,7 @@ A `Guard` that accepts only strings, that is in the given length range. #### Defined in -[src/guards/TStringWithLength/index.ts:22](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/guards/TStringWithLength/index.ts#L22) +[src/guards/TStringWithLength/index.ts:22](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/guards/TStringWithLength/index.ts#L22) ___ @@ -902,4 +924,4 @@ const TBiggerThan10 = TValidate( #### Defined in -[src/guards/TValidate/index.ts:22](https://github.com/davidkarolyi/tguard/blob/d0ca035/src/guards/TValidate/index.ts#L22) +[src/guards/TValidate/index.ts:22](https://github.com/davidkarolyi/tguard/blob/0dd2269/src/guards/TValidate/index.ts#L22)