Skip to content

Commit

Permalink
[ops] Bump package version to 12.22.0 and update changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
peterver committed Sep 7, 2024
1 parent 46a8a59 commit e9ee6a5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
42 changes: 41 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ isFormData(new FormData()); // TRUE
isFormData({hi: 'there'}); // FALSE
```

### formdata/toObject(val:FormData)
### formdata/toObject(val:FormData, {raw?:string[]} = {})
Converts an instance of FormData to an object
```typescript
import toObject from '@valkyriestudios/utils/formdata/toObject';
Expand All @@ -800,6 +800,46 @@ form.append('emptyField', '');
toObject(form); // {name: 'Alice', hobbies: ['reading', 'writing'], emptyField: ''}
```

Automatically converts strings to numbers and booleans, and nests objects/arrays based on key structures:
```typescript
const form = new FormData();
form.append('user[0].name', 'Alice');
form.append('user[1].age', '25');
form.append('enabled', 'false');
form.append('config.isGood', 'true');
form.append('config.amount', ' 50 ');
toObject(form); /* {
user: [
{name: 'Alice'},
{age: 25},
],
enabled: false,
config: {
isGood: true,
amount: 50,
},
} */
```

Allows blacklisting keys that should not be normalized into numbers/booleans but should remain as they are:
```typescript
const form = new FormData();
form.append('pincode', '0123');
form.append('enabled', 'false');
form.append('config.isGood', 'true');
form.append('config.amount', ' 50 ');
toObject(form, {raw: ['pincode']}); /* {
pincode: '0123',
enabled: false,
config: {
isGood: true,
amount: 50,
},
} */
```

### hash/guid()
Generate a unique identifier (guid) according to RFC4122
```typescript
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@valkyriestudios/utils",
"version": "12.21.0",
"version": "12.22.0",
"description": "A collection of single-function utilities for common tasks",
"author": {
"name": "Peter Vermeulen",
Expand Down

0 comments on commit e9ee6a5

Please sign in to comment.