Skip to content

Commit

Permalink
refactor: simplify types creation
Browse files Browse the repository at this point in the history
  • Loading branch information
StyleShit committed Aug 18, 2024
1 parent 23308e2 commit 777d6f6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/stupid-gorillas-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'bodek': patch
---

Refactor types creation
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { StringSchema } from './schemas/string';
import { ObjectSchema } from './schemas/object';

export const b = {
string: () => new StringSchema(),
number: () => new NumberSchema(),
string: StringSchema.make,
number: NumberSchema.make,
object: ObjectSchema.make,
};

Expand Down
4 changes: 4 additions & 0 deletions src/schemas/number.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Schema } from './schema';

export class NumberSchema extends Schema<number> {
static make(this: void) {
return new NumberSchema();
}

_parse(value: unknown, message?: string) {
const defaultMessage = `${String(value)} is not a number`;

Expand Down
4 changes: 4 additions & 0 deletions src/schemas/string.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Schema } from './schema';

export class StringSchema extends Schema<string> {
static make(this: void) {
return new StringSchema();
}

_parse(value: unknown, message?: string) {
const defaultMessage = `${String(value)} is not a string`;

Expand Down

0 comments on commit 777d6f6

Please sign in to comment.