Skip to content
Snippets Groups Projects
Commit a9910181 authored by François Agneray's avatar François Agneray
Browse files

Add instance shared module

parent a97b3b64
No related branches found
No related tags found
No related merge requests found
/**
* This file is part of Anis Client.
*
* @copyright Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import { FormControl } from '@angular/forms';
/**
* Validates NaN.
*
* @param {FormControl} control - The form control where to check NaN.
*
* @return {[key: string]: any} | null
*/
export function nanValidator(control: FormControl): {[key: string]: any} | null {
const value = parseFloat(control.value);
const regexp: RegExp = /^\-?\d+([.,]+\d*)?$/;
const isFloat = regexp.test(control.value);
if (control.value === '' || control.value === null) {
return null;
}
if (isNaN(value) || !isFloat) {
return { 'nan': { value: control.value + ' is not a number' } };
}
return null;
}
/**
* This file is part of Anis Client.
*
* @copyright Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import { ValidatorFn, AbstractControl } from '@angular/forms';
/**
* Validates range.
*
* @param {number} min - The minimum for the range.
* @param {number} max - The maximum for the range.
* @param {string} [formLabel] - The label of the form displayed in error message.
*
* @return ValidatorFn
*/
export function rangeValidator(min: number, max: number, formLabel?: string): ValidatorFn {
return (control: AbstractControl): {[key: string]: any} | null => {
const value = parseFloat(control.value);
if (value < min || value > max) {
if (formLabel) {
return { 'range': { value: formLabel + ' must be between ' + min + ' and ' + max } };
}
return { 'range': { value: 'Must be between ' + min + ' and ' + max } };
}
return null;
}
}
......@@ -173,7 +173,7 @@ export const getPrettyCriterion = (criterion: Criterion): string => {
* // returns =
* getPrettyOperator('eq')
*/
const getPrettyOperator = (operator: string): string => {
export const getPrettyOperator = (operator: string): string => {
switch (operator) {
case 'eq':
return '=';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment