1.0.7 • Published 3 years ago

euriklis-validator v1.0.7

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

Euriklis - validator package.

About the package:

The euriklis - validator package is a javascript tool for analyzing, testing and validating of javascript types under some conditions. The package also provide an utility library for colored console printing of messages with some additional properties like warning symbol, information symbol, check symbol or not check symbol.

Installation

To install the euriklis-validator package just run in the terminal the following command.

npm install euriklis-validator --save --save-exact

This command will add the package to your node_modules folder.

Usage:

To use the validator or the message library you have to get it from the package:

const {validator, message} = require ('euriklis-validator')
let text = 'Test string'
new validator(text).is_string().on(true, () => {
    console.log('Yes, the text is string')
    let contain = new validator(text).contains('string')
        .on(true, () => {
            new message().bold().italic().underline()
                .set_color_yellow()
                .append('Euriklis information message:\n')
                .reset().set_color_green()
                .append_check_mark()
                .set_color_cyan()
                .append_white_space()
                .append('The string that is inserted like ')
                .append('argument in the validator instance ')
                .append('contains the substring "string".')
                .reset().log()
        })
})

Methods:

validator methods:

All the methods of validator except the on() method returns a validator type. The answer of the comparison and the condition fulfilling is recorded in the property answer. the validator class has the following methods: 1. is_string() - a method that checks if the value property of the current validator instance is string and sets the returned validator answer property to true or false respectively. 2. is_number() - checks if the value property of the current validator instance is number of not (integer and float). 3. is_array() - checks if the value of the current validator instance is array. 4. is_object() - checks if the value property of the current validator instance is object or not. 5. is_function() - checks if the validator property of the current validator instance is a javascript function type or not. 6. is_date() - checks if the current validator instance is a date or not. 7. is_empty() - a method that works when the type of the value property of the current validator instance is of null, array, string or object type and checks if these variables are empty of not. 8. is_integer() - this method checks if the value of the current validator instance is number that is integer or not. 9. is_float() - checks if the value of the current validator instance is a floating point number or not. 10. is_number_array() 11. is_string_array() 12. is_boolean() - a method that checks if the value property of the current validator instance is a boolean variable or not. 13. is_undefined() - checks if a variable is null or undefined. 14. is_same(parameter) - checks if the value property of the current validator instance is equals to the type and value of the parameter argument of the method. 15. is_same_with_any(parameter_array) - checks if the value property of the current validator instance contains some of the parameters that exists in the parameter array variable. 16. for_all (some_function) - checks if every value of an array/object in the value property of the validator instance, fulfills the conditions of the function. The argument of the some_function is assumed to be a validator type. 17. for_some(some_function) - similar to the for_all() method but requites the some_function to be true at least for one element of the array or object value property of the current validator instance. 18. not() - an operational method that sets the not operand to true and negate the next active validator atomic sentence. 19. and() - an operational method that sets the and operand to true and makes conjunction with the next active validator atomic sentence. 20. or() - an operational method that sets the the or operand to true and makes disjunction with the next active validator atomic sentence. 21. bind(other_validator) - gets in the input argument of the method a validator atomic sentence and then execute the operations that are required. 22. is_equal_or_lesser_than(n) - checks if the number in the value property of the current validator instance is equal or smaller to the number n in the argument of the method. Similar to this method is the method is the method is_lesser_than(n). 23. is_equal_or_bigger_than(n) - checks if the number in the value property of the current validator instance is greater of equal to the number n in the argument of the method. Similar to this method is the method is_bigger(n). 24. is_in_range(a, b) - checks if the number in the value property of the current validator instance is in the open interval (a, b), where a and b are both numbers, a <= b and a and b are the arguments of the method. Similar to this method is the method is_in_closed_range(a, b), where the number type in the validator instance has to be in the closed interval a, b. 25. has_length(n) - checks is a string or array or object type in the value property of the current validator instance has length equal to n, where n is number and is the argument of the method. 26. copy() - this method returns a validator instance with the same value property but removes the answer property. Similar to this method is the method absolute_copy() that copies all the properties of the current validator instance.

message methods

All the methods of the message class returns message object but makes changes on the text parameter of the instance. 1. bold() - makes the text that will be printed in the terminal bold style. 2. italic() - makes the text that will be printed in the terminal with italic style. 3. underline() or underscore() ?!!? - this method makes the style of the text that will be printed on the terminal to be underlined. 4. blink() - the text that will be printed on the terminal will blink periodically. 5. setColor(color) - sets the color of the text that will be printed on the terminal. The possible values of the color are 'black', 'red', 'green', 'blue', 'grey', 'violet', 'cyan' and finally 'yellow'. 6. setBgColor(color) - sets the background color of the text message that will be printed on the terminal. The possible color values of the method are the same with the setColor() method. Note that for the methods setColor() and setBgColor() exists short specified methods like set_color_red() that sets the color of the text automatically to the cyan without inserting of some argument. 7. reset() - reset, restart the color/background color and style properties of the text to the default. 8. append(text_message) - appends a text to the current text property of the message instance. 9. append_check_mark() - appends check mark symbol to the text. 10. append_not_check_mark() 11. append_warning_sign() - appends a warning sign to the text. 12. append_white_space() - appends a white space to the text property. 13. log() - prints the message on the terminal. 14. warn() - execute console.warn method to the text. 15. error() - execute console.error() method to the text property. 16. info() - execute console.info() method to the text property.

Note that the color, background color and style method are valid only in the node terminal environment.

1.0.7

3 years ago

1.0.6

3 years ago