common validators for onny products
npm install @onny/validate
 
Common validators and sanitizers for our Onny apps and utils
Mostly based on/wrappers for validator
npm i --save onny-validate```javascript
// load everything
import onnyUtils from 'onny-validate';
// validators only
import validators from 'onny-validate/validate';
// sanitizers only
import sanitize from 'onny-validate/sanitize';
// selective loading validators
import { isArray } from 'onny-validate';
// or
import isArray from 'onny-validate/validate/isArray';
```
Are we an array?
@param {|Array} value - value to test
* @returns {boolean} - true if array, false if not
@param {|null} value - value to test
* @returns {boolean} - true if null or defined, false if not
check if the string is a valid hex-encoded representation of a MongoDB ObjectId.
See MongoDB ObjectId
@param {|String} value
* @returns {boolean} - true if formatted as a mongoID
* @param {string} input - the string to check
* @returns {string|null} - string with <, >, &, ', " and / replaced with HTML entities
* @param {string} input - the string to parse
* @returns {string|null} - string with HTML encoded entities replaced with <, >, &, ', " and /
* @param {string} email - the email to normalize
* @param {object} options - canonicalizes an email address
* @param {boolean} options.all_lowercase - Transforms the local part (before the @ symbol) of all email addresses to lowercase. Please note that this may violate RFC 5321, which gives providers the possibility to treat the local part of email addresses in a case sensitive way (although in practice most - yet not all - providers don't). The domain part of the email address is always lowercased, as it's case insensitive per RFC 1035.
default: true
* @param {boolean} options.gmail_lowercase - GMail addresses are known to be case-insensitive, so this switch allows lowercasing them even when all_lowercase is set to false. Please note that when all_lowercase is true, GMail addresses are lowercased regardless of the value of this setting.
default: true
* @param {boolean} options.gmail_remove_dots - Removes dots from the local part of the email address, as GMail ignores them (e.g. "john.doe" and "johndoe" are considered equal).
default: true
* @param {boolean} options.gmail_remove_subaddress - Normalizes addresses by removing "sub-addresses", which is the part following a "+" sign (e.g. "foo+bar@gmail.com" becomes "foo@gmail.com").
default: true
* @param {boolean} options.gmail_convert_googlemaildotcom - Converts addresses with domain @googlemail.com to @gmail.com, as they're equivalent.
default: true
* @param {boolean} options.outlookdotcom_lowercase - Outlook.com addresses (including Windows Live and Hotmail) are known to be case-insensitive, so this switch allows lowercasing them even when all_lowercase is set to false. Please note that when all_lowercase is true, Outlook.com addresses are lowercased regardless of the value of this setting.
default: true
* @param {boolean} options.outlookdotcom_remove_subaddress - Normalizes addresses by removing "sub-addresses", which is the part following a "+" sign (e.g. "foo+bar@outlook.com" becomes "foo@outlook.com").
default: true
* @param {boolean} options.yahoo_lowercase - Yahoo Mail addresses are known to be case-insensitive, so this switch allows lowercasing them even when all_lowercase is set to false. Please note that when all_lowercase is true, Yahoo Mail addresses are lowercased regardless of the value of this setting.
default: true
* @param {boolean} options.yahoo_remove_subaddress - Normalizes addresses by removing "sub-addresses", which is the part following a "-" sign (e.g. "foo-bar@yahoo.com" becomes "foo@yahoo.com").
default: true
* @param {boolean} options.icloud_lowercase - iCloud addresses (including MobileMe) are known to be case-insensitive, so this switch allows lowercasing them even when all_lowercase is set to false. Please note that when all_lowercase is true, iCloud addresses are lowercased regardless of the value of this setting.
default: true
* @param {boolean} options.icloud_remove_subaddress - Normalizes addresses by removing "sub-addresses", which is the part following a "+" sign (e.g. "foo+bar@icloud.com" becomes "foo@icloud.com").
default: true
* @returns {string|null} - string with <, >, &, ', " and / replaced with HTML entities
##### License
GPL-3.0 License
Copyright (C) 2015-2019 Onny LLC - All Rights Reserved