5htp-core 0.4.6-2 → 0.4.6-3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "5htp-core",
3
3
  "description": "Convenient TypeScript framework designed for Performance and Productivity.",
4
- "version": "0.4.6-2",
4
+ "version": "0.4.6-3",
5
5
  "author": "Gaetan Le Gac (https://github.com/gaetanlegac)",
6
6
  "repository": "git://github.com/gaetanlegac/5htp-core.git",
7
7
  "license": "MIT",
@@ -41,6 +41,28 @@ type TSubtype = TSchemaSubtype | Validator<any>;
41
41
  ----------------------------------*/
42
42
  export default class SchemaValidators {
43
43
 
44
+ /*----------------------------------
45
+ - UTILITIES
46
+ ----------------------------------*/
47
+ // Make every field optional
48
+ public partial = ( schema: TSchemaFields ) => {
49
+
50
+ const partialSchema: TSchemaFields = {};
51
+ for (const key in schema) {
52
+
53
+ // Only if validator
54
+ if (schema[key] instanceof Validator)
55
+ partialSchema[key] = new Validator(schema[key].type, schema[key].validateType, {
56
+ ...schema[key].options,
57
+ opt: true
58
+ });
59
+ else
60
+ partialSchema[key] = schema[key];
61
+ }
62
+
63
+ return partialSchema;
64
+ }
65
+
44
66
  /*----------------------------------
45
67
  - CONTENEURS
46
68
  ----------------------------------*/