🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@seges/angular-validators

Package Overview
Dependencies
Maintainers
4
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@seges/angular-validators - npm Package Compare versions

Comparing version
3.0.1
to
3.1.0
+29
src/app/validators/value/decimals.ts
import { IValidator } from "../IValidator";
export interface IDecimalsAttrs extends ng.IAttributes {
decimals: number;
}
export class DecimalsValidator implements IValidator<void> {
/**
* Validate if one value (number) is greater than other
* Return true if value is greater than compare value. Otherwise return false
* @param value: Value to check
* @param attrs: ng.IAttributes
*/
isValid(value: string, attrs?: IDecimalsAttrs): boolean {
if (!value || !attrs.decimals) {
return true;
}
let floatValue = value.replace(",", ".");
floatValue.toString().split(".");
let decimals = floatValue.toString().split(".")[1];
if (!decimals || !decimals.length) {
return true;
}
return decimals.length <= attrs.decimals;
}
}
+1
-1
{
"name": "@seges/angular-validators",
"version": "3.0.1",
"version": "3.1.0",
"description": "",

@@ -5,0 +5,0 @@ "main": "index.ts",

import * as angular from "angular";
import "angular-messages";
import { AngularValidationDirective } from "./angular.validator";
import {
MinuteValidator,
Time24HourValidator,
} from "./dateTime";
import {
DecimalsValidator,
IntegerValidator,

@@ -9,7 +15,2 @@ MaxValueValidator,

} from "./value";
import {
MinuteValidator,
Time24HourValidator,
} from "./dateTime";
import { AngularValidationDirective } from "./angular.validator";

@@ -40,1 +41,5 @@ export const validatorsModule = "seges.time.validators";

module.directive(minValueValidatorName, () => minValueValidator.factory());
const decimalsValidatorName = "decimals";
const decimalsValidator = new AngularValidationDirective(DecimalsValidator, decimalsValidatorName);
module.directive(decimalsValidatorName, () => decimalsValidator.factory());
export * from "./integer";
export * from "./maxValue";
export * from "./minValue";
export * from "./decimals";

@@ -27,3 +27,3 @@ import { IValidator } from "../IValidator";

*/
isValid(value: number, attrs?: IMaxValueAttrs): boolean {
isValid(value: string, attrs?: IMaxValueAttrs): boolean {
if (!value || !attrs.maxValue) {

@@ -33,4 +33,7 @@ return false;

return value <= parseInt(attrs.maxValue, 10);
let floatValue = value.replace(",", ".");
let floatMaxValue = attrs.maxValue.replace(",", ".");
return parseFloat(floatValue) <= parseFloat(floatMaxValue);
}
}

@@ -27,3 +27,3 @@ import { IValidator } from "../IValidator";

*/
isValid(value: number, attrs?: IMinValueAttrs ): boolean {
isValid(value: string, attrs?: IMinValueAttrs ): boolean {
if (!value || !attrs.minValue) {

@@ -33,4 +33,7 @@ return false;

return value >= parseInt(attrs.minValue, 10);
let floatValue = value.replace(",", ".");
let floatMinValue = attrs.minValue.replace(",", ".");
return parseFloat(floatValue) >= parseFloat(floatMinValue);
}
}