Socket
Socket
Sign inDemoInstall

@hookstate/validation

Package Overview
Dependencies
7
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.5.2 to 1.8.0

45

dist/index.es.js

@@ -0,1 +1,3 @@

import { StateMarkerID, self } from '@hookstate/core';
var PluginID = Symbol('Validate');

@@ -46,9 +48,9 @@ var emptyErrors = [];

}
var _a = this.getRulesAndNested(l.path), existingRules = _a[0], nestedRulesKeys = _a[1];
var _a = this.getRulesAndNested(l[self].path), existingRules = _a[0], nestedRulesKeys = _a[1];
for (var i = 0; i < existingRules.length; i += 1) {
var r = existingRules[i];
if (!r.rule(l.value)) {
if (!r.rule(l[self].value)) {
var err = {
path: l.path,
message: typeof r.message === 'function' ? r.message(l.value) : r.message,
path: l[self].path,
message: typeof r.message === 'function' ? r.message(l[self].value) : r.message,
severity: r.severity

@@ -71,4 +73,4 @@ };

}
var nestedInst = l.nested;
if (nestedInst === undefined) {
var nestedInst = l;
if (nestedInst[self].keys === undefined) {
// console.log('getResults no nested inst', result)

@@ -130,9 +132,20 @@ return consistentResult();

}());
function Validation(self) {
if (self) {
var _a = self.with(PluginID), l_1 = _a[0], instance = _a[1];
function Validation($this) {
if ($this) {
var state_1;
if ($this[StateMarkerID]) {
state_1 = $this;
}
else {
state_1 = $this[self];
}
var plugin = state_1[self].attach(PluginID)[0];
if (plugin instanceof Error) {
throw plugin;
}
var instance = plugin;
var inst_1 = instance;
return {
validate: function (r, m, s) {
inst_1.addRule(l_1.path, {
inst_1.addRule(state_1[self].path, {
rule: r,

@@ -144,18 +157,18 @@ message: m,

validShallow: function () {
return inst_1.getErrors(l_1, 1, undefined, true).length === 0;
return inst_1.getErrors(state_1, 1, undefined, true).length === 0;
},
valid: function () {
return inst_1.getErrors(l_1, Number.MAX_SAFE_INTEGER, undefined, true).length === 0;
return inst_1.getErrors(state_1, Number.MAX_SAFE_INTEGER, undefined, true).length === 0;
},
invalidShallow: function () {
return inst_1.getErrors(l_1, 1, undefined, true).length !== 0;
return inst_1.getErrors(state_1, 1, undefined, true).length !== 0;
},
invalid: function () {
return inst_1.getErrors(l_1, Number.MAX_SAFE_INTEGER, undefined, true).length !== 0;
return inst_1.getErrors(state_1, Number.MAX_SAFE_INTEGER, undefined, true).length !== 0;
},
errors: function (filter, depth, first) {
return inst_1.getErrors(l_1, depth === undefined ? Number.MAX_SAFE_INTEGER : depth, filter, first);
return inst_1.getErrors(state_1, depth === undefined ? Number.MAX_SAFE_INTEGER : depth, filter, first);
},
firstError: function (filter, depth) {
var r = inst_1.getErrors(l_1, depth === undefined ? Number.MAX_SAFE_INTEGER : depth, filter, true);
var r = inst_1.getErrors(state_1, depth === undefined ? Number.MAX_SAFE_INTEGER : depth, filter, true);
if (r.length === 0) {

@@ -162,0 +175,0 @@ return {};

@@ -5,2 +5,4 @@ 'use strict';

var core = require('@hookstate/core');
var PluginID = Symbol('Validate');

@@ -51,9 +53,9 @@ var emptyErrors = [];

}
var _a = this.getRulesAndNested(l.path), existingRules = _a[0], nestedRulesKeys = _a[1];
var _a = this.getRulesAndNested(l[core.self].path), existingRules = _a[0], nestedRulesKeys = _a[1];
for (var i = 0; i < existingRules.length; i += 1) {
var r = existingRules[i];
if (!r.rule(l.value)) {
if (!r.rule(l[core.self].value)) {
var err = {
path: l.path,
message: typeof r.message === 'function' ? r.message(l.value) : r.message,
path: l[core.self].path,
message: typeof r.message === 'function' ? r.message(l[core.self].value) : r.message,
severity: r.severity

@@ -76,4 +78,4 @@ };

}
var nestedInst = l.nested;
if (nestedInst === undefined) {
var nestedInst = l;
if (nestedInst[core.self].keys === undefined) {
// console.log('getResults no nested inst', result)

@@ -135,9 +137,20 @@ return consistentResult();

}());
function Validation(self) {
if (self) {
var _a = self.with(PluginID), l_1 = _a[0], instance = _a[1];
function Validation($this) {
if ($this) {
var state_1;
if ($this[core.StateMarkerID]) {
state_1 = $this;
}
else {
state_1 = $this[core.self];
}
var plugin = state_1[core.self].attach(PluginID)[0];
if (plugin instanceof Error) {
throw plugin;
}
var instance = plugin;
var inst_1 = instance;
return {
validate: function (r, m, s) {
inst_1.addRule(l_1.path, {
inst_1.addRule(state_1[core.self].path, {
rule: r,

@@ -149,18 +162,18 @@ message: m,

validShallow: function () {
return inst_1.getErrors(l_1, 1, undefined, true).length === 0;
return inst_1.getErrors(state_1, 1, undefined, true).length === 0;
},
valid: function () {
return inst_1.getErrors(l_1, Number.MAX_SAFE_INTEGER, undefined, true).length === 0;
return inst_1.getErrors(state_1, Number.MAX_SAFE_INTEGER, undefined, true).length === 0;
},
invalidShallow: function () {
return inst_1.getErrors(l_1, 1, undefined, true).length !== 0;
return inst_1.getErrors(state_1, 1, undefined, true).length !== 0;
},
invalid: function () {
return inst_1.getErrors(l_1, Number.MAX_SAFE_INTEGER, undefined, true).length !== 0;
return inst_1.getErrors(state_1, Number.MAX_SAFE_INTEGER, undefined, true).length !== 0;
},
errors: function (filter, depth, first) {
return inst_1.getErrors(l_1, depth === undefined ? Number.MAX_SAFE_INTEGER : depth, filter, first);
return inst_1.getErrors(state_1, depth === undefined ? Number.MAX_SAFE_INTEGER : depth, filter, first);
},
firstError: function (filter, depth) {
var r = inst_1.getErrors(l_1, depth === undefined ? Number.MAX_SAFE_INTEGER : depth, filter, true);
var r = inst_1.getErrors(state_1, depth === undefined ? Number.MAX_SAFE_INTEGER : depth, filter, true);
if (r.length === 0) {

@@ -167,0 +180,0 @@ return {};

@@ -1,2 +0,2 @@

import { Plugin, Path, StateLink } from '@hookstate/core';
import { Plugin, Path, StateLink, State } from '@hookstate/core';
export declare type ValidationSeverity = 'error' | 'warning';

@@ -18,2 +18,3 @@ export interface ValidationError {

export declare function Validation(): Plugin;
export declare function Validation<S>(self: StateLink<S>): ValidationExtensions<S>;
export declare function Validation<S>($this: StateLink<S>): ValidationExtensions<S>;
export declare function Validation<S>($this: State<S>): ValidationExtensions<S>;
{
"name": "@hookstate/validation",
"version": "1.5.2",
"version": "1.8.0",
"description": "Plugin for @hookstate/core to enable validation of data state.",

@@ -38,32 +38,32 @@ "license": "MIT",

"peerDependencies": {
"@hookstate/core": "^1.5.2"
"@hookstate/core": "^1.8.3"
},
"devDependencies": {
"@hookstate/core": "^1.5.2",
"@testing-library/react": "9.4.0",
"@babel/core": "7.9.6",
"@babel/runtime": "7.9.6",
"@hookstate/core": "1.8.3",
"@rollup/plugin-babel": "5.0.2",
"@rollup/plugin-commonjs": "12.0.0",
"@rollup/plugin-node-resolve": "8.0.0",
"@rollup/plugin-url": "5.0.0",
"@testing-library/react": "10.0.4",
"@testing-library/react-hooks": "3.2.1",
"@types/jest": "25.1.2",
"@types/jest": "25.2.3",
"@types/lodash.clonedeep": "4.5.6",
"@types/lodash.isequal": "4.5.5",
"@types/react": "16.9.19",
"@types/react-dom": "16.9.5",
"babel-core": "6.26.3",
"babel-runtime": "6.26.0",
"cross-env": "7.0.0",
"npm-check-updates": "4.0.1",
"react": "16.12.0",
"react-dom": "16.12.0",
"react-scripts": "3.3.1",
"react-test-renderer": "16.12.0",
"rimraf": "3.0.1",
"rollup": "1.31.0",
"rollup-plugin-babel": "4.3.3",
"rollup-plugin-commonjs": "10.1.0",
"rollup-plugin-node-resolve": "5.2.0",
"@types/react": "16.9.35",
"@types/react-dom": "16.9.8",
"cross-env": "7.0.2",
"npm-check-updates": "6.0.1",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-scripts": "3.4.1",
"react-test-renderer": "16.13.1",
"rimraf": "3.0.2",
"rollup": "2.10.5",
"rollup-plugin-peer-deps-external": "2.2.2",
"rollup-plugin-typescript2": "0.25.3",
"rollup-plugin-url": "3.0.1",
"tslint": "6.0.0",
"tslint-react": "4.2.0",
"typescript": "3.7.5"
"rollup-plugin-typescript2": "0.27.1",
"tslint": "6.1.2",
"tslint-react": "5.0.0",
"typescript": "3.9.3"
},

@@ -70,0 +70,0 @@ "files": [

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with โšก๏ธ by Socket Inc