From 779de212a9b5676d533947515e91b9bfbfa84638 Mon Sep 17 00:00:00 2001 From: Anton Trofimenko Date: Sat, 4 Apr 2020 00:08:19 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9E=95=20Added=20static=20methods=20`from`?= =?UTF-8?q?=20and=20`fromArray`=20=E2=9E=95=20Added=20configuration=20from?= =?UTF-8?q?=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/_sidebar.md | 3 +- docs/en/_sidebar.md | 3 +- docs/en/changelog.md | 4 +- docs/en/configuration_function.md | 80 ++++++++++++++++++ ...nfiguration.md => configuration_object.md} | 4 +- docs/{ => icons}/android-icon-144x144.png | Bin docs/{ => icons}/android-icon-192x192.png | Bin docs/{ => icons}/android-icon-36x36.png | Bin docs/{ => icons}/android-icon-48x48.png | Bin docs/{ => icons}/android-icon-72x72.png | Bin docs/{ => icons}/android-icon-96x96.png | Bin docs/{ => icons}/apple-icon-114x114.png | Bin docs/{ => icons}/apple-icon-120x120.png | Bin docs/{ => icons}/apple-icon-144x144.png | Bin docs/{ => icons}/apple-icon-152x152.png | Bin docs/{ => icons}/apple-icon-180x180.png | Bin docs/{ => icons}/apple-icon-57x57.png | Bin docs/{ => icons}/apple-icon-60x60.png | Bin docs/{ => icons}/apple-icon-72x72.png | Bin docs/{ => icons}/apple-icon-76x76.png | Bin docs/{ => icons}/apple-icon-precomposed.png | Bin docs/{ => icons}/apple-icon.png | Bin docs/{ => icons}/favicon-16x16.png | Bin docs/{ => icons}/favicon-32x32.png | Bin docs/{ => icons}/favicon-96x96.png | Bin docs/{ => icons}/favicon.ico | Bin docs/{ => icons}/ms-icon-144x144.png | Bin docs/{ => icons}/ms-icon-150x150.png | Bin docs/{ => icons}/ms-icon-310x310.png | Bin docs/{ => icons}/ms-icon-70x70.png | Bin docs/index.html | 42 ++++----- docs/manifest.json | 14 +-- docs/ru/_sidebar.md | 3 +- docs/ru/changelog.md | 4 +- docs/ru/configuration_function.md | 80 ++++++++++++++++++ ...nfiguration.md => configuration_object.md} | 2 +- docs/ua/_sidebar.md | 3 +- docs/ua/changelog.md | 4 +- docs/ua/configuration_function.md | 80 ++++++++++++++++++ ...nfiguration.md => configuration_object.md} | 0 40 files changed, 288 insertions(+), 38 deletions(-) create mode 100644 docs/en/configuration_function.md rename docs/en/{configuration.md => configuration_object.md} (97%) rename docs/{ => icons}/android-icon-144x144.png (100%) rename docs/{ => icons}/android-icon-192x192.png (100%) rename docs/{ => icons}/android-icon-36x36.png (100%) rename docs/{ => icons}/android-icon-48x48.png (100%) rename docs/{ => icons}/android-icon-72x72.png (100%) rename docs/{ => icons}/android-icon-96x96.png (100%) rename docs/{ => icons}/apple-icon-114x114.png (100%) rename docs/{ => icons}/apple-icon-120x120.png (100%) rename docs/{ => icons}/apple-icon-144x144.png (100%) rename docs/{ => icons}/apple-icon-152x152.png (100%) rename docs/{ => icons}/apple-icon-180x180.png (100%) rename docs/{ => icons}/apple-icon-57x57.png (100%) rename docs/{ => icons}/apple-icon-60x60.png (100%) rename docs/{ => icons}/apple-icon-72x72.png (100%) rename docs/{ => icons}/apple-icon-76x76.png (100%) rename docs/{ => icons}/apple-icon-precomposed.png (100%) rename docs/{ => icons}/apple-icon.png (100%) rename docs/{ => icons}/favicon-16x16.png (100%) rename docs/{ => icons}/favicon-32x32.png (100%) rename docs/{ => icons}/favicon-96x96.png (100%) rename docs/{ => icons}/favicon.ico (100%) rename docs/{ => icons}/ms-icon-144x144.png (100%) rename docs/{ => icons}/ms-icon-150x150.png (100%) rename docs/{ => icons}/ms-icon-310x310.png (100%) rename docs/{ => icons}/ms-icon-70x70.png (100%) create mode 100644 docs/ru/configuration_function.md rename docs/ru/{configuration.md => configuration_object.md} (98%) create mode 100644 docs/ua/configuration_function.md rename docs/ua/{configuration.md => configuration_object.md} (100%) diff --git a/docs/_sidebar.md b/docs/_sidebar.md index 05750a1..a402b69 100644 --- a/docs/_sidebar.md +++ b/docs/_sidebar.md @@ -3,7 +3,8 @@ - [Importing](/en/importing.md) - [Creating Instance](/en/creating_instance.md) - API - - [Configuration](/en/configuration.md) + - [Configuration Object](/en/configuration_object.md) + - [Configuration Function](/en/configuration_function.md) - [Data Manipulation](/en/data_manipulation.md) - [Static Methods](/en/static_methods.md) - Functions diff --git a/docs/en/_sidebar.md b/docs/en/_sidebar.md index 05750a1..a402b69 100644 --- a/docs/en/_sidebar.md +++ b/docs/en/_sidebar.md @@ -3,7 +3,8 @@ - [Importing](/en/importing.md) - [Creating Instance](/en/creating_instance.md) - API - - [Configuration](/en/configuration.md) + - [Configuration Object](/en/configuration_object.md) + - [Configuration Function](/en/configuration_function.md) - [Data Manipulation](/en/data_manipulation.md) - [Static Methods](/en/static_methods.md) - Functions diff --git a/docs/en/changelog.md b/docs/en/changelog.md index 01932db..3808838 100644 --- a/docs/en/changelog.md +++ b/docs/en/changelog.md @@ -2,10 +2,12 @@ --- -## 1.4.0 Apr 03, 2020 +## 1.4.0 Apr 04, 2020 - ➕ Added static methods `from` and `fromArray` +- ➕ Added configuration from function + --- ## 1.3.12 Mar 30, 2020 diff --git a/docs/en/configuration_function.md b/docs/en/configuration_function.md new file mode 100644 index 0000000..becd142 --- /dev/null +++ b/docs/en/configuration_function.md @@ -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 +} +``` + +--- diff --git a/docs/en/configuration.md b/docs/en/configuration_object.md similarity index 97% rename from docs/en/configuration.md rename to docs/en/configuration_object.md index 289b46f..daad0ea 100644 --- a/docs/en/configuration.md +++ b/docs/en/configuration_object.md @@ -1,8 +1,8 @@ -# Configuration +# Configuration Object --- -## Configuration object +## Configuration object properties [Cast](/en/cast.md) [Defaults](/en/defaults.md) [Defined](/en/defined.md) [Exclude](/en/exclude.md) [Omit](/en/omit.md) [Order](/en/order.md) [Pick](/en/pick.md) [Rename](/en/rename.md) [Replace](/en/replace.md) [Required](/en/required.md) [Transform](/en/transform.md) diff --git a/docs/android-icon-144x144.png b/docs/icons/android-icon-144x144.png similarity index 100% rename from docs/android-icon-144x144.png rename to docs/icons/android-icon-144x144.png diff --git a/docs/android-icon-192x192.png b/docs/icons/android-icon-192x192.png similarity index 100% rename from docs/android-icon-192x192.png rename to docs/icons/android-icon-192x192.png diff --git a/docs/android-icon-36x36.png b/docs/icons/android-icon-36x36.png similarity index 100% rename from docs/android-icon-36x36.png rename to docs/icons/android-icon-36x36.png diff --git a/docs/android-icon-48x48.png b/docs/icons/android-icon-48x48.png similarity index 100% rename from docs/android-icon-48x48.png rename to docs/icons/android-icon-48x48.png diff --git a/docs/android-icon-72x72.png b/docs/icons/android-icon-72x72.png similarity index 100% rename from docs/android-icon-72x72.png rename to docs/icons/android-icon-72x72.png diff --git a/docs/android-icon-96x96.png b/docs/icons/android-icon-96x96.png similarity index 100% rename from docs/android-icon-96x96.png rename to docs/icons/android-icon-96x96.png diff --git a/docs/apple-icon-114x114.png b/docs/icons/apple-icon-114x114.png similarity index 100% rename from docs/apple-icon-114x114.png rename to docs/icons/apple-icon-114x114.png diff --git a/docs/apple-icon-120x120.png b/docs/icons/apple-icon-120x120.png similarity index 100% rename from docs/apple-icon-120x120.png rename to docs/icons/apple-icon-120x120.png diff --git a/docs/apple-icon-144x144.png b/docs/icons/apple-icon-144x144.png similarity index 100% rename from docs/apple-icon-144x144.png rename to docs/icons/apple-icon-144x144.png diff --git a/docs/apple-icon-152x152.png b/docs/icons/apple-icon-152x152.png similarity index 100% rename from docs/apple-icon-152x152.png rename to docs/icons/apple-icon-152x152.png diff --git a/docs/apple-icon-180x180.png b/docs/icons/apple-icon-180x180.png similarity index 100% rename from docs/apple-icon-180x180.png rename to docs/icons/apple-icon-180x180.png diff --git a/docs/apple-icon-57x57.png b/docs/icons/apple-icon-57x57.png similarity index 100% rename from docs/apple-icon-57x57.png rename to docs/icons/apple-icon-57x57.png diff --git a/docs/apple-icon-60x60.png b/docs/icons/apple-icon-60x60.png similarity index 100% rename from docs/apple-icon-60x60.png rename to docs/icons/apple-icon-60x60.png diff --git a/docs/apple-icon-72x72.png b/docs/icons/apple-icon-72x72.png similarity index 100% rename from docs/apple-icon-72x72.png rename to docs/icons/apple-icon-72x72.png diff --git a/docs/apple-icon-76x76.png b/docs/icons/apple-icon-76x76.png similarity index 100% rename from docs/apple-icon-76x76.png rename to docs/icons/apple-icon-76x76.png diff --git a/docs/apple-icon-precomposed.png b/docs/icons/apple-icon-precomposed.png similarity index 100% rename from docs/apple-icon-precomposed.png rename to docs/icons/apple-icon-precomposed.png diff --git a/docs/apple-icon.png b/docs/icons/apple-icon.png similarity index 100% rename from docs/apple-icon.png rename to docs/icons/apple-icon.png diff --git a/docs/favicon-16x16.png b/docs/icons/favicon-16x16.png similarity index 100% rename from docs/favicon-16x16.png rename to docs/icons/favicon-16x16.png diff --git a/docs/favicon-32x32.png b/docs/icons/favicon-32x32.png similarity index 100% rename from docs/favicon-32x32.png rename to docs/icons/favicon-32x32.png diff --git a/docs/favicon-96x96.png b/docs/icons/favicon-96x96.png similarity index 100% rename from docs/favicon-96x96.png rename to docs/icons/favicon-96x96.png diff --git a/docs/favicon.ico b/docs/icons/favicon.ico similarity index 100% rename from docs/favicon.ico rename to docs/icons/favicon.ico diff --git a/docs/ms-icon-144x144.png b/docs/icons/ms-icon-144x144.png similarity index 100% rename from docs/ms-icon-144x144.png rename to docs/icons/ms-icon-144x144.png diff --git a/docs/ms-icon-150x150.png b/docs/icons/ms-icon-150x150.png similarity index 100% rename from docs/ms-icon-150x150.png rename to docs/icons/ms-icon-150x150.png diff --git a/docs/ms-icon-310x310.png b/docs/icons/ms-icon-310x310.png similarity index 100% rename from docs/ms-icon-310x310.png rename to docs/icons/ms-icon-310x310.png diff --git a/docs/ms-icon-70x70.png b/docs/icons/ms-icon-70x70.png similarity index 100% rename from docs/ms-icon-70x70.png rename to docs/icons/ms-icon-70x70.png diff --git a/docs/index.html b/docs/index.html index 5d88e91..9d1b843 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,5 +1,5 @@ - + Vicis - Presentation and transformation layer for data output in RESTful APIs. @@ -9,24 +9,24 @@ name="viewport" content="width=device-width, user-scalable=yes, initial-scale=1.0, maximum-scale=5.0, minimum-scale=1.0" /> - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - +