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
feat: new string validations #26
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 |
---|---|---|
|
@@ -124,6 +124,54 @@ describe("#isIn()", function() { | |
}); | ||
}); | ||
|
||
describe("#isUpper()", function() { | ||
it("should verify basic is simple conditions", () => { | ||
let result; | ||
|
||
result = yonius.isUpper()("HELLO"); | ||
assert.strictEqual(result, true); | ||
|
||
result = yonius.isUpper()("HELLO.WORLD"); | ||
assert.strictEqual(result, true); | ||
|
||
result = yonius.isUpper()(null); | ||
assert.strictEqual(result, true); | ||
|
||
assert.throws( | ||
() => yonius.isUpper()("illegal!"), | ||
err => { | ||
assert.strictEqual(err instanceof yonius.ValidationError, true); | ||
assert.strictEqual(err.message, "Value contains lower cased characters"); | ||
return true; | ||
} | ||
); | ||
}); | ||
}); | ||
|
||
describe("#isLower()", function() { | ||
it("should verify basic is simple conditions", () => { | ||
let result; | ||
|
||
result = yonius.isLower()("hello"); | ||
assert.strictEqual(result, true); | ||
|
||
result = yonius.isLower()("hello.hello"); | ||
assert.strictEqual(result, true); | ||
|
||
result = yonius.isLower()(null); | ||
assert.strictEqual(result, true); | ||
|
||
assert.throws( | ||
() => yonius.isLower()("ILLEGAL!"), | ||
err => { | ||
assert.strictEqual(err instanceof yonius.ValidationError, true); | ||
assert.strictEqual(err.message, "Value contains upper cased characters"); | ||
return true; | ||
} | ||
); | ||
}); | ||
}); | ||
|
||
describe("#isSimple()", function() { | ||
it("should verify basic is simple conditions", () => { | ||
let result; | ||
|
@@ -213,3 +261,72 @@ describe("#isRegex()", function() { | |
); | ||
}); | ||
}); | ||
|
||
describe("#stringGt()", function() { | ||
it("should verify basic greater than operations", () => { | ||
let result; | ||
|
||
result = yonius.stringGt(2)("hel"); | ||
assert.strictEqual(result, true); | ||
|
||
result = yonius.stringGt(4)("hello"); | ||
assert.strictEqual(result, true); | ||
|
||
result = yonius.stringGt(4)(null); | ||
assert.strictEqual(result, true); | ||
|
||
assert.throws( | ||
() => yonius.stringGt(4)("hell"), | ||
err => { | ||
assert.strictEqual(err instanceof yonius.ValidationError, true); | ||
assert.strictEqual(err.message, "Must be larger than 4 characters"); | ||
return true; | ||
} | ||
); | ||
}); | ||
}); | ||
|
||
describe("#stringLt()", function() { | ||
it("should verify basic greater than operations", () => { | ||
let result; | ||
|
||
result = yonius.stringLt(2)("h"); | ||
assert.strictEqual(result, true); | ||
|
||
result = yonius.stringLt(4)("hel"); | ||
assert.strictEqual(result, true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
|
||
result = yonius.stringLt(4)(null); | ||
assert.strictEqual(result, true); | ||
|
||
assert.throws( | ||
() => yonius.stringLt(4)("hell"), | ||
err => { | ||
assert.strictEqual(err instanceof yonius.ValidationError, true); | ||
assert.strictEqual(err.message, "Must be smaller than 4 characters"); | ||
return true; | ||
} | ||
); | ||
}); | ||
}); | ||
|
||
describe("#stringEq()", function() { | ||
it("should verify basic greater than operations", () => { | ||
let result; | ||
|
||
result = yonius.stringEq(2)("he"); | ||
assert.strictEqual(result, true); | ||
|
||
result = yonius.stringEq(4)(null); | ||
assert.strictEqual(result, true); | ||
|
||
assert.throws( | ||
() => yonius.stringEq(4)("hel"), | ||
err => { | ||
assert.strictEqual(err instanceof yonius.ValidationError, true); | ||
assert.strictEqual(err.message, "Must be exactly 4 characters"); | ||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export declare function register(name: string, value: any): void; | ||
export declare function register(name: string, value: unknown): void; | ||
export declare function unregister(name: string): void; | ||
export declare function request(name: string): any; | ||
export declare function request(name: string): unknown; |
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 +1 @@ | ||
export declare function verify(condition: boolean, message?: string, code?: number, exception?: any, kwargs?: any): void; | ||
export declare function verify(condition: boolean, message?: string, code?: number, exception?: unknown, kwargs?: unknown): void; |
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,2 +1,2 @@ | ||
export declare function load(names?: Array<string>, path?: string, encoding?: string, force?: boolean, ctx?: any): Promise<void>; | ||
export declare function conf(name: string, fallback?: any, cast?: string, ctx?: any): any; | ||
export declare function load(names?: Array<string>, path?: string, encoding?: string, force?: boolean, ctx?: unknown): Promise<void>; | ||
export declare function conf(name: string, fallback?: unknown, cast?: string, ctx?: unknown): unknown; |
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,9 +1,9 @@ | ||
export declare function getObject( | ||
params: Record<string, any>, | ||
params: Record<string, unknown>, | ||
options: { | ||
alias?: boolean, | ||
page?: boolean, | ||
find?: boolean, | ||
norm?: boolean | ||
} | ||
): Record<string, any>; | ||
): Record<string, unknown>; |
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,40 +1,63 @@ | ||
export declare function eq<T>( | ||
valueC: T, | ||
message?: string | ||
): (value?: T, ctx?: any) => boolean; | ||
): (value?: T, ctx?: unknown) => boolean; | ||
|
||
export declare function gt<T>( | ||
valueC: T, | ||
message?: string | ||
): (value?: T, ctx?: any) => boolean; | ||
): (value?: T, ctx?: unknown) => boolean; | ||
|
||
export declare function gte<T>( | ||
valueC: T, | ||
message?: string | ||
): (value?: T, ctx?: any) => boolean; | ||
): (value?: T, ctx?: unknown) => boolean; | ||
|
||
export declare function notEmpty( | ||
message?: string | ||
): (value?: string | unknown[], ctx?: any) => boolean; | ||
): (value?: string | unknown[], ctx?: unknown) => boolean; | ||
|
||
export declare function isIn<T>( | ||
valueC: T[], | ||
message?: string | ||
): (value?: T, ctx?: any) => boolean; | ||
): (value?: T, ctx?: unknown) => boolean; | ||
|
||
export declare function isUpper( | ||
message?: string | ||
): (value?: string, ctx?: unknown) => boolean; | ||
|
||
export declare function isLower( | ||
message?: string | ||
): (value?: string, ctx?: unknown) => boolean; | ||
|
||
export declare function isSimple( | ||
message?: string | ||
): (value?: string, ctx?: any) => boolean; | ||
): (value?: string, ctx?: unknown) => boolean; | ||
|
||
export declare function isEmail( | ||
message?: string | ||
): (value?: string, ctx?: any) => boolean; | ||
): (value?: string, ctx?: unknown) => boolean; | ||
|
||
export declare function isUrl( | ||
message?: string | ||
): (value?: string, ctx?: any) => boolean; | ||
): (value?: string, ctx?: unknown) => boolean; | ||
|
||
export declare function isRegex( | ||
regex: string, | ||
message?: string | ||
): (value?: string, ctx?: any) => boolean; | ||
): (value?: string, ctx?: unknown) => boolean; | ||
|
||
export declare function stringGt( | ||
valueC: number, | ||
message?: string | ||
): (value?: string, ctx?: unknown) => boolean; | ||
|
||
export declare function stringLt( | ||
valueC: number, | ||
message?: string | ||
): (value?: string, ctx?: unknown) => boolean; | ||
|
||
export declare function stringEq( | ||
valueC: number, | ||
message?: string | ||
): (value?: string, ctx?: unknown) => boolean; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please keep using the typical hello and hello world string "HELLO" example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taken from
yonius/test/util/validation.js
Line 141 in 35e9dcb