All files / src predicates.js

100% Statements 12/12
100% Branches 4/4
100% Functions 3/3
100% Lines 11/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31    6x 6x 6x 6x   6x 6x   6x 6x 12x     6x 3x                            
import R from 'ramda';
 
export const hasMinLength8 = R.compose(R.flip(R.gte)(8), R.length);
export const hasLowerLetter = R.test(/[a-z]/);
export const hasUpperLetter = R.test(/[A-Z]/);
export const hasNumber = R.test(/[0-9]/);
 
export const isNotEmpty = R.complement(R.isEmpty);
export const isNonEmptyOfType = (t, transform) => R.allPass([ R.is(t), R.pipe(transform, isNotEmpty) ]);
 
export const isNonEmptyTrimmedString = isNonEmptyOfType(String, R.trim);
export const hasLengthBetween = R.curry((minLength, maxLength, string) => {
    return string.length >= minLength && string.length <= maxLength;
});
 
export const isEqualOrShorterThan = R.curry((length, string) => {
    return string ? string.length <= length : true;
});
 
export default {
    hasMinLength8,
    hasLowerLetter,
    hasUpperLetter,
    hasLengthBetween,
    isEqualOrShorterThan,
    hasNumber,
    isNotEmpty,
    isNonEmptyOfType,
    isNonEmptyTrimmedString
};