Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

livr

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

livr - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

lib/LIVR/util.js

8

lib/LIVR/Rules/Filters.js
'use strict';
function escapeRegExp(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
}
var util = require('../util');

@@ -36,3 +34,3 @@ module.exports = {

remove: function(chars) {
chars = escapeRegExp(chars);
chars = util.escapeRegExp(chars);
var re = new RegExp( '[' + chars + ']', 'g' );

@@ -49,3 +47,3 @@

leave_only: function(chars) {
chars = escapeRegExp(chars);
chars = util.escapeRegExp(chars);
var re = new RegExp( '[^' + chars + ']', 'g' );

@@ -52,0 +50,0 @@

'use strict';
var util = require('../util');
module.exports = {

@@ -7,2 +9,3 @@ integer: function() {

if (value === undefined || value === null || value === '' ) return;
if (!util.isNumberOrString(value)) return 'FORMAT_ERROR';

@@ -18,2 +21,3 @@ value += '';

if (value === undefined || value === null || value === '' ) return;
if (!util.isNumberOrString(value)) return 'FORMAT_ERROR';

@@ -29,2 +33,3 @@ value += '';

if (value === undefined || value === null || value === '' ) return;
if (!util.isNumberOrString(value)) return 'FORMAT_ERROR';

@@ -40,2 +45,3 @@ value += '';

if (value === undefined || value === null || value === '' ) return;
if (!util.isNumberOrString(value)) return 'FORMAT_ERROR';

@@ -51,2 +57,3 @@ value += '';

if (value === undefined || value === null || value === '' ) return;
if (!util.isNumberOrString(value)) return 'FORMAT_ERROR';

@@ -61,2 +68,3 @@ if ( +value > +maxNumber ) return 'TOO_HIGH';

if (value === undefined || value === null || value === '' ) return;
if (!util.isNumberOrString(value)) return 'FORMAT_ERROR';

@@ -72,2 +80,3 @@ if ( +value < +minNumber ) return 'TOO_LOW';

if (value === undefined || value === null || value === '' ) return;
if (!util.isNumberOrString(value)) return 'FORMAT_ERROR';

@@ -74,0 +83,0 @@ if ( +value < +minNumber ) return 'TOO_LOW';

'use strict';
var util = require('../util');
module.exports = {

@@ -9,2 +11,3 @@ email: function() {

if (value === undefined || value === null || value === '' ) return;
if (!util.isNumberOrString(value)) return 'FORMAT_ERROR';

@@ -21,2 +24,3 @@ value += '';

if (value === undefined || value === null || value === '' ) return;
if (!util.isNumberOrString(value)) return 'FORMAT_ERROR';

@@ -34,2 +38,3 @@ if ( value != params[field] ) return 'FIELDS_NOT_EQUAL';

if (value === undefined || value === null || value === '' ) return;
if (!util.isNumberOrString(value)) return 'FORMAT_ERROR';

@@ -44,2 +49,3 @@ if (value.length < 2083 && urlRe.test(value)) return;

if (value === undefined || value === null || value === '' ) return;
if (!util.isNumberOrString(value)) return 'FORMAT_ERROR';

@@ -53,4 +59,5 @@ var matched = value.match(/^(\d{4})-([0-1][0-9])-([0-3][0-9])$/);

var d = new Date(epoch);
d.setTime( d.getTime() + d.getTimezoneOffset() * 60 * 1000 );
if ( d.getUTCFullYear() == matched[1] && d.getMonth()+1 == +matched[2] && d.getDate() == +matched[3] ) {
if ( d.getFullYear() == matched[1] && d.getMonth()+1 == +matched[2] && d.getDate() == +matched[3] ) {
return;

@@ -57,0 +64,0 @@ }

'use strict';
var util = require('../util');
module.exports = {

@@ -12,2 +14,3 @@ one_of: function(allowedValues) {

if (value === undefined || value === null || value === '' ) return;
if (!util.isNumberOrString(value)) return 'FORMAT_ERROR';

@@ -27,2 +30,3 @@ for (var i=0; i<allowedValues.length; i++) {

if (value === undefined || value === null || value === '' ) return;
if (!util.isNumberOrString(value)) return 'FORMAT_ERROR';

@@ -38,2 +42,3 @@ value += '';

if (value === undefined || value === null || value === '' ) return;
if (!util.isNumberOrString(value)) return 'FORMAT_ERROR';

@@ -49,2 +54,3 @@ value += '';

if (value === undefined || value === null || value === '' ) return;
if (!util.isNumberOrString(value)) return 'FORMAT_ERROR';

@@ -61,2 +67,3 @@ value += '';

if (value === undefined || value === null || value === '' ) return;
if (!util.isNumberOrString(value)) return 'FORMAT_ERROR';

@@ -76,2 +83,3 @@ value += '';

if (value === undefined || value === null || value === '' ) return;
if (!util.isNumberOrString(value)) return 'FORMAT_ERROR';

@@ -78,0 +86,0 @@ value += '';

'use strict';
var util = require('./util');
var DEFAULT_RULES = {};

@@ -89,3 +91,3 @@ var IS_DEFAULT_AUTO_TRIM = 0;

if (! isObject(data) ) {
if (! util.isObject(data) ) {
this.errors = 'FORMAT_ERROR';

@@ -129,3 +131,3 @@ return;

if (isEmpty(errors)) {
if (util.isEmpty(errors)) {
this.errors = null;

@@ -167,3 +169,3 @@ return result;

if ( isObject(livrRule) ) {
if ( util.isObject(livrRule) ) {
name = Object.keys(livrRule)[0];

@@ -212,3 +214,3 @@ args = livrRule[ name ];

return trimmedData;
} else if ( dataType == 'object' && isObject(data) ) {
} else if ( dataType == 'object' && util.isObject(data) ) {
var trimmedData = {};

@@ -229,16 +231,2 @@

function isObject(obj) {
// TODO make better checking
return obj === Object(obj);
}
function isEmpty(map) {
for(var key in map) {
if (map.hasOwnProperty(key)) {
return false;
}
}
return true;
}
module.exports = Validator;
{
"name": "livr",
"version": "0.0.5",
"version": "0.0.6",
"description": "Lightweight validator supporting Language Independent Validation Rules Specification",

@@ -5,0 +5,0 @@ "homepage": "http://livr-spec.org",

{
"first_name": "",
"last_name": null,
"age": "25"
"age": "25",
"value_is_hash": {"test": 1},
"value_is_empty_hash": {},
"value_is_array": ["test", 1],
"value_is_empty_array": []
}
{
"first_name": "required",
"last_name": ["required"],
"middle_name": [ { "required": [] } ]
"middle_name": [ { "required": [] } ],
"value_is_hash": "required",
"value_is_empty_hash": "required",
"value_is_array": "required",
"value_is_empty_array": "required"
}
{
"first_name": "",
"last_name": null,
"age": "25"
"age": "25",
"value_is_hash": {"test": 1},
"value_is_empty_hash": {},
"value_is_array": ["test", 1],
"value_is_empty_array": []
}
{
"first_name": "not_empty",
"last_name": ["not_empty"],
"middle_name": [ { "not_empty": [] } ]
"middle_name": [ { "not_empty": [] } ],
"value_is_hash": "not_empty",
"value_is_empty_hash": "not_empty",
"value_is_array": "not_empty",
"value_is_empty_array": "not_empty"
}
{
"city1": "NOT_ALLOWED_VALUE",
"city2": "NOT_ALLOWED_VALUE",
"city3": "NOT_ALLOWED_VALUE"
"city3": "NOT_ALLOWED_VALUE",
"value_is_hash": "FORMAT_ERROR",
"value_is_empty_hash": "FORMAT_ERROR",
"value_is_array": "FORMAT_ERROR",
"value_is_empty_array": "FORMAT_ERROR"
}

@@ -5,3 +5,8 @@ {

"city3": "New York",
"extra_city": "New York"
"extra_city": "New York",
"value_is_hash": {"test": 1},
"value_is_empty_hash": {},
"value_is_array": ["test", 1],
"value_is_empty_array": []
}
{
"city1": { "one_of": [["Moscow", "Kiev" ]] },
"city2": [{ "one_of": [["Moscow", "Kiev" ]] }],
"city3": { "one_of": ["Moscow", "Kiev"] }
"city3": { "one_of": ["Moscow", "Kiev"] },
"value_is_hash": { "one_of": [["Moscow", "Kiev" ]] },
"value_is_empty_hash": { "one_of": [["Moscow", "Kiev" ]] },
"value_is_array": { "one_of": [["Moscow", "Kiev" ]] },
"value_is_empty_array": { "one_of": [["Moscow", "Kiev" ]] }
}
{
"first_name": "TOO_SHORT",
"last_name": "TOO_SHORT",
"middle_name": "TOO_SHORT"
"middle_name": "TOO_SHORT",
"value_is_hash": "FORMAT_ERROR",
"value_is_empty_hash": "FORMAT_ERROR",
"value_is_array": "FORMAT_ERROR",
"value_is_empty_array": "FORMAT_ERROR"
}

@@ -6,3 +6,8 @@ {

"empty_name": "",
"extra_name": "extra_name"
"extra_name": "extra_name",
"value_is_hash": {"test": 1},
"value_is_empty_hash": {},
"value_is_array": ["test", 1],
"value_is_empty_array": []
}

@@ -5,3 +5,8 @@ {

"middle_name": [{ "min_length": [10] }],
"empty_name": { "min_length": 3 }
"empty_name": { "min_length": 3 },
"value_is_hash": { "min_length": 6 },
"value_is_empty_hash": { "min_length": 6 },
"value_is_array": { "min_length": 6 },
"value_is_empty_array": { "min_length": 6 }
}
{
"first_name": "TOO_LONG",
"last_name": "TOO_LONG",
"middle_name": "TOO_LONG"
"middle_name": "TOO_LONG",
"value_is_hash": "FORMAT_ERROR",
"value_is_empty_hash": "FORMAT_ERROR",
"value_is_array": "FORMAT_ERROR",
"value_is_empty_array": "FORMAT_ERROR"
}

@@ -6,3 +6,8 @@ {

"empty_name": "",
"extra_name": "extra_name"
"extra_name": "extra_name",
"value_is_hash": {"test": 1},
"value_is_empty_hash": {},
"value_is_array": ["test", 1],
"value_is_empty_array": []
}

@@ -5,3 +5,8 @@ {

"middle_name": [{ "max_length": [0] }],
"empty_name": { "max_length": 3 }
"empty_name": { "max_length": 3 },
"value_is_hash": { "max_length": 4 },
"value_is_empty_hash": { "max_length": 4 },
"value_is_array": { "max_length": 4 },
"value_is_empty_array": { "max_length": 4 }
}
{
"first_name": "TOO_LONG",
"last_name": "TOO_SHORT",
"middle_name": "TOO_LONG"
"middle_name": "TOO_LONG",
"value_is_hash": "FORMAT_ERROR",
"value_is_empty_hash": "FORMAT_ERROR",
"value_is_array": "FORMAT_ERROR",
"value_is_empty_array": "FORMAT_ERROR"
}

@@ -6,3 +6,8 @@ {

"empty_name": "",
"extra_name": "extra_name"
"extra_name": "extra_name",
"value_is_hash": {"test": 1},
"value_is_empty_hash": {},
"value_is_array": ["test", 1],
"value_is_empty_array": []
}

@@ -5,3 +5,8 @@ {

"middle_name": [{ "length_equal": [3] }],
"empty_name": { "length_equal": 3 }
"empty_name": { "length_equal": 3 },
"value_is_hash": { "length_equal": 2 },
"value_is_empty_hash": { "length_equal": 2 },
"value_is_array": { "length_equal": 2 },
"value_is_empty_array": { "length_equal": 2 }
}

@@ -5,3 +5,8 @@ {

"middle_name": "WRONG_FORMAT",
"age": "WRONG_FORMAT"
"age": "WRONG_FORMAT",
"value_is_hash": "FORMAT_ERROR",
"value_is_empty_hash": "FORMAT_ERROR",
"value_is_array": "FORMAT_ERROR",
"value_is_empty_array": "FORMAT_ERROR"
}

@@ -7,3 +7,9 @@ {

"empty_name": "",
"extra_name": "extra_name"
"extra_name": "extra_name",
"value_is_hash": {"test": 1},
"value_is_empty_hash": {},
"value_is_array": ["test", 1],
"value_is_empty_array": []
}

@@ -6,3 +6,8 @@ {

"age": [{ "like": "^[a-z]+$" }],
"empty_name": { "like": "[A-Za-z]" }
"empty_name": { "like": "[A-Za-z]" },
"value_is_hash": { "like": "[0-9]+" },
"value_is_empty_hash": { "like": "[0-9]+" },
"value_is_array": { "like": "[0-9]+" },
"value_is_empty_array": { "like": "[0-9]+" }
}
{
"number1": "NOT_INTEGER",
"number2": "NOT_INTEGER",
"number3": "NOT_INTEGER"
"number3": "NOT_INTEGER",
"value_is_hash": "FORMAT_ERROR",
"value_is_empty_hash": "FORMAT_ERROR",
"value_is_array": "FORMAT_ERROR",
"value_is_empty_array": "FORMAT_ERROR"
}

@@ -6,3 +6,8 @@ {

"empty_field": "",
"extra_field": "100"
"extra_field": "100",
"value_is_hash": {"test": 1},
"value_is_empty_hash": {},
"value_is_array": ["test", 1],
"value_is_empty_array": []
}

@@ -5,3 +5,8 @@ {

"number3": [ { "integer": [] } ],
"empty_field": "integer"
"empty_field": "integer",
"value_is_hash": "integer",
"value_is_empty_hash": "integer",
"value_is_array": "integer",
"value_is_empty_array": "integer"
}
{
"number1": "NOT_POSITIVE_INTEGER",
"number2": "NOT_POSITIVE_INTEGER",
"number3": "NOT_POSITIVE_INTEGER"
"number3": "NOT_POSITIVE_INTEGER",
"value_is_hash": "FORMAT_ERROR",
"value_is_empty_hash": "FORMAT_ERROR",
"value_is_array": "FORMAT_ERROR",
"value_is_empty_array": "FORMAT_ERROR"
}

@@ -6,3 +6,8 @@ {

"empty_field": "",
"extra_field": "100"
"extra_field": "100",
"value_is_hash": {"test": 1},
"value_is_empty_hash": {},
"value_is_array": ["test", 1],
"value_is_empty_array": []
}

@@ -5,3 +5,8 @@ {

"number3": [ { "positive_integer": [] } ],
"empty_field": "positive_integer"
"empty_field": "positive_integer",
"value_is_hash": "positive_integer",
"value_is_empty_hash": "positive_integer",
"value_is_array": "positive_integer",
"value_is_empty_array": "positive_integer"
}
{
"number1": "NOT_DECIMAL",
"number2": "NOT_DECIMAL",
"number3": "NOT_DECIMAL"
"number3": "NOT_DECIMAL",
"value_is_hash": "FORMAT_ERROR",
"value_is_empty_hash": "FORMAT_ERROR",
"value_is_array": "FORMAT_ERROR",
"value_is_empty_array": "FORMAT_ERROR"
}

@@ -6,3 +6,8 @@ {

"empty_field": "",
"extra_field": "100"
"extra_field": "100",
"value_is_hash": {"test": 1},
"value_is_empty_hash": {},
"value_is_array": ["test", 1],
"value_is_empty_array": []
}

@@ -5,3 +5,8 @@ {

"number3": [ { "decimal": [] } ],
"empty_field": "decimal"
"empty_field": "decimal",
"value_is_hash": "decimal",
"value_is_empty_hash": "decimal",
"value_is_array": "decimal",
"value_is_empty_array": "decimal"
}
{
"number1": "NOT_POSITIVE_DECIMAL",
"number2": "NOT_POSITIVE_DECIMAL",
"number3": "NOT_POSITIVE_DECIMAL"
"number3": "NOT_POSITIVE_DECIMAL",
"value_is_hash": "FORMAT_ERROR",
"value_is_empty_hash": "FORMAT_ERROR",
"value_is_array": "FORMAT_ERROR",
"value_is_empty_array": "FORMAT_ERROR"
}

@@ -6,3 +6,8 @@ {

"empty_field": "",
"extra_field": "100"
"extra_field": "100",
"value_is_hash": {"test": 1},
"value_is_empty_hash": {},
"value_is_array": ["test", 1],
"value_is_empty_array": []
}

@@ -5,3 +5,8 @@ {

"number3": [ { "positive_decimal": [] } ],
"empty_field": "positive_decimal"
"empty_field": "positive_decimal",
"value_is_hash": "positive_decimal",
"value_is_empty_hash": "positive_decimal",
"value_is_array": "positive_decimal",
"value_is_empty_array": "positive_decimal"
}
{
"number1": "TOO_HIGH",
"number2": "TOO_HIGH"
"number2": "TOO_HIGH",
"value_is_hash": "FORMAT_ERROR",
"value_is_empty_hash": "FORMAT_ERROR",
"value_is_array": "FORMAT_ERROR",
"value_is_empty_array": "FORMAT_ERROR"
}

@@ -5,3 +5,8 @@ {

"empty_field": "",
"extra_field": "100"
"extra_field": "100",
"value_is_hash": {"test": 1},
"value_is_empty_hash": {},
"value_is_array": ["test", 1],
"value_is_empty_array": []
}
{
"number1": { "max_number": 10 },
"number2": [{ "max_number": 20 }],
"empty_field": { "max_number": 40 }
"empty_field": { "max_number": 40 },
"value_is_hash": { "max_number": 10 },
"value_is_empty_hash": { "max_number": 10 },
"value_is_array": { "max_number": 10 },
"value_is_empty_array": { "max_number": 10 }
}
{
"number1": "TOO_LOW",
"number2": "TOO_LOW"
"number2": "TOO_LOW",
"value_is_hash": "FORMAT_ERROR",
"value_is_empty_hash": "FORMAT_ERROR",
"value_is_array": "FORMAT_ERROR",
"value_is_empty_array": "FORMAT_ERROR"
}

@@ -5,3 +5,8 @@ {

"empty_field": "",
"extra_field": "100"
"extra_field": "100",
"value_is_hash": {"test": 1},
"value_is_empty_hash": {},
"value_is_array": ["test", 1],
"value_is_empty_array": []
}
{
"number1": { "min_number" : 10 },
"number2": [{ "min_number" : 20 }],
"empty_field": { "min_number" : 10 }
"empty_field": { "min_number" : 10 },
"value_is_hash": { "min_number": 10 },
"value_is_empty_hash": { "min_number": 10 },
"value_is_array": { "min_number": 10 },
"value_is_empty_array": { "min_number": 10 }
}
{
"number1": "TOO_LOW",
"number2": "TOO_HIGH"
"number2": "TOO_HIGH",
"value_is_hash": "FORMAT_ERROR",
"value_is_empty_hash": "FORMAT_ERROR",
"value_is_array": "FORMAT_ERROR",
"value_is_empty_array": "FORMAT_ERROR"
}

@@ -5,3 +5,8 @@ {

"empty_field": "",
"extra_field": "100"
"extra_field": "100",
"value_is_hash": {"test": 1},
"value_is_empty_hash": {},
"value_is_array": ["test", 1],
"value_is_empty_array": []
}
{
"number1": { "number_between": [10,20] },
"number2": [ { "number_between": [10,20] } ],
"empty_field": { "number_between": [10,20] }
"empty_field": { "number_between": [10,20] },
"value_is_hash": { "number_between": [10,20] },
"value_is_empty_hash": { "number_between": [10,20] },
"value_is_array": { "number_between": [10,20] },
"value_is_empty_array": { "number_between": [10,20] }
}
{
"email1": "WRONG_EMAIL",
"email2": "WRONG_EMAIL",
"email3": "WRONG_EMAIL"
"email3": "WRONG_EMAIL",
"value_is_hash": "FORMAT_ERROR",
"value_is_empty_hash": "FORMAT_ERROR",
"value_is_array": "FORMAT_ERROR",
"value_is_empty_array": "FORMAT_ERROR"
}

@@ -6,3 +6,8 @@ {

"empty_field": "",
"extra_field": "aaaa"
"extra_field": "aaaa",
"value_is_hash": {"test": 1},
"value_is_empty_hash": {},
"value_is_array": ["test", 1],
"value_is_empty_array": []
}

@@ -5,3 +5,8 @@ {

"email3": [ { "email": [] } ],
"empty_field": "email"
"empty_field": "email",
"value_is_hash": "email",
"value_is_empty_hash": "email",
"value_is_array": "email",
"value_is_empty_array": "email"
}
{
"field1": "FIELDS_NOT_EQUAL",
"field2": "FIELDS_NOT_EQUAL",
"field3": "FIELDS_NOT_EQUAL"
"field3": "FIELDS_NOT_EQUAL",
"value_is_hash": "FORMAT_ERROR",
"value_is_empty_hash": "FORMAT_ERROR",
"value_is_array": "FORMAT_ERROR",
"value_is_empty_array": "FORMAT_ERROR"
}

@@ -6,3 +6,8 @@ {

"empty_field": "",
"extra_field": "some value"
"extra_field": "some value",
"value_is_hash": {"test": 1},
"value_is_empty_hash": {},
"value_is_array": ["test", 1],
"value_is_empty_array": []
}

@@ -5,3 +5,8 @@ {

"field3": { "equal_to_field": ["field1"] },
"empty_field": { "equal_to_field": "field2" }
"empty_field": { "equal_to_field": "field2" },
"value_is_hash": { "equal_to_field": "field2" },
"value_is_empty_hash": { "equal_to_field": "field2" },
"value_is_array": { "equal_to_field": "field2" },
"value_is_empty_array": { "equal_to_field": "field2" }
}
{
"url1": "WRONG_URL",
"url2": "WRONG_URL",
"url3": "WRONG_URL"
"url3": "WRONG_URL",
"value_is_hash": "FORMAT_ERROR",
"value_is_empty_hash": "FORMAT_ERROR",
"value_is_array": "FORMAT_ERROR",
"value_is_empty_array": "FORMAT_ERROR"
}

@@ -6,3 +6,8 @@ {

"empty_field": "",
"extra_field": "aaaa"
"extra_field": "aaaa",
"value_is_hash": {"test": 1},
"value_is_empty_hash": {},
"value_is_array": ["test", 1],
"value_is_empty_array": []
}

@@ -5,3 +5,8 @@ {

"url3": [ { "url": [] } ],
"empty_field": "url"
"empty_field": "url",
"value_is_hash": "url",
"value_is_empty_hash": "url",
"value_is_array": "url",
"value_is_empty_array": "url"
}
{
"iso_date1": "WRONG_DATE",
"iso_date2": "WRONG_DATE",
"iso_date3": "WRONG_DATE"
"iso_date3": "WRONG_DATE",
"value_is_hash": "FORMAT_ERROR",
"value_is_empty_hash": "FORMAT_ERROR",
"value_is_array": "FORMAT_ERROR",
"value_is_empty_array": "FORMAT_ERROR"
}

@@ -6,3 +6,8 @@ {

"empty_field": "",
"extra_field": "aaaa"
"extra_field": "aaaa",
"value_is_hash": {"test": 1},
"value_is_empty_hash": {},
"value_is_array": ["test", 1],
"value_is_empty_array": []
}

@@ -5,3 +5,8 @@ {

"iso_date3": [ { "iso_date": [] } ],
"empty_field": "iso_date"
"empty_field": "iso_date",
"value_is_hash": "iso_date",
"value_is_empty_hash": "iso_date",
"value_is_array": "iso_date",
"value_is_empty_array": "iso_date"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc