Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@athenna/resource",
"version": "5.1.0",
"description": "📩 Add transformation layers between your application data transfer.",
"version": "5.2.0",
"description": "Add transformation layers between your application data transfer.",
"license": "MIT",
"author": "João Lenon <lenon@athenna.io>",
"bugs": "https://github.com/AthennaIO/Resource/issues",
Expand Down
24 changes: 23 additions & 1 deletion src/resource/BaseResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export abstract class BaseResource<R = any, I = any> {
* with the `schema()` method. We always use array
* values to standardize iterations, maps, etc.
*/
private readonly items: I[]
// TODO Convert to symbol
private items: I[]

/**
* Indicates if the item received in the constructor
Expand Down Expand Up @@ -48,4 +49,25 @@ export abstract class BaseResource<R = any, I = any> {

return this.isArray ? transformed : transformed[0]
}

/**
* Change the value of an item inside your resource.
* If your resource is an array, all keys in the array will
* be changed.
*/
public setValue(key: string, value: any) {
if (this.isArray) {
this.items = this.items.map(item => {
item[key] = value

return item
})

return this
}

this.items[key] = value

return this
}
}
Loading