UNPKG

@ng-formworks/core

Version:

Angular ng-formworks - JSON Schema Form builder core

1 lines 785 kB
{"version":3,"file":"ng-formworks-core.mjs","sources":["../../../../projects/ng-formworks-core/src/lib/framework-library/framework.ts","../../../../projects/ng-formworks-core/src/lib/locale/de-validation-messages.ts","../../../../projects/ng-formworks-core/src/lib/locale/en-validation-messages.ts","../../../../projects/ng-formworks-core/src/lib/locale/es-validation-messages.ts","../../../../projects/ng-formworks-core/src/lib/locale/fr-validation-messages.ts","../../../../projects/ng-formworks-core/src/lib/locale/it-validation-messages.ts","../../../../projects/ng-formworks-core/src/lib/locale/pt-validation-messages.ts","../../../../projects/ng-formworks-core/src/lib/locale/zh-validation-messages.ts","../../../../projects/ng-formworks-core/src/lib/shared/validator.functions.ts","../../../../projects/ng-formworks-core/src/lib/shared/utility.functions.ts","../../../../projects/ng-formworks-core/src/lib/shared/jsonpointer.functions.ts","../../../../projects/ng-formworks-core/src/lib/shared/format-regex.constants.ts","../../../../projects/ng-formworks-core/src/lib/shared/json.validators.ts","../../../../projects/ng-formworks-core/src/lib/shared/merge-schemas.function.ts","../../../../projects/ng-formworks-core/src/lib/shared/json-schema.functions.ts","../../../../projects/ng-formworks-core/src/lib/shared/convert-schema-to-draft6.function.ts","../../../../projects/ng-formworks-core/src/lib/shared/form-group.functions.ts","../../../../projects/ng-formworks-core/src/lib/shared/layout.functions.ts","../../../../projects/ng-formworks-core/src/lib/shared/index.ts","../../../../projects/ng-formworks-core/src/lib/json-schema-form.service.ts","../../../../projects/ng-formworks-core/src/lib/widget-library/select-widget.component.ts","../../../../projects/ng-formworks-core/src/lib/framework-library/no-framework.component.ts","../../../../projects/ng-formworks-core/src/lib/framework-library/no-framework.component.html","../../../../projects/ng-formworks-core/src/lib/framework-library/no.framework.ts","../../../../projects/ng-formworks-core/src/lib/widget-library/element-attribute.directive.ts","../../../../projects/ng-formworks-core/src/lib/widget-library/add-reference.component.ts","../../../../projects/ng-formworks-core/src/lib/widget-library/button.component.ts","../../../../projects/ng-formworks-core/src/lib/widget-library/checkbox.component.ts","../../../../projects/ng-formworks-core/src/lib/widget-library/checkboxes.component.ts","../../../../projects/ng-formworks-core/src/lib/widget-library/file.component.ts","../../../../projects/ng-formworks-core/src/lib/widget-library/hidden.component.ts","../../../../projects/ng-formworks-core/src/lib/widget-library/input.component.ts","../../../../projects/ng-formworks-core/src/lib/widget-library/message.component.ts","../../../../projects/ng-formworks-core/src/lib/widget-library/none.component.ts","../../../../projects/ng-formworks-core/src/lib/widget-library/number.component.ts","../../../../projects/ng-formworks-core/src/lib/widget-library/select-framework.component.ts","../../../../projects/ng-formworks-core/src/lib/widget-library/tabs.component.ts","../../../../projects/ng-formworks-core/src/lib/widget-library/one-of.component.ts","../../../../projects/ng-formworks-core/src/lib/widget-library/radios.component.ts","../../../../projects/ng-formworks-core/src/lib/widget-library/orderable.directive.ts","../../../../projects/ng-formworks-core/src/lib/widget-library/root.component.ts","../../../../projects/ng-formworks-core/src/lib/widget-library/section.component.ts","../../../../projects/ng-formworks-core/src/lib/widget-library/select.component.ts","../../../../projects/ng-formworks-core/src/lib/widget-library/submit.component.ts","../../../../projects/ng-formworks-core/src/lib/widget-library/tab.component.ts","../../../../projects/ng-formworks-core/src/lib/widget-library/template.component.ts","../../../../projects/ng-formworks-core/src/lib/widget-library/textarea.component.ts","../../../../projects/ng-formworks-core/src/lib/widget-library/widget-library.service.ts","../../../../projects/ng-formworks-core/src/lib/widget-library/index.ts","../../../../projects/ng-formworks-core/src/lib/widget-library/widget-library.module.ts","../../../../projects/ng-formworks-core/src/lib/framework-library/no-framework.module.ts","../../../../projects/ng-formworks-core/src/lib/framework-library/framework-library.service.ts","../../../../projects/ng-formworks-core/src/lib/json-schema-form.component.ts","../../../../projects/ng-formworks-core/src/lib/json-schema-form.component.html","../../../../projects/ng-formworks-core/src/lib/json-schema-form.module.ts","../../../../projects/ng-formworks-core/src/public_api.ts","../../../../projects/ng-formworks-core/src/ng-formworks-core.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\r\n\r\n@Injectable()\r\nexport class Framework {\r\n name: string;\r\n text:string;\r\n framework: any;\r\n widgets?: { [key: string]: any } = {};\r\n stylesheets?: string[] = [];\r\n scripts?: string[] = [];\r\n}\r\n","export const deValidationMessages: any = { // Default German error messages\r\n required: 'Darf nicht leer sein',\r\n minLength: 'Mindestens {{minimumLength}} Zeichen benötigt (aktuell: {{currentLength}})',\r\n maxLength: 'Maximal {{maximumLength}} Zeichen erlaubt (aktuell: {{currentLength}})',\r\n pattern: 'Entspricht nicht diesem regulären Ausdruck: {{requiredPattern}}',\r\n format: function (error) {\r\n switch (error.requiredFormat) {\r\n case 'date':\r\n return 'Muss ein Datum sein, z. B. \"2000-12-31\"';\r\n case 'time':\r\n return 'Muss eine Zeitangabe sein, z. B. \"16:20\" oder \"03:14:15.9265\"';\r\n case 'date-time':\r\n return 'Muss Datum mit Zeit beinhalten, z. B. \"2000-03-14T01:59\" oder \"2000-03-14T01:59:26.535Z\"';\r\n case 'email':\r\n return 'Keine gültige E-Mail-Adresse (z. B. \"name@example.com\")';\r\n case 'hostname':\r\n return 'Kein gültiger Hostname (z. B. \"example.com\")';\r\n case 'ipv4':\r\n return 'Keine gültige IPv4-Adresse (z. B. \"127.0.0.1\")';\r\n case 'ipv6':\r\n return 'Keine gültige IPv6-Adresse (z. B. \"1234:5678:9ABC:DEF0:1234:5678:9ABC:DEF0\")';\r\n // TODO: add examples for 'uri', 'uri-reference', and 'uri-template'\r\n // case 'uri': case 'uri-reference': case 'uri-template':\r\n case 'url':\r\n return 'Keine gültige URL (z. B. \"http://www.example.com/page.html\")';\r\n case 'uuid':\r\n return 'Keine gültige UUID (z. B. \"12345678-9ABC-DEF0-1234-56789ABCDEF0\")';\r\n case 'color':\r\n return 'Kein gültiger Farbwert (z. B. \"#FFFFFF\")';\r\n case 'json-pointer':\r\n return 'Kein gültiger JSON-Pointer (z. B. \"/pointer/to/something\")';\r\n case 'relative-json-pointer':\r\n return 'Kein gültiger relativer JSON-Pointer (z. B. \"2/pointer/to/something\")';\r\n case 'regex':\r\n return 'Kein gültiger regulärer Ausdruck (z. B. \"(1-)?\\\\d{3}-\\\\d{3}-\\\\d{4}\")';\r\n case 'duration':\r\n return \"Muss eine gültige ISO 8601-Dauer sein (z. B. 'PT1H30M')\"; \r\n default:\r\n return 'Muss diesem Format entsprechen: ' + error.requiredFormat;\r\n }\r\n },\r\n minimum: 'Muss mindestens {{minimumValue}} sein',\r\n exclusiveMinimum: 'Muss größer als {{exclusiveMinimumValue}} sein',\r\n maximum: 'Darf maximal {{maximumValue}} sein',\r\n exclusiveMaximum: 'Muss kleiner als {{exclusiveMaximumValue}} sein',\r\n multipleOf: function (error) {\r\n if ((1 / error.multipleOfValue) % 10 === 0) {\r\n const decimals = Math.log10(1 / error.multipleOfValue);\r\n return `Maximal ${decimals} Dezimalstellen erlaubt`;\r\n } else {\r\n return `Muss ein Vielfaches von ${error.multipleOfValue} sein`;\r\n }\r\n },\r\n minProperties: 'Mindestens {{minimumProperties}} Attribute erforderlich (aktuell: {{currentProperties}})',\r\n maxProperties: 'Maximal {{maximumProperties}} Attribute erlaubt (aktuell: {{currentProperties}})',\r\n minItems: 'Mindestens {{minimumItems}} Werte erforderlich (aktuell: {{currentItems}})',\r\n maxItems: 'Maximal {{maximumItems}} Werte erlaubt (aktuell: {{currentItems}})',\r\n uniqueItems: 'Alle Werte müssen eindeutig sein',\r\n // Note: No default error messages for 'type', 'const', 'enum', or 'dependencies'\r\n};\r\n","export const enValidationMessages: any = { // Default English error messages\r\n required: 'This field is required.',\r\n minLength: 'Must be {{minimumLength}} characters or longer (current length: {{currentLength}})',\r\n maxLength: 'Must be {{maximumLength}} characters or shorter (current length: {{currentLength}})',\r\n pattern: 'Must match pattern: {{requiredPattern}}',\r\n format: function (error) {\r\n switch (error.requiredFormat) {\r\n case 'date':\r\n return 'Must be a date, like \"2000-12-31\"';\r\n case 'time':\r\n return 'Must be a time, like \"16:20\" or \"03:14:15.9265\"';\r\n case 'date-time':\r\n return 'Must be a date-time, like \"2000-03-14T01:59\" or \"2000-03-14T01:59:26.535Z\"';\r\n case 'email':\r\n return 'Must be an email address, like \"name@example.com\"';\r\n case 'hostname':\r\n return 'Must be a hostname, like \"example.com\"';\r\n case 'ipv4':\r\n return 'Must be an IPv4 address, like \"127.0.0.1\"';\r\n case 'ipv6':\r\n return 'Must be an IPv6 address, like \"1234:5678:9ABC:DEF0:1234:5678:9ABC:DEF0\"';\r\n // TODO: add examples for 'uri', 'uri-reference', and 'uri-template'\r\n // case 'uri': case 'uri-reference': case 'uri-template':\r\n case 'url':\r\n return 'Must be a url, like \"http://www.example.com/page.html\"';\r\n case 'uuid':\r\n return 'Must be a uuid, like \"12345678-9ABC-DEF0-1234-56789ABCDEF0\"';\r\n case 'color':\r\n return 'Must be a color, like \"#FFFFFF\"';\r\n case 'json-pointer':\r\n return 'Must be a JSON Pointer, like \"/pointer/to/something\"';\r\n case 'relative-json-pointer':\r\n return 'Must be a relative JSON Pointer, like \"2/pointer/to/something\"';\r\n case 'regex':\r\n return 'Must be a regular expression, like \"(1-)?\\\\d{3}-\\\\d{3}-\\\\d{4}\"';\r\n case 'duration':\r\n return \"Must be a valid ISO 8601 duration (e.g., 'PT1H30M')\";\r\n default:\r\n return 'Must be a correctly formatted ' + error.requiredFormat;\r\n }\r\n },\r\n minimum: 'Must be {{minimumValue}} or more',\r\n exclusiveMinimum: 'Must be more than {{exclusiveMinimumValue}}',\r\n maximum: 'Must be {{maximumValue}} or less',\r\n exclusiveMaximum: 'Must be less than {{exclusiveMaximumValue}}',\r\n multipleOf: function (error) {\r\n if ((1 / error.multipleOfValue) % 10 === 0) {\r\n const decimals = Math.log10(1 / error.multipleOfValue);\r\n return `Must have ${decimals} or fewer decimal places.`;\r\n } else {\r\n return `Must be a multiple of ${error.multipleOfValue}.`;\r\n }\r\n },\r\n minProperties: 'Must have {{minimumProperties}} or more items (current items: {{currentProperties}})',\r\n maxProperties: 'Must have {{maximumProperties}} or fewer items (current items: {{currentProperties}})',\r\n minItems: 'Must have {{minimumItems}} or more items (current items: {{currentItems}})',\r\n maxItems: 'Must have {{maximumItems}} or fewer items (current items: {{currentItems}})',\r\n uniqueItems: 'All items must be unique',\r\n // Note: No default error messages for 'type', 'const', 'enum', or 'dependencies'\r\n};\r\n","export const esValidationMessages: any = { // Default Spanish error messages\r\n required: 'Este campo está requerido.',\r\n minLength: 'Debe tener {{minimumLength}} caracteres o más longitud (longitud actual: {{currentLength}})',\r\n maxLength: 'Debe tener {{maximumLength}} caracteres o menos longitud (longitud actual: {{currentLength}})',\r\n pattern: 'Must match pattern: {{requiredPattern}}',\r\n format: function (error) {\r\n switch (error.requiredFormat) {\r\n case 'date':\r\n return 'Debe tener una fecha, ej \"2000-12-31\"';\r\n case 'time':\r\n return 'Debe tener una hora, ej \"16:20\" o \"03:14:15.9265\"';\r\n case 'date-time':\r\n return 'Debe tener fecha y hora, ej \"2000-03-14T01:59\" o \"2000-03-14T01:59:26.535Z\"';\r\n case 'email':\r\n return 'No hay dirección de correo electrónico válida, ej \"name@example.com\"';\r\n case 'hostname':\r\n return 'Debe ser un nombre de host válido, ej \"example.com\"';\r\n case 'ipv4':\r\n return 'Debe ser una dirección de IPv4, ej \"127.0.0.1\"';\r\n case 'ipv6':\r\n return 'Debe ser una dirección de IPv6, ej \"1234:5678:9ABC:DEF0:1234:5678:9ABC:DEF0\"';\r\n case 'url':\r\n return 'Debe ser una URL, ej \"http://www.example.com/page.html\"';\r\n case 'uuid':\r\n return 'Debe ser un UUID, ej \"12345678-9ABC-DEF0-1234-56789ABCDEF0\"';\r\n case 'color':\r\n return 'Debe ser un color, ej \"#FFFFFF\"';\r\n case 'json-pointer':\r\n return 'Debe ser un JSON Pointer, ej \"/pointer/to/something\"';\r\n case 'relative-json-pointer':\r\n return 'Debe ser un JSON Pointer relativo, ej \"2/pointer/to/something\"';\r\n case 'regex':\r\n return 'Debe ser una expresión regular, ej \"(1-)?\\\\d{3}-\\\\d{3}-\\\\d{4}\"';\r\n case 'duration':\r\n return \"Debe ser una duración válida en formato ISO 8601 (p. ej., 'PT1H30M')\"; \r\n default:\r\n return 'Debe tener el formato correcto ' + error.requiredFormat;\r\n }\r\n },\r\n minimum: 'Debe ser {{minimumValue}} o más',\r\n exclusiveMinimum: 'Debe ser superior a {{exclusiveMinimumValue}}',\r\n maximum: 'Debe ser {{maximumValue}} o menos',\r\n exclusiveMaximum: 'Debe ser menor que {{exclusiveMaximumValue}}',\r\n multipleOf: function (error) {\r\n if ((1 / error.multipleOfValue) % 10 === 0) {\r\n const decimals = Math.log10(1 / error.multipleOfValue);\r\n return `Se permite un máximo de ${decimals} decimales`;\r\n } else {\r\n return `Debe ser múltiplo de ${error.multipleOfValue}.`;\r\n }\r\n },\r\n minProperties: 'Debe tener {{minimumProperties}} o más elementos (elementos actuales: {{currentProperties}})',\r\n maxProperties: 'Debe tener {{maximumProperties}} o menos elementos (elementos actuales: {{currentProperties}})',\r\n minItems: 'Debe tener {{minimumItems}} o más elementos (elementos actuales: {{currentItems}})',\r\n maxItems: 'Debe tener {{maximumItems}} o menos elementos (elementos actuales: {{currentItems}})',\r\n uniqueItems: 'Todos los elementos deben ser únicos',\r\n};\r\n","export const frValidationMessages: any = { // French error messages\r\n required: 'Est obligatoire.',\r\n minLength: 'Doit avoir minimum {{minimumLength}} caractères (actuellement: {{currentLength}})',\r\n maxLength: 'Doit avoir maximum {{maximumLength}} caractères (actuellement: {{currentLength}})',\r\n pattern: 'Doit respecter: {{requiredPattern}}',\r\n format: function (error) {\r\n switch (error.requiredFormat) {\r\n case 'date':\r\n return 'Doit être une date, tel que \"2000-12-31\"';\r\n case 'time':\r\n return 'Doit être une heure, tel que \"16:20\" ou \"03:14:15.9265\"';\r\n case 'date-time':\r\n return 'Doit être une date et une heure, tel que \"2000-03-14T01:59\" ou \"2000-03-14T01:59:26.535Z\"';\r\n case 'email':\r\n return 'Doit être une adresse e-mail, tel que \"name@example.com\"';\r\n case 'hostname':\r\n return 'Doit être un nom de domaine, tel que \"example.com\"';\r\n case 'ipv4':\r\n return 'Doit être une adresse IPv4, tel que \"127.0.0.1\"';\r\n case 'ipv6':\r\n return 'Doit être une adresse IPv6, tel que \"1234:5678:9ABC:DEF0:1234:5678:9ABC:DEF0\"';\r\n // TODO: add examples for 'uri', 'uri-reference', and 'uri-template'\r\n // case 'uri': case 'uri-reference': case 'uri-template':\r\n case 'url':\r\n return 'Doit être une URL, tel que \"http://www.example.com/page.html\"';\r\n case 'uuid':\r\n return 'Doit être un UUID, tel que \"12345678-9ABC-DEF0-1234-56789ABCDEF0\"';\r\n case 'color':\r\n return 'Doit être une couleur, tel que \"#FFFFFF\"';\r\n case 'json-pointer':\r\n return 'Doit être un JSON Pointer, tel que \"/pointer/to/something\"';\r\n case 'relative-json-pointer':\r\n return 'Doit être un relative JSON Pointer, tel que \"2/pointer/to/something\"';\r\n case 'regex':\r\n return 'Doit être une expression régulière, tel que \"(1-)?\\\\d{3}-\\\\d{3}-\\\\d{4}\"';\r\n case 'duration':\r\n return \"Doit être une durée valide au format ISO 8601 (par ex., 'PT1H30M')\";\r\n default:\r\n return 'Doit être avoir le format correct: ' + error.requiredFormat;\r\n }\r\n },\r\n minimum: 'Doit être supérieur à {{minimumValue}}',\r\n exclusiveMinimum: 'Doit avoir minimum {{exclusiveMinimumValue}} charactères',\r\n maximum: 'Doit être inférieur à {{maximumValue}}',\r\n exclusiveMaximum: 'Doit avoir maximum {{exclusiveMaximumValue}} charactères',\r\n multipleOf: function (error) {\r\n if ((1 / error.multipleOfValue) % 10 === 0) {\r\n const decimals = Math.log10(1 / error.multipleOfValue);\r\n return `Doit comporter ${decimals} ou moins de decimales.`;\r\n } else {\r\n return `Doit être un multiple de ${error.multipleOfValue}.`;\r\n }\r\n },\r\n minProperties: 'Doit comporter au minimum {{minimumProperties}} éléments',\r\n maxProperties: 'Doit comporter au maximum {{maximumProperties}} éléments',\r\n minItems: 'Doit comporter au minimum {{minimumItems}} éléments',\r\n maxItems: 'Doit comporter au maximum {{minimumItems}} éléments',\r\n uniqueItems: 'Tous les éléments doivent être uniques',\r\n // Note: No default error messages for 'type', 'const', 'enum', or 'dependencies'\r\n};\r\n","export const itValidationMessages: any = { // Default Italian error messages\r\n required: 'Il campo è obbligatorio',\r\n minLength: 'Deve inserire almeno {{minimumLength}} caratteri (lunghezza corrente: {{currentLength}})',\r\n maxLength: 'Il numero massimo di caratteri consentito è {{maximumLength}} (lunghezza corrente: {{currentLength}})',\r\n pattern: 'Devi rispettare il pattern : {{requiredPattern}}',\r\n format: function (error) {\r\n switch (error.requiredFormat) {\r\n case 'date':\r\n return 'Deve essere una data, come \"31-12-2000\"';\r\n case 'time':\r\n return 'Deve essere un orario, come \"16:20\" o \"03:14:15.9265\"';\r\n case 'date-time':\r\n return 'Deve essere data-orario, come \"14-03-2000T01:59\" or \"14-03-2000T01:59:26.535Z\"';\r\n case 'email':\r\n return 'Deve essere un indirzzo email, come \"name@example.com\"';\r\n case 'hostname':\r\n return 'Deve essere un hostname, come \"example.com\"';\r\n case 'ipv4':\r\n return 'Deve essere un indirizzo IPv4, come \"127.0.0.1\"';\r\n case 'ipv6':\r\n return 'Deve essere un indirizzo IPv6, come \"1234:5678:9ABC:DEF0:1234:5678:9ABC:DEF0\"';\r\n // TODO: add examples for 'uri', 'uri-reference', and 'uri-template'\r\n // case 'uri': case 'uri-reference': case 'uri-template':\r\n case 'url':\r\n return 'Deve essere un url, come \"http://www.example.com/page.html\"';\r\n case 'uuid':\r\n return 'Deve essere un uuid, come \"12345678-9ABC-DEF0-1234-56789ABCDEF0\"';\r\n case 'color':\r\n return 'Deve essere un colore, come \"#FFFFFF\"';\r\n case 'json-pointer':\r\n return 'Deve essere un JSON Pointer, come \"/pointer/to/something\"';\r\n case 'relative-json-pointer':\r\n return 'Deve essere un JSON Pointer relativo, come \"2/pointer/to/something\"';\r\n case 'regex':\r\n return 'Deve essere una regular expression, come \"(1-)?\\\\d{3}-\\\\d{3}-\\\\d{4}\"';\r\n case 'duration':\r\n return \"Deve essere una durata valida nel formato ISO 8601 (es. 'PT1H30M')\"; \r\n default:\r\n return 'Deve essere formattato correttamente ' + error.requiredFormat;\r\n }\r\n },\r\n minimum: 'Deve essere {{minimumValue}} o più',\r\n exclusiveMinimum: 'Deve essere più di {{exclusiveMinimumValue}}',\r\n maximum: 'Deve essere {{maximumValue}} o meno',\r\n exclusiveMaximum: 'Deve essere minore di {{exclusiveMaximumValue}}',\r\n multipleOf: function (error) {\r\n if ((1 / error.multipleOfValue) % 10 === 0) {\r\n const decimals = Math.log10(1 / error.multipleOfValue);\r\n return `Deve avere ${decimals} o meno decimali.`;\r\n } else {\r\n return `Deve essere multiplo di ${error.multipleOfValue}.`;\r\n }\r\n },\r\n minProperties: 'Deve avere {{minimumProperties}} o più elementi (elementi correnti: {{currentProperties}})',\r\n maxProperties: 'Deve avere {{maximumProperties}} o meno elementi (elementi correnti: {{currentProperties}})',\r\n minItems: 'Deve avere {{minimumItems}} o più elementi (elementi correnti: {{currentItems}})',\r\n maxItems: 'Deve avere {{maximumItems}} o meno elementi (elementi correnti: {{currentItems}})',\r\n uniqueItems: 'Tutti gli elementi devono essere unici',\r\n // Note: No default error messages for 'type', 'const', 'enum', or 'dependencies'\r\n};\r\n","export const ptValidationMessages: any = { // Brazilian Portuguese error messages\r\n required: 'Este campo é obrigatório.',\r\n minLength: 'É preciso no mínimo {{minimumLength}} caracteres ou mais (tamanho atual: {{currentLength}})',\r\n maxLength: 'É preciso no máximo {{maximumLength}} caracteres ou menos (tamanho atual: {{currentLength}})',\r\n pattern: 'Tem que ajustar ao formato: {{requiredPattern}}',\r\n format: function (error) {\r\n switch (error.requiredFormat) {\r\n case 'date':\r\n return 'Tem que ser uma data, por exemplo \"2000-12-31\"';\r\n case 'time':\r\n return 'Tem que ser horário, por exemplo \"16:20\" ou \"03:14:15.9265\"';\r\n case 'date-time':\r\n return 'Tem que ser data e hora, por exemplo \"2000-03-14T01:59\" ou \"2000-03-14T01:59:26.535Z\"';\r\n case 'email':\r\n return 'Tem que ser um email, por exemplo \"fulano@exemplo.com.br\"';\r\n case 'hostname':\r\n return 'Tem que ser uma nome de domínio, por exemplo \"exemplo.com.br\"';\r\n case 'ipv4':\r\n return 'Tem que ser um endereço IPv4, por exemplo \"127.0.0.1\"';\r\n case 'ipv6':\r\n return 'Tem que ser um endereço IPv6, por exemplo \"1234:5678:9ABC:DEF0:1234:5678:9ABC:DEF0\"';\r\n // TODO: add examples for 'uri', 'uri-reference', and 'uri-template'\r\n // case 'uri': case 'uri-reference': case 'uri-template':\r\n case 'url':\r\n return 'Tem que ser uma URL, por exemplo \"http://www.exemplo.com.br/pagina.html\"';\r\n case 'uuid':\r\n return 'Tem que ser um uuid, por exemplo \"12345678-9ABC-DEF0-1234-56789ABCDEF0\"';\r\n case 'color':\r\n return 'Tem que ser uma cor, por exemplo \"#FFFFFF\"';\r\n case 'json-pointer':\r\n return 'Tem que ser um JSON Pointer, por exemplo \"/referencia/para/algo\"';\r\n case 'relative-json-pointer':\r\n return 'Tem que ser um JSON Pointer relativo, por exemplo \"2/referencia/para/algo\"';\r\n case 'regex':\r\n return 'Tem que ser uma expressão regular, por exemplo \"(1-)?\\\\d{3}-\\\\d{3}-\\\\d{4}\"';\r\n case 'duration':\r\n return \"Deve ser uma duração válida no formato ISO 8601 (ex.: 'PT1H30M')\";\r\n default:\r\n return 'Tem que ser no formato: ' + error.requiredFormat;\r\n }\r\n },\r\n minimum: 'Tem que ser {{minimumValue}} ou mais',\r\n exclusiveMinimum: 'Tem que ser mais que {{exclusiveMinimumValue}}',\r\n maximum: 'Tem que ser {{maximumValue}} ou menos',\r\n exclusiveMaximum: 'Tem que ser menor que {{exclusiveMaximumValue}}',\r\n multipleOf: function (error) {\r\n if ((1 / error.multipleOfValue) % 10 === 0) {\r\n const decimals = Math.log10(1 / error.multipleOfValue);\r\n return `Tem que ter ${decimals} ou menos casas decimais.`;\r\n } else {\r\n return `Tem que ser um múltiplo de ${error.multipleOfValue}.`;\r\n }\r\n },\r\n minProperties: 'Deve ter {{minimumProperties}} ou mais itens (itens até o momento: {{currentProperties}})',\r\n maxProperties: 'Deve ter {{maximumProperties}} ou menos intens (itens até o momento: {{currentProperties}})',\r\n minItems: 'Deve ter {{minimumItems}} ou mais itens (itens até o momento: {{currentItems}})',\r\n maxItems: 'Deve ter {{maximumItems}} ou menos itens (itens até o momento: {{currentItems}})',\r\n uniqueItems: 'Todos os itens devem ser únicos',\r\n // Note: No default error messages for 'type', 'const', 'enum', or 'dependencies'\r\n};\r\n","export const zhValidationMessages: any = { // Chinese error messages\r\n required: '必填字段.',\r\n minLength: '字符长度必须大于或者等于 {{minimumLength}} (当前长度: {{currentLength}})',\r\n maxLength: '字符长度必须小于或者等于 {{maximumLength}} (当前长度: {{currentLength}})',\r\n pattern: '必须匹配正则表达式: {{requiredPattern}}',\r\n format: function (error) {\r\n switch (error.requiredFormat) {\r\n case 'date':\r\n return '必须为日期格式, 比如 \"2000-12-31\"';\r\n case 'time':\r\n return '必须为时间格式, 比如 \"16:20\" 或者 \"03:14:15.9265\"';\r\n case 'date-time':\r\n return '必须为日期时间格式, 比如 \"2000-03-14T01:59\" 或者 \"2000-03-14T01:59:26.535Z\"';\r\n case 'email':\r\n return '必须为邮箱地址, 比如 \"name@example.com\"';\r\n case 'hostname':\r\n return '必须为主机名, 比如 \"example.com\"';\r\n case 'ipv4':\r\n return '必须为 IPv4 地址, 比如 \"127.0.0.1\"';\r\n case 'ipv6':\r\n return '必须为 IPv6 地址, 比如 \"1234:5678:9ABC:DEF0:1234:5678:9ABC:DEF0\"';\r\n // TODO: add examples for 'uri', 'uri-reference', and 'uri-template'\r\n // case 'uri': case 'uri-reference': case 'uri-template':\r\n case 'url':\r\n return '必须为 url, 比如 \"http://www.example.com/page.html\"';\r\n case 'uuid':\r\n return '必须为 uuid, 比如 \"12345678-9ABC-DEF0-1234-56789ABCDEF0\"';\r\n case 'color':\r\n return '必须为颜色值, 比如 \"#FFFFFF\"';\r\n case 'json-pointer':\r\n return '必须为 JSON Pointer, 比如 \"/pointer/to/something\"';\r\n case 'relative-json-pointer':\r\n return '必须为相对的 JSON Pointer, 比如 \"2/pointer/to/something\"';\r\n case 'regex':\r\n return '必须为正则表达式, 比如 \"(1-)?\\\\d{3}-\\\\d{3}-\\\\d{4}\"';\r\n case 'duration':\r\n return \"必须是有效的 ISO 8601 持续时间(例如:'PT1H30M')\"; \r\n default:\r\n return '必须为格式正确的 ' + error.requiredFormat;\r\n }\r\n },\r\n minimum: '必须大于或者等于最小值: {{minimumValue}}',\r\n exclusiveMinimum: '必须大于最小值: {{exclusiveMinimumValue}}',\r\n maximum: '必须小于或者等于最大值: {{maximumValue}}',\r\n exclusiveMaximum: '必须小于最大值: {{exclusiveMaximumValue}}',\r\n multipleOf: function (error) {\r\n if ((1 / error.multipleOfValue) % 10 === 0) {\r\n const decimals = Math.log10(1 / error.multipleOfValue);\r\n return `必须有 ${decimals} 位或更少的小数位`;\r\n } else {\r\n return `必须为 ${error.multipleOfValue} 的倍数`;\r\n }\r\n },\r\n minProperties: '项目数必须大于或者等于 {{minimumProperties}} (当前项目数: {{currentProperties}})',\r\n maxProperties: '项目数必须小于或者等于 {{maximumProperties}} (当前项目数: {{currentProperties}})',\r\n minItems: '项目数必须大于或者等于 {{minimumItems}} (当前项目数: {{currentItems}})',\r\n maxItems: '项目数必须小于或者等于 {{maximumItems}} (当前项目数: {{currentItems}})',\r\n uniqueItems: '所有项目必须是唯一的',\r\n // Note: No default error messages for 'type', 'const', 'enum', or 'dependencies'\r\n};\r\n","import { AbstractControl } from '@angular/forms';\r\nimport { from, Observable } from 'rxjs';\r\n\r\n/**\r\n * Validator utility function library:\r\n *\r\n * Validator and error utilities:\r\n * _executeValidators, _executeAsyncValidators, _mergeObjects, _mergeErrors\r\n *\r\n * Individual value checking:\r\n * isDefined, hasValue, isEmpty\r\n *\r\n * Individual type checking:\r\n * isString, isNumber, isInteger, isBoolean, isFunction, isObject, isArray,\r\n * isMap, isSet, isPromise, isObservable\r\n *\r\n * Multiple type checking and fixing:\r\n * getType, isType, isPrimitive, toJavaScriptType, toSchemaType,\r\n * _toPromise, toObservable\r\n *\r\n * Utility functions:\r\n * inArray, xor\r\n *\r\n * Typescript types and interfaces:\r\n * SchemaPrimitiveType, SchemaType, JavaScriptPrimitiveType, JavaScriptType,\r\n * PrimitiveValue, PlainObject, IValidatorFn, AsyncIValidatorFn\r\n *\r\n * Note: 'IValidatorFn' is short for 'invertable validator function',\r\n * which is a validator functions that accepts an optional second\r\n * argument which, if set to TRUE, causes the validator to perform\r\n * the opposite of its original function.\r\n */\r\n\r\nexport type SchemaPrimitiveType =\r\n 'string' | 'number' | 'integer' | 'boolean' | 'null';\r\nexport type SchemaType =\r\n 'string' | 'number' | 'integer' | 'boolean' | 'null' | 'object' | 'array';\r\nexport type JavaScriptPrimitiveType =\r\n 'string' | 'number' | 'boolean' | 'null' | 'undefined';\r\nexport type JavaScriptType =\r\n 'string' | 'number' | 'boolean' | 'null' | 'undefined' | 'object' | 'array' |\r\n 'map' | 'set' | 'arguments' | 'date' | 'error' | 'function' | 'json' |\r\n 'math' | 'regexp'; // Note: this list is incomplete\r\nexport type PrimitiveValue = string | number | boolean | null | undefined;\r\nexport interface PlainObject { [k: string]: any; }\r\n\r\nexport type IValidatorFn = (c: AbstractControl, i?: boolean) => PlainObject;\r\nexport type AsyncIValidatorFn = (c: AbstractControl, i?: boolean) => any;\r\n\r\n/**\r\n * '_executeValidators' utility function\r\n *\r\n * Validates a control against an array of validators, and returns\r\n * an array of the same length containing a combination of error messages\r\n * (from invalid validators) and null values (from valid validators)\r\n *\r\n * // { AbstractControl } control - control to validate\r\n * // { IValidatorFn[] } validators - array of validators\r\n * // { boolean } invert - invert?\r\n * // { PlainObject[] } - array of nulls and error message\r\n */\r\nexport function _executeValidators(control, validators, invert = false) {\r\n return validators.map(validator => validator(control, invert));\r\n}\r\n\r\n/**\r\n * '_executeAsyncValidators' utility function\r\n *\r\n * Validates a control against an array of async validators, and returns\r\n * an array of observabe results of the same length containing a combination of\r\n * error messages (from invalid validators) and null values (from valid ones)\r\n *\r\n * // { AbstractControl } control - control to validate\r\n * // { AsyncIValidatorFn[] } validators - array of async validators\r\n * // { boolean } invert - invert?\r\n * // - array of observable nulls and error message\r\n */\r\nexport function _executeAsyncValidators(control, validators, invert = false) {\r\n return validators.map(validator => validator(control, invert));\r\n}\r\n\r\n/**\r\n * '_mergeObjects' utility function\r\n *\r\n * Recursively Merges one or more objects into a single object with combined keys.\r\n * Automatically detects and ignores null and undefined inputs.\r\n * Also detects duplicated boolean 'not' keys and XORs their values.\r\n *\r\n * // { PlainObject[] } objects - one or more objects to merge\r\n * // { PlainObject } - merged object\r\n */\r\nexport function _mergeObjects(...objects) {\r\n const mergedObject: PlainObject = { };\r\n for (const currentObject of objects) {\r\n if (isObject(currentObject)) {\r\n for (const key of Object.keys(currentObject)) {\r\n const currentValue = currentObject[key];\r\n const mergedValue = mergedObject[key];\r\n mergedObject[key] = !isDefined(mergedValue) ? currentValue :\r\n key === 'not' && isBoolean(mergedValue, 'strict') &&\r\n isBoolean(currentValue, 'strict') ? xor(mergedValue, currentValue) :\r\n getType(mergedValue) === 'object' && getType(currentValue) === 'object' ?\r\n _mergeObjects(mergedValue, currentValue) :\r\n currentValue;\r\n }\r\n }\r\n }\r\n return mergedObject;\r\n}\r\n\r\n/**\r\n * '_mergeErrors' utility function\r\n *\r\n * Merges an array of objects.\r\n * Used for combining the validator errors returned from 'executeValidators'\r\n *\r\n * // { PlainObject[] } arrayOfErrors - array of objects\r\n * // { PlainObject } - merged object, or null if no usable input objectcs\r\n */\r\nexport function _mergeErrors(arrayOfErrors) {\r\n const mergedErrors = _mergeObjects(...arrayOfErrors);\r\n return isEmpty(mergedErrors) ? null : mergedErrors;\r\n}\r\n\r\n/**\r\n * 'isDefined' utility function\r\n *\r\n * Checks if a variable contains a value of any type.\r\n * Returns true even for otherwise 'falsey' values of 0, '', and false.\r\n *\r\n * // value - the value to check\r\n * // { boolean } - false if undefined or null, otherwise true\r\n */\r\nexport function isDefined(value) {\r\n return value !== undefined && value !== null;\r\n}\r\n\r\n/**\r\n * 'hasValue' utility function\r\n *\r\n * Checks if a variable contains a value.\r\n * Returs false for null, undefined, or a zero-length strng, '',\r\n * otherwise returns true.\r\n * (Stricter than 'isDefined' because it also returns false for '',\r\n * though it stil returns true for otherwise 'falsey' values 0 and false.)\r\n *\r\n * // value - the value to check\r\n * // { boolean } - false if undefined, null, or '', otherwise true\r\n */\r\nexport function hasValue(value) {\r\n return value !== undefined && value !== null && value !== '';\r\n}\r\n\r\n/**\r\n * 'isEmpty' utility function\r\n *\r\n * Similar to !hasValue, but also returns true for empty arrays and objects.\r\n *\r\n * // value - the value to check\r\n * // { boolean } - false if undefined, null, or '', otherwise true\r\n */\r\nexport function isEmpty(value) {\r\n if (isArray(value)) { return !value.length; }\r\n if (isObject(value)) { return !Object.keys(value).length; }\r\n return value === undefined || value === null || value === '';\r\n}\r\n\r\n/**\r\n * 'isString' utility function\r\n *\r\n * Checks if a value is a string.\r\n *\r\n * // value - the value to check\r\n * // { boolean } - true if string, false if not\r\n */\r\nexport function isString(value) {\r\n return typeof value === 'string';\r\n}\r\n\r\n/**\r\n * 'isNumber' utility function\r\n *\r\n * Checks if a value is a regular number, numeric string, or JavaScript Date.\r\n *\r\n * // value - the value to check\r\n * // { any = false } strict - if truthy, also checks JavaScript tyoe\r\n * // { boolean } - true if number, false if not\r\n */\r\nexport function isNumber(value, strict: any = false) {\r\n if (strict && typeof value !== 'number') { return false; }\r\n return !isNaN(value) && value !== value / 0;\r\n}\r\n\r\n/**\r\n * 'isInteger' utility function\r\n *\r\n * Checks if a value is an integer.\r\n *\r\n * // value - the value to check\r\n * // { any = false } strict - if truthy, also checks JavaScript tyoe\r\n * // {boolean } - true if number, false if not\r\n */\r\nexport function isInteger(value, strict: any = false) {\r\n if (strict && typeof value !== 'number') { return false; }\r\n return !isNaN(value) && value !== value / 0 && value % 1 === 0;\r\n}\r\n\r\n/**\r\n * 'isBoolean' utility function\r\n *\r\n * Checks if a value is a boolean.\r\n *\r\n * // value - the value to check\r\n * // { any = null } option - if 'strict', also checks JavaScript type\r\n * if TRUE or FALSE, checks only for that value\r\n * // { boolean } - true if boolean, false if not\r\n */\r\nexport function isBoolean(value, option: any = null) {\r\n if (option === 'strict') { return value === true || value === false; }\r\n if (option === true) {\r\n return value === true || value === 1 || value === 'true' || value === '1';\r\n }\r\n if (option === false) {\r\n return value === false || value === 0 || value === 'false' || value === '0';\r\n }\r\n return value === true || value === 1 || value === 'true' || value === '1' ||\r\n value === false || value === 0 || value === 'false' || value === '0';\r\n}\r\n\r\nexport function isFunction(item: any): boolean {\r\n return typeof item === 'function';\r\n}\r\n\r\nexport function isObject(item: any): boolean {\r\n return item !== null && typeof item === 'object';\r\n}\r\n\r\nexport function isArray(item: any): boolean {\r\n return Array.isArray(item);\r\n}\r\n\r\nexport function isDate(item: any): boolean {\r\n return !!item && Object.prototype.toString.call(item) === '[object Date]';\r\n}\r\n\r\nexport function isMap(item: any): boolean {\r\n return !!item && Object.prototype.toString.call(item) === '[object Map]';\r\n}\r\n\r\nexport function isSet(item: any): boolean {\r\n return !!item && Object.prototype.toString.call(item) === '[object Set]';\r\n}\r\n\r\nexport function isSymbol(item: any): boolean {\r\n return typeof item === 'symbol';\r\n}\r\n\r\n/**\r\n * 'getType' function\r\n *\r\n * Detects the JSON Schema Type of a value.\r\n * By default, detects numbers and integers even if formatted as strings.\r\n * (So all integers are also numbers, and any number may also be a string.)\r\n * However, it only detects true boolean values (to detect boolean values\r\n * in non-boolean formats, use isBoolean() instead).\r\n *\r\n * If passed a second optional parameter of 'strict', it will only detect\r\n * numbers and integers if they are formatted as JavaScript numbers.\r\n *\r\n * Examples:\r\n * getType('10.5') = 'number'\r\n * getType(10.5) = 'number'\r\n * getType('10') = 'integer'\r\n * getType(10) = 'integer'\r\n * getType('true') = 'string'\r\n * getType(true) = 'boolean'\r\n * getType(null) = 'null'\r\n * getType({ }) = 'object'\r\n * getType([]) = 'array'\r\n *\r\n * getType('10.5', 'strict') = 'string'\r\n * getType(10.5, 'strict') = 'number'\r\n * getType('10', 'strict') = 'string'\r\n * getType(10, 'strict') = 'integer'\r\n * getType('true', 'strict') = 'string'\r\n * getType(true, 'strict') = 'boolean'\r\n *\r\n * // value - value to check\r\n * // { any = false } strict - if truthy, also checks JavaScript tyoe\r\n * // { SchemaType }\r\n */\r\nexport function getType(value, strict: any = false) {\r\n if (!isDefined(value)) { return 'null'; }\r\n if (isArray(value)) { return 'array'; }\r\n if (isObject(value)) { return 'object'; }\r\n if (isBoolean(value, 'strict')) { return 'boolean'; }\r\n if (isInteger(value, strict)) { return 'integer'; }\r\n if (isNumber(value, strict)) { return 'number'; }\r\n if (isString(value) || (!strict && isDate(value))) { return 'string'; }\r\n return null;\r\n}\r\n\r\n/**\r\n * 'isType' function\r\n *\r\n * Checks wether an input (probably string) value contains data of\r\n * a specified JSON Schema type\r\n *\r\n * // { PrimitiveValue } value - value to check\r\n * // { SchemaPrimitiveType } type - type to check\r\n * // { boolean }\r\n */\r\nexport function isType(value, type) {\r\n switch (type) {\r\n case 'string':\r\n return isString(value) || isDate(value);\r\n case 'number':\r\n return isNumber(value);\r\n case 'integer':\r\n return isInteger(value);\r\n case 'boolean':\r\n return isBoolean(value);\r\n case 'null':\r\n return !hasValue(value);\r\n default:\r\n console.error(`isType error: \"${type}\" is not a recognized type.`);\r\n return null;\r\n }\r\n}\r\n\r\n/**\r\n * 'isPrimitive' function\r\n *\r\n * Checks wether an input value is a JavaScript primitive type:\r\n * string, number, boolean, or null.\r\n *\r\n * // value - value to check\r\n * // { boolean }\r\n */\r\nexport function isPrimitive(value) {\r\n return (isString(value) || isNumber(value) ||\r\n isBoolean(value, 'strict') || value === null);\r\n}\r\n\r\n/**\r\n * \r\n * @param date \r\n * @returns {string}\r\n * exmaple:\r\n * toDateString('2018-01-01') = '2018-01-01'\r\n * toDateString('2018-01-30T00:00:00.000Z') = '2018-01-30'\r\n */\r\nexport const toIsoString = (date: Date) => {\r\n const day = date.getDate();\r\n const month = date.getMonth() + 1;\r\n const year = date.getFullYear();\r\n return `${year}-${month < 10 ? '0' + month : month}-${day < 10 ? '0' + day : day}`;\r\n}\r\n\r\n/**\r\n * 'toJavaScriptType' function\r\n *\r\n * Converts an input (probably string) value to a JavaScript primitive type -\r\n * 'string', 'number', 'boolean', or 'null' - before storing in a JSON object.\r\n *\r\n * Does not coerce values (other than null), and only converts the types\r\n * of values that would otherwise be valid.\r\n *\r\n * If the optional third parameter 'strictIntegers' is TRUE, and the\r\n * JSON Schema type 'integer' is specified, it also verifies the input value\r\n * is an integer and, if it is, returns it as a JaveScript number.\r\n * If 'strictIntegers' is FALSE (or not set) the type 'integer' is treated\r\n * exactly the same as 'number', and allows decimals.\r\n *\r\n * Valid Examples:\r\n * toJavaScriptType('10', 'number' ) = 10 // '10' is a number\r\n * toJavaScriptType('10', 'integer') = 10 // '10' is also an integer\r\n * toJavaScriptType( 10, 'integer') = 10 // 10 is still an integer\r\n * toJavaScriptType( 10, 'string' ) = '10' // 10 can be made into a string\r\n * toJavaScriptType('10.5', 'number' ) = 10.5 // '10.5' is a number\r\n *\r\n * Invalid Examples:\r\n * toJavaScriptType('10.5', 'integer') = null // '10.5' is not an integer\r\n * toJavaScriptType( 10.5, 'integer') = null // 10.5 is still not an integer\r\n *\r\n * // { PrimitiveValue } value - value to convert\r\n * // { SchemaPrimitiveType | SchemaPrimitiveType[] } types - types to convert to\r\n * // { boolean = false } strictIntegers - if FALSE, treat integers as numbers\r\n * // { PrimitiveValue }\r\n */\r\nexport function toJavaScriptType(value, types, strictIntegers = true) {\r\n if (!isDefined(value)) { return null; }\r\n if (isString(types)) { types = [types]; }\r\n if (strictIntegers && inArray('integer', types)) {\r\n if (isInteger(value, 'strict')) { return value; }\r\n if (isInteger(value)) { return parseInt(value, 10); }\r\n }\r\n if (inArray('number', types) || (!strictIntegers && inArray('integer', types))) {\r\n if (isNumber(value, 'strict')) { return value; }\r\n if (isNumber(value)) { return parseFloat(value); }\r\n }\r\n if (inArray('string', types)) {\r\n if (isString(value)) { return value; }\r\n // If value is a date, and types includes 'string',\r\n // convert the date to a string\r\n if (isDate(value)) { return toIsoString(value); }\r\n if (isNumber(value)) { return value.toString(); }\r\n }\r\n // If value is a date, and types includes 'integer' or 'number',\r\n // but not 'string', convert the date to a number\r\n if (isDate(value) && (inArray('integer', types) || inArray('number', types))) {\r\n return value.getTime();\r\n }\r\n if (inArray('boolean', types)) {\r\n if (isBoolean(value, true)) { return true; }\r\n if (isBoolean(value, false)) { return false; }\r\n }\r\n return null;\r\n}\r\n\r\n/**\r\n * 'toSchemaType' function\r\n *\r\n * Converts an input (probably string) value to the \"best\" JavaScript\r\n * equivalent available from an allowed list of JSON Schema types, which may\r\n * contain 'string', 'number', 'integer', 'boolean', and/or 'null'.\r\n * If necssary, it does progressively agressive type coersion.\r\n * It will not return null unless null is in the list of allowed types.\r\n *\r\n * Number conversion examples:\r\n * toSchemaType('10', ['number','integer','string']) = 10 // integer\r\n * toSchemaType('10', ['number','string']) = 10 // number\r\n * toSchemaType('10', ['string']) = '10' // string\r\n * toSchemaType('10.5', ['number','integer','string']) = 10.5 // number\r\n * toSchemaType('10.5', ['integer','string']) = '10.5' // string\r\n * toSchemaType('10.5', ['integer']) = 10 // integer\r\n * toSchemaType(10.5, ['null','boolean','string']) = '10.5' // string\r\n * toSchemaType(10.5, ['null','boolean']) = true // boolean\r\n *\r\n * String conversion examples:\r\n * toSchemaType('1.5x', ['boolean','number','integer','string']) = '1.5x' // string\r\n * toSchemaType('1.5x', ['boolean','number','integer']) = '1.5' // number\r\n * toSchemaType('1.5x', ['boolean','integer']) = '1' // integer\r\n * toSchemaType('1.5x', ['boolean']) = true // boolean\r\n * toSchemaType('xyz', ['number','integer','boolean','null']) = true // boolean\r\n * toSchemaType('xyz', ['number','integer','null']) = null // null\r\n * toSchemaType('xyz', ['number','integer']) = 0 // number\r\n *\r\n * Boolean conversion examples:\r\n * toSchemaType('1', ['integer','number','string','boolean']) = 1 // integer\r\n * toSchemaType('1', ['number','string','boolean']) = 1 // number\r\n * toSchemaType('1', ['string','boolean']) = '1' // string\r\n * toSchemaType('1', ['boolean']) = true // boolean\r\n * toSchemaType('true', ['number','string','boolean']) = 'true' // string\r\n * toSchemaType('true', ['boolean']) = true // boolean\r\n * toSchemaType('true', ['number']) = 0 // number\r\n * toSchemaType(true, ['number','string','boolean']) = true // boolean\r\n * toSchemaType(true, ['number','string']) = 'true' // string\r\n * toSchemaType(true, ['number']) = 1 // number\r\n *\r\n * // { PrimitiveValue } value - value to convert\r\n * // { SchemaPrimitiveType | SchemaPrimitiveType[] } types - allowed types to convert to\r\n * // { PrimitiveValue }\r\n */\r\nexport function toSchemaType(value, types) {\r\n if (!isArray(<SchemaPrimitiveType>types)) {\r\n types = <SchemaPrimitiveType[]>[types];\r\n }\r\n if ((<SchemaPrimitiveType[]>types).includes('null') && !hasValue(value)) {\r\n return null;\r\n }\r\n if ((<SchemaPrimitiveType[]>types).includes('boolean') && !isBoolean(value, 'strict')) {\r\n return value;\r\n }\r\n if ((<SchemaPrimitiveType[]>types).includes('integer')) {\r\n const testValue = toJavaScriptType(value, 'integer');\r\n if (testValue !== null) { return +testValue; }\r\n }\r\n if ((<SchemaPrimitiveType[]>types).includes('number')) {\r\n const testValue = toJavaScriptType(value, 'number');\r\n if (testValue !== null) { return +testValue; }\r\n }\r\n if (\r\n (isString(value) || isNumber(value, 'strict')) &&\r\n (<SchemaPrimitiveType[]>types).includes('string')\r\n ) { // Convert number to string\r\n return toJavaScriptType(value, 'string');\r\n }\r\n if ((<SchemaPrimitiveType[]>types).includes('boolean') && isBoolean(value)) {\r\n return toJavaScriptType(value, 'boolean');\r\n }\r\n if ((<SchemaPrimitiveType[]>types).includes('string')) { // Convert null & boolean to string\r\n if (value === null) { return ''; }\r\n const testValue = toJavaScriptType(value, 'string');\r\n if (testValue !== null) { return testValue; }\r\n }\r\n if ((\r\n (<SchemaPrimitiveType[]>types).includes('number') ||\r\n (<SchemaPrimitiveType[]>types).includes('integer'))\r\n ) {\r\n if (value === true) { return 1; } // Convert boolean & null to number\r\n if (value === false || value === null || value === '') { return 0; }\r\n }\r\n if ((<SchemaPrimitiveType[]>types).includes('number')) { // Convert mixed string to number\r\n const testValue = parseFloat(<string>value);\r\n if (!!testValue) { return testValue; }\r\n }\r\n if ((<SchemaPrimitiveType[]>types).includes('integer')) { // Convert string or number to integer\r\n const testValue = parseInt(<string>value, 10);\r\n if (!!testValue) { return testValue; }\r\n }\r\n if ((<SchemaPrimitiveType[]>types).includes('boolean')) { // Convert anything to boolean\r\n return !!value;\r\n }\r\n if ((\r\n (<SchemaPrimitiveType[]>types).includes('number') ||\r\n (<SchemaPrimitiveType[]>types).includes('integer')\r\n ) && !(<SchemaPrimitiveType[]>types).includes('null')\r\n ) {\r\n return 0; // If null not allowed, return 0 for non-convertable values\r\n }\r\n}\r\n\r\n/**\r\n * 'isPromise' function\r\n *\r\n * // object\r\n * // { boolean }\r\n */\r\nexport function isPromise(object): object is Promise<any> {\r\n return !!object && typeof object.then === 'function';\r\n}\r\n\r\n/**\r\n * 'isObservable' function\r\n *\r\n * // object\r\n * // { boolean }\r\n */\r\nexport function isObservable(object): object is Observable<any> {\r\n return !!object && typeof object.subscribe === 'function';\r\n}\r\n\r\n/**\r\n * '_toPromise' function\r\n *\r\n * // { object } object\r\n * // { Promise<any> }\r\n */\r\nexport function _toPromise(object): Promise<any> {\r\n return isPromise(object) ? object : object.toPromise();\r\n}\r\n\r\n/**\r\n * 'toObservable' function\r\n *\r\n * // { object } object\r\n * // { Observable<any> }\r\n */\r\nexport function toObservable(object): Observable<any> {\r\n const observable = isPromise(object) ? from(object) : object;\r\n if (isObservable(observable)) { return observable; }\r\n console.error('toObservable error: Expected validator to return Promise or Observable.');\r\n return new Observable();\r\n}\r\n\r\n/**\r\n * 'inArray' function\r\n *\r\n * Searches an array for an item, or one of a list of items, and returns true\r\n * as soon as a match is found, or false if no match.\r\n *\r\n * If the optional third parameter allIn is set to TRUE, and the item to find\r\n * is an array, then the function returns true only if all elements from item\r\n * are found in the array list, and false if any element is not found. If the\r\n * item to find is not an array, setting allIn to TRUE has no effect.\r\n *\r\n * // { any|any[] } item - the item to search for\r\n * // array - the array to search\r\n * // { boolean = false } all