<commit_before>fivalid
=======

fivalid is lightweight field data validator.

Features
--------
* data validation
    >>> from fivalid import validators
    >>> num = validators.Number(max=20)
    >>> num(10)
    >>> num(21)
    fivalid.validators.InvalidValueError: over max

* data validation and conversion
    >>> from fivalid import BaseField, validators, converters
    >>> class PercentageField(BaseField):
    ...   validator = validators.All(
    ...     validators.Number(min=0, max=100),
    ...     validators.String())
    ...   converter = converters.int_converter
    >>> field = PercentageField()
    >>> field('99')
    99
    >>> field('200')
    fivalid.validators.InvalidValueError: over max

* structured data (e.g. nested dict, nested list) validation and conversion
    >>> from fivalid import StructuredFields, Seq, Dict, BaseField
    >>> from fivalid.validators import String, Length, All, Flag
    >>> from fivalid.converters import truthvalue_converter
    >>> class CommentField(BaseField): validator = All(String(), Length(max=500))
    >>> class NicknameField(BaseField): validator = All(String(), Length(max=20))
    >>> class RememberMeField(BaseField): validator = Flag(); converter = truthvalue_converter
    >>> rule = Dict(
    ...   {'comment': CommentField(required=True),
    ...    'nickname': NicknameField(),
    ...    'remember me': RememberMeField()}
    ... )
    >>> stfields = StructuredFields(rule)
    >>> stfields({'comment': 'Hello, fivalid.',
    ...           'nickname': '<NAME>',
    ...           'remember me': '1'})
    {'comment': u'Hello, fivalid.', 'nickname': u'<NAME>', 'remember me': True}
<commit_msg>Easy to see the README<commit_after>fivalid
=======

fivalid is lightweight field data validator.

Features
--------
* data validation
    >>> from fivalid import validators
    >>> num = validators.Number(max=20)
    >>> num(10)
    >>> num(21)
    fivalid.validators.InvalidValueError: over max

* data validation and conversion
    >>> from fivalid import BaseField, validators, converters
    >>> class PercentageField(BaseField):
    ...   validator = validators.All(
    ...     validators.Number(min=0, max=100),
    ...     validators.String())
    ...   converter = converters.int_converter
    >>> field = PercentageField()
    >>> field('99')
    99
    >>> field('200')
    fivalid.validators.InvalidValueError: over max

* structured data (e.g. nested dict, nested list) validation and conversion
    >>> from fivalid import StructuredFields, Dict, BaseField
    >>> from fivalid.validators import String, Length, All, Flag
    >>> from fivalid.converters import truthvalue_converter
    >>> class CommentField(BaseField):
    ...   validator = All(String(), Length(max=500))
    >>> class NicknameField(BaseField):
    ...   validator = All(String(), Length(max=20))
    >>> class RememberMeField(BaseField):
    ...   validator = Flag()
    ...   converter = truthvalue_converter
    >>> rule = Dict(
    ...   {'comment': CommentField(required=True),
    ...    'nickname': NicknameField(),
    ...    'remember me': RememberMeField()}
    ... )
    >>> stfields = StructuredFields(rule)
    >>> stfields({'comment': 'Hello, fivalid.',
    ...           'nickname': '<NAME>',
    ...           'remember me': '1'}
    ... )
    {'comment': u'Hello, fivalid.', 'nickname': u'<NAME>', 'remember me': True}

{'fraction_non_alphanumeric': 0.16322314049586778, 'fraction_numerical': 0.01357733175914994, 'mean_word_length': 3.0782190132370637, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 115, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1908116', 'n_tokens_mistral': 1039, 'n_tokens_neox': 1000, 'n_words': 241}