Skip to content

Commit

Permalink
@types/joi add dataUri type definition (DefinitelyTyped#28727)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWillG authored and RyanCavanaugh committed Sep 14, 2018
1 parent c472319 commit 5099333
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions types/joi/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// Rafael Kallis <https://github.com/rafaelkallis>
// Conan Lai <https://github.com/aconanlai>
// Peter Thorson <https://github.com/zaphoyd>
// Will Garcia <https://github.com/thewillg>
// Simon Schick <https://github.com/SimonSchick>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.4

Expand Down Expand Up @@ -147,6 +149,13 @@ export interface UriOptions {
relativeOnly?: boolean;
}

export interface DataUriOptions {
/**
* optional parameter defaulting to true which will require = padding if true or make padding optional if false
*/
paddingRequired?: boolean;
}

export interface Base64Options {
/**
* optional parameter defaulting to true which will require = padding if true or make padding optional if false
Expand Down Expand Up @@ -630,6 +639,11 @@ export interface StringSchema extends AnySchema {
*/
uri(options?: UriOptions): this;

/**
* Requires the string value to be a valid data URI string.
*/
dataUri(options?: DataUriOptions): this;

/**
* Requires the string value to be a valid GUID.
*/
Expand Down
8 changes: 8 additions & 0 deletions types/joi/joi-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ base64Opts = { paddingRequired: bool };

// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---

let dataUriOpts: Joi.DataUriOptions = null;

dataUriOpts = { paddingRequired: bool };

// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---

let whenOpts: Joi.WhenOptions = null;

whenOpts = { is: x };
Expand Down Expand Up @@ -818,6 +824,8 @@ strSchema = strSchema.normalize();
strSchema = strSchema.normalize('NFKC');
strSchema = strSchema.base64();
strSchema = strSchema.base64(base64Opts);
strSchema = strSchema.dataUri();
strSchema = strSchema.dataUri(dataUriOpts);

{ // common
strSchema = strSchema.allow(x);
Expand Down

0 comments on commit 5099333

Please sign in to comment.