mirror of
https://github.com/tcgdex/javascript-sdk.git
synced 2025-08-03 02:51:59 +00:00
feat: Allow a user to filters elements on the API (#275)
This commit is contained in:
28
src/models/Model.ts
Normal file
28
src/models/Model.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { objectLoop } from '@dzeio/object-util'
|
||||
import type TCGdex from '../tcgdex'
|
||||
|
||||
export default abstract class Model {
|
||||
|
||||
public constructor(
|
||||
protected readonly sdk: TCGdex
|
||||
) { }
|
||||
|
||||
/**
|
||||
* build a model depending on the data given
|
||||
* @param model the model to build
|
||||
* @param data the data to fill it with
|
||||
*/
|
||||
public static build<T extends Model>(model: T, data?: object): T {
|
||||
if (!data) {
|
||||
throw new Error('data is necessary.')
|
||||
}
|
||||
model.fill(data)
|
||||
return model
|
||||
}
|
||||
|
||||
protected fill(obj: object) {
|
||||
objectLoop(obj, (value, key) => {
|
||||
(this as object)[key] = value
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user