-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
➕ Added static methods
from
and fromArray
➕ Added configuration from function
- Loading branch information
1 parent
148a9a4
commit 779de21
Showing
40 changed files
with
288 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# Configuration Function | ||
|
||
--- | ||
|
||
## Configuration function with minimal parameters | ||
|
||
```js | ||
const serializer = new Vicis(function (model) { | ||
return { | ||
castToBoolean: model.property_01.boolean, | ||
castToFlag: model.property_02.flag, | ||
castToInteger: model.property_03.integer, | ||
castToNumeric: model.property_04.numeric, | ||
castToString: model.property_05.string, | ||
castToJSON: model.property_06.json, | ||
mustBeDefined: model.property_07.defined, | ||
mustBeWithValue: model.property_08.required, | ||
defaultValue: model.property_09.default("no value"), | ||
transformedValue: model.property_10.transform((value) => value++), | ||
valueToBeReplaced: model.property_11.replace("Override value"), | ||
justValue: "You can put here anything", | ||
}; | ||
}); | ||
|
||
serializer.data(modelFromDatabase).toJSON(); | ||
``` | ||
|
||
```json | ||
{ | ||
"castToBoolean": true, | ||
"castToFlag": false, | ||
"castToInteger": 12345, | ||
"castToNumeric": 123.456, | ||
"castToString": "Title", | ||
"castToJSON": { "a": 1 }, | ||
"mustBeDefined": "I'm defined", | ||
"mustBeWithValue": "Has value", | ||
"defaultValue": "no value", | ||
"transformedValue": 2, | ||
"justValue": "You can put here anything" | ||
} | ||
``` | ||
|
||
--- | ||
|
||
## Chained example | ||
|
||
```js | ||
const serializer = new Vicis(function (model) { | ||
return { | ||
id: model.id.required.integer, | ||
title: model.title.defined.string, | ||
active: true, | ||
rating: model.rating.numeric, | ||
tested: model.tested.default(false), | ||
}; | ||
}); | ||
|
||
const modelFromDatabase = { | ||
id: "12345", | ||
title: "", | ||
active: "maybe", | ||
rating: "3.5", | ||
tested: undefined, | ||
}; | ||
|
||
serializer.data(modelFromDatabase).toJSON(); | ||
``` | ||
|
||
```json | ||
{ | ||
"id": 12345, | ||
"title": "", | ||
"active": true, | ||
"rating": 3.5, | ||
"tested": false | ||
} | ||
``` | ||
|
||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# Конфигурация Функцией | ||
|
||
--- | ||
|
||
## Конфигурация функцией с минимальными параметрами | ||
|
||
```js | ||
const serializer = new Vicis(function (model) { | ||
return { | ||
castToBoolean: model.property_01.boolean, | ||
castToFlag: model.property_02.flag, | ||
castToInteger: model.property_03.integer, | ||
castToNumeric: model.property_04.numeric, | ||
castToString: model.property_05.string, | ||
castToJSON: model.property_06.json, | ||
mustBeDefined: model.property_07.defined, | ||
mustBeWithValue: model.property_08.required, | ||
defaultValue: model.property_09.default("no value"), | ||
transformedValue: model.property_10.transform((value) => value++), | ||
valueToBeReplaced: model.property_11.replace("Override value"), | ||
justValue: "You can put here anything", | ||
}; | ||
}); | ||
|
||
serializer.data(modelFromDatabase).toJSON(); | ||
``` | ||
|
||
```json | ||
{ | ||
"castToBoolean": true, | ||
"castToFlag": false, | ||
"castToInteger": 12345, | ||
"castToNumeric": 123.456, | ||
"castToString": "Title", | ||
"castToJSON": { "a": 1 }, | ||
"mustBeDefined": "I'm defined", | ||
"mustBeWithValue": "Has value", | ||
"defaultValue": "no value", | ||
"transformedValue": 2, | ||
"justValue": "You can put here anything" | ||
} | ||
``` | ||
|
||
--- | ||
|
||
## Пример вызовов цепочкой | ||
|
||
```js | ||
const serializer = new Vicis(function (model) { | ||
return { | ||
id: model.id.required.integer, | ||
title: model.title.defined.string, | ||
active: true, | ||
rating: model.rating.numeric, | ||
tested: model.tested.default(false), | ||
}; | ||
}); | ||
|
||
const modelFromDatabase = { | ||
id: "12345", | ||
title: "", | ||
active: "maybe", | ||
rating: "3.5", | ||
tested: undefined, | ||
}; | ||
|
||
serializer.data(modelFromDatabase).toJSON(); | ||
``` | ||
|
||
```json | ||
{ | ||
"id": 12345, | ||
"title": "", | ||
"active": true, | ||
"rating": 3.5, | ||
"tested": false | ||
} | ||
``` | ||
|
||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Конфигурация | ||
# Конфигурация Объектом | ||
|
||
--- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.