Skip to content

Commit

Permalink
Add examples to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
rametta committed Oct 15, 2023
1 parent 88403ec commit 06164cd
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ Here is a list of all the available types to use for validation, and their assoc
- `.coerce()` calls `str_to_var()` before validation, useful if previously called `var_to_string()`
- `.nullable()` allows the field to be null or missing

Examples

```gdscript
# Coerce example
var schema = Z.integer().minimum(1).maximum(20).coerce()
schema.parse(var_to_str(5)).is_ok() # true
schema.parse(var_to_str(26)).is_ok() # false
# Nullable example
var schema = Z.integer().minimum(1).maximum(20).nullable()
schema.parse(5).is_ok() # true
schema.parse(null).is_ok() # true
schema.parse(26).is_ok() # false
```

### Z.string()

Parse [string](https://docs.godotengine.org/en/latest/classes/class_string.html#class-string) type.
Expand All @@ -66,6 +81,14 @@ Available extension constraints:
- `.minimum()` enforces a minimum length
- `.maximum()` enforces a maximum length

Example

```gdscript
var schema = Z.string().minimum(1).maximum(20)
schema.parse("hello").is_ok() # true
schema.parse("").is_ok() # false
```

### Z.integer()

Parse [integer](https://docs.godotengine.org/en/latest/classes/class_int.html#class-int) type.
Expand All @@ -74,3 +97,12 @@ Available extension constraints:

- `.minimum()` enforces a minimum value
- `.maximum()` enforces a maximum value

Example

```gdscript
var schema = Z.integer().minimum(1).maximum(20)
schema.parse(5).is_ok() # true
schema.parse(100).is_ok() # false
schema.parse(5.5).is_ok() # false - float is not an integer
```

0 comments on commit 06164cd

Please sign in to comment.