Skip to content

Commit

Permalink
fix: Remove commented-out import
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry Grumbar committed Nov 23, 2017
1 parent 553e91f commit d3ef69f
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions src/rules.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,48 @@
// import isEqual = require('lodash/isEqual')

export type Rule<T> = (val: any, req: T) => boolean;
export type Rule<T> = (val: any, req: T) => boolean

export interface DefaultRules {
required: Rule<boolean>;
equals: Rule<any>;
min: Rule<number>;
max: Rule<number>;
required: Rule<boolean>
equals: Rule<any>
min: Rule<number>
max: Rule<number>
}

export function required(val: any, req: boolean = true) {
if (!req) {
return true;
return true
}

if (val === undefined || val === null) {
return false;
return false
}

return String(val).replace(/\s/g, "").length > 0;
return String(val).replace(/\s/g, '').length > 0
}

export function equals(val: any, compare: any) {
return val === compare;
return val === compare
}

export function min(val: any, req: number) {
return getSize(val) >= req;
return getSize(val) >= req
}

export function max(val: any, req: number) {
return getSize(val) <= req;
return getSize(val) <= req
}

const rules: DefaultRules = { required, equals, min, max };
const rules: DefaultRules = { required, equals, min, max }

export default rules;
export default rules

function getSize(val: any) {
if (val instanceof Array) {
return val.length;
return val.length
}

if (typeof val === "number") {
return val;
if (typeof val === 'number') {
return val
}

return val.length;
return val.length
}

0 comments on commit d3ef69f

Please sign in to comment.