Skip to content

Commit 2d7156d

Browse files
committed
add boolItem to README
1 parent 350f35d commit 2d7156d

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

README.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -522,11 +522,26 @@ DeriveType<typeof dateArrayPacketLayout>["payload"];
522522
//=> Set<number>
523523
```
524524

525+
### Bool Item
526+
527+
Converts a boolean into a single byte.
528+
529+
Implemented via a *uint* item. Strict by default, i.e. only accepts 1 and 0 as the valid values, but can be set to be permissive so any non-zero value counts as true.
530+
531+
```typescript
532+
const strictBool = boolItem();
533+
const permissiveBool = boolItem(true);
534+
deserialize(strictBool, new Uint8Array([2]));
535+
//=> throws
536+
deserialize(permissiveBool, new Uint8Array([2]));
537+
//=> true
538+
```
539+
525540
### Enum Item
526541

527542
Converts a set of string values into their associated numeric values.
528543

529-
Implement via a *uint* item. Default size is 1, default endianness is big.
544+
Implemented via a *uint* item. Default size is 1, default endianness is big.
530545

531546
```typescript
532547
const myEnumItem = enumItem([["foo", 1], ["bar", 3]], { size: 2, endianness: "little" });

0 commit comments

Comments
 (0)